Display And Monitor
Fait partie de la section Fondamentaux du Journey Verilog de Coddy. Leçon 75 sur 90.
$display et $monitor sont des tâches système utilisées pour afficher des informations de votre simulation. Elles vous aident à voir ce qui se passe à l’intérieur de votre conception.
$display
$display affiche un message une seule fois au moment où il est exécuté.
Syntaxe :
$display("message", variables);Exemple :
initial begin
$display("Simulation started");
#10;
$display("Time 10");
#10;
$display("Time 20");
endSortie :
Simulation started
Time 10
Time 20$monitor
$monitor affiche un message automatiquement chaque fois que l’une de ses variables change.
Syntaxe :
$monitor("message", variables);Exemple :
initial begin
a = 0; b = 0;
$monitor("Time %0t: a=%b, b=%b", $time, a, b);
#10 a = 1;
#10 b = 1;
#10 a = 0;
endSortie :
Time 0: a=0, b=0
Time 10: a=1, b=0
Time 20: a=1, b=1
Time 30: a=0, b=1$display contre $monitor
| $display | $monitor | |
|---|---|---|
| Quand il s'affiche | Une fois lors de son exécution | Chaque fois qu'une variable change |
| Combien de fois | Autant de fois que vous l'appelez | Continuellement (jusqu'à ce qu'il soit modifié) |
| Utiliser pour | Headers, message de test | track des signaux changeants |
Spécificateurs de format courants
| Spécificateur | Signification | Exemple |
|---|---|---|
%b | Binary | $display("%b", a); |
%d | Décimal | $display("%d", count); |
%h | Hexadécimal | $display("%h", data); |
%t | Time | $display("%t", $time); |
%0t | Time (sans espaces) | $display("%0t", $time); |
%s | Chaîne | $display("%s", "Hello"); |
Règles importantes
| Règle | Explication |
|---|---|
$display affiche une seule fois | Utile pour les en-têtes et les résultats finaux |
$monitor affiche en cas de changement | Utile pour surveiller les signaux |
Un seul $monitor actif | Le dernier remplace le précédent |
Utilisez $finish pour arrêter | Sinon, la Simulation peut s'exécuter indéfiniment |
Défi
Add the missing $display and $monitor statements to this testbench.
À faire :
- Add
$displaypour afficher un en-tête : "Testing OR Gate" - Add
$monitorpour afficher time, x, y et z chaque fois qu’un signal change. Format : "Time %0t: x=%b, y=%b, z=%b" - Add
$displayat the end pour afficher "Test complete"
Essayez vous-même
module or_gate (
input x,
input y,
output z
);
assign z = x | y;
endmodule
module testbench;
reg x, y;
wire z;
or_gate dut (
.x(x),
.y(y),
.z(z)
);
initial begin
// TODO: Ajouter l'en-tête $display "Testing OR Gate"
// TODO: Ajouter $monitor pour suivre time, x, y, z
// Format : "Time %0t: x=%b, y=%b, z=%b"
// Appliquer le stimulus
x = 0; y = 0; #10;
x = 0; y = 1; #10;
x = 1; y = 0; #10;
x = 1; y = 1; #10;
// TODO: Ajouter $display "Test complete"
$finish;
end
endmoduleCette leçon comprend un petit quiz. Commencez la leçon pour y répondre et suivre votre progression.
Toutes les leçons de Fondamentaux
1Introduction
Qu’est-ce que VerilogMatériel vs logicielVotre premier moduleCommentairesNiveaux d’abstraction de conception4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge14Testbench Basics
What Is A TestbenchCreating StimulusDisplay And MonitorDumpfile And DumpvarsUsing System TasksRecap - Full Testbench3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine LogicEntraînez-vous par vous-même : Compilateur Verilog en ligne