Verifying The Output
Parte da seção Fundamentos do Journey de Verilog da Coddy. Lição 83 de 90.
Desafio
Nesta lição, você adicionará comandos de dump de formas de onda e verificará se o controlador do semáforo funciona corretamente.
O que fazer:
Atualize o testbench para:
- Adicionar
$dumpfilepara criar um arquivo de forma de onda chamadotraffic.vcd - Adicionar
$dumpvarspara fazer dump de todos os sinais no testbench - Executar a simulação e verificar a forma de onda
Experimente você mesmo
module traffic_light (
input clk,
input reset,
output reg red,
output reg yellow,
output reg green
);
// Estados: 0=Verde, 1=Amarelo, 2=Vermelho
reg [1:0] state;
reg [5:0] counter;
always @(posedge clk or posedge reset) begin
if (reset) begin
state <= 2; // Começa no Vermelho
counter <= 0;
end else begin
if (counter == 0) begin
// Muda o estado
if (state == 0) begin // Verde -> Amarelo
state <= 1;
counter <= 10; // Amarelo dura 10 segundos
end else if (state == 1) begin // Amarelo -> Vermelho
state <= 2;
counter <= 40; // Vermelho dura 40 segundos
end else begin // Vermelho -> Verde
state <= 0;
counter <= 30; // Verde dura 30 segundos
end
end else begin
counter <= counter - 1;
end
end
end
// Lógica de saída
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: Adicione $dumpfile para criar "traffic.vcd"
// TODO: Adicione $dumpvars para despejar todos os sinais (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 as lições de Fundamentos
1Introdução
O que é VerilogHardware vs. SoftwareSeu primeiro móduloComentáriosNíveis de abstração de projeto4Operators 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 LogicPratique por conta própria: Compilador de Verilog online