ECAD and Architecture Practical Classes
Tick 2 - Traffic Lights
We want to design a module that models the sequence of traffic lights at a cross roads. We suggest you base it around a counter for the eight states with the correct output being provided by decode logic.

Notes:
- Red is the most significant bit, i.e.
lightsA = {r,a,g}
where{r,a,g}
are the red, amber and green bits. - The very first output after reset needs to be for state 0 in the diagram.
- Your output decoder needs to be combinational, i.e. inside
an
always_comb
block.
Outline module
module twotrafficlights( input logic clk, input logic rst, output logic [2:0] lightsA, output logic [2:0] lightsB ); logic [2:0] state; // insert your code here endmodule
Test bench
The ticker tests your design against a known-good golden model using the following test bench code. You may wish to simplify it to just instantiate your module and display the sequence produced.
module twotrafficlights_tester ( output logic clk, output logic rst, output logic [2:0] lightsA, output logic [2:0] lightsB ); logic [2:0] correctA, correctB; initial begin clk = 1; rst = 1; #20 rst = 0; #165 $finish(); end always #5 clk <= !clk; twotrafficlights dut(.clk(clk), .rst(rst), .lightsA(lightsA), .lightsB(lightsB)); twotrafficlights_golden gold(.clk(clk), .rst(rst), .lightsA(correctA), .lightsB(correctB)); always @(posedge clk) if(!rst) begin $write("%04d: rst=%1b (lightsA,lightsB) = (%03b, %03b) correct: (%03b, %03b)", $time, rst, lightsA, lightsB, correctA, correctB); if({lightsA,lightsB} == {correctA,correctB}) $display(" - pass"); else $display(" - FAIL"); end endmodule