BitFlow

Traffic light

A state machine is a register holding which state you're in, plus rules for moving on. Here the states are GREEN, YELLOW and RED, and each moves on when its time is up: green 3 s, yellow 1 s, red 3 s.

LED 0 is green, LED 1 yellow and LED 2 red. Name your states with localparam so the code reads like the rules.

lab.v
drag to turn · scroll to zoom

Loading the board…

Press Run on the board: your Verilog is turned into gates in this browser and runs here, cycle by cycle.

Goals

  • ○One light is on at a time
  • ○Green, then yellow, then red, then green again
  • ○Green 3 s, yellow 1 s, red 3 s
Hints
  1. A 2-bit state and a timer that restarts on every change.
  2. case (state) GREEN: if (timer == 3*CLK_HZ - 1) begin state <= YELLOW; timer <= 0; end ...

Pin log

Run the design to see its outputs change.

Put it on a real board

  • The clock is set to the board's 27 MHz, and its active-low buttons and LEDs are flipped for you.
Waveform