Verifying The Output
Parte de la sección Fundamentos del Journey de Verilog de Coddy. Lección 83 de 90.
Desafío
En esta lección, añadirás comandos para volcar formas de onda y verificarás que el controlador del semáforo funciona correctamente.
Qué hacer:
Actualiza el testbench para:
- Añadir
$dumpfilepara crear un archivo de formas de onda llamadotraffic.vcd - Añadir
$dumpvarspara volcar todas las señales del testbench - Ejecutar la simulación y comprobar la forma de onda
Pruébalo tú mismo
module traffic_light (
input clk,
input reset,
output reg red,
output reg yellow,
output reg green
);
// Estados: 0=Verde, 1=Amarillo, 2=Rojo
reg [1:0] state;
reg [5:0] counter;
always @(posedge clk or posedge reset) begin
if (reset) begin
state <= 2; // Comienza en Rojo
counter <= 0;
end else begin
if (counter == 0) begin
// Cambiar estado
if (state == 0) begin // Verde -> Amarillo
state <= 1;
counter <= 10; // Amarillo dura 10 segundos
end else if (state == 1) begin // Amarillo -> Rojo
state <= 2;
counter <= 40; // Rojo dura 40 segundos
end else begin // Rojo -> Verde
state <= 0;
counter <= 30; // Verde dura 30 segundos
end
end else begin
counter <= counter - 1;
end
end
end
// Lógica de salida
always @(*) begin
red = (state == 2);
yellow = (state == 1);
green = (state == 0);
end
endmodule
module testbench;
reg clk, reset;
wire red, yellow, green;
traffic_light uut (
.clk(clk),
.reset(reset),
.red(red),
.yellow(yellow),
.green(green)
);
always #1 clk = ~clk;
initial begin
// TODO: Añade $dumpfile para crear "traffic.vcd"
// TODO: Añade $dumpvars para volcar todas las señales (0, testbench)
$display("Traffic Light Test");
$monitor("Time %0t: red=%b, yellow=%b, green=%b", $time, red, yellow, green);
clk = 0;
reset = 1;
#2 reset = 0;
#90;
$finish;
end
endmodule
Todas las lecciones de Fundamentos
1Introducción
Qué es VerilogHardware frente a softwareTu primer móduloComentariosNiveles de abstracción del diseño4Operators 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 Challenge3Number 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 LogicPractica por tu cuenta: Compilador de Verilog online