A synchronous FSM-based traffic light controller for a single road, written in Verilog / SystemVerilog.
Author: Ashraful Hasan Bhuiyan
Cycles a single road's signal through three states in fixed order:
RED → YELLOW → GREEN → RED → ...
Built on a counter + comparator + FSM datapath. State durations are parameters, not hardcoded values.
| Item | Specification |
|---|---|
| Clock | Synchronous clk |
| Reset | Active-high, asynchronous rst |
| Start behavior | Idle after reset until start is pressed; then runs continuously |
| RED duration | 50 clock cycles |
| GREEN duration | 50 clock cycles) |
| YELLOW duration | 5 clock cycles |
| State control | FSM drives transitions; internal counter tracks elapsed cycles per state |
| Output | Exactly one of RED, YELLOW, GREEN asserted at any time |
- ASM (Algorithmic State Machine) state diagram
- State transition logic
- Counter / timer logic
- Output logic
- RTL module implementation in Verilog / SystemVerilog
- Testbench covering the full RED -> YELLOW -> GREEN sequence
Four states - IDLE, RED, YELLOW, GREEN - with counter-driven transitions.
- Decision boxes check
cnt_eq_50/cnt_eq_5to decide when to leave the current state. - Each state box drives choices for transitions and asserts output signals (
red_light,yellow_light,green_light).
Integrates traffic_light_ctrl_top with inputs (clk, arst_n, start) and outputs (red_light, yellow_light, green_light).
Datapath and control signals connect the counter, comparator, and FSM to drive the light outputs.
| File / Path | Description |
|---|---|
rtl/counter.v |
Cycle counter for timing each state |
rtl/comparator.v |
Compares counter value against thresholds (cnt_eq_50, cnt_eq_5) |
rtl/traffic_light_ctrl_fsm.v |
FSM for state transitions and output logic |
rtl/traffic_light_ctrl_top.v |
Top-level module integrating counter, comparator, FSM |
tb/traffic_light_ctrl_tb.v |
Testbench for the full RED → YELLOW → GREEN sequence |
sim/compile.f |
File list containing all source files for compilation |
sim/Makefile |
Makefile supporting Vivado (xsim) and Cadence (ncsim) flows |
sim/run_vivado.sh |
Bash script for running Vivado simulation flow |
sim/run_nc.sh |
Bash script for running NC-Sim simulation flow |
Navigate to the simulation directory first:
cd sim# Full simulation flow (compile + elaborate + sim)
make
# Or step-by-step
make compile
make elaborate
make sim
# Launch waveform GUI
make gui# Batch mode
./run_vivado.sh
# GUI mode
./run_vivado.sh guiYou can run NC-Sim using either the Makefile or the provided bash script:
# Full NC-Sim flow
make SIM=nc
# Shortcut
make nc
# Step-by-step with NC-Sim
make SIM=nc compile
make SIM=nc elaborate
make SIM=nc sim
make SIM=nc gui# Batch mode
./run_nc.sh
# GUI mode
./run_nc.sh guiTo remove generated log files and simulation artifacts:
# Using Makefile
make clean
# Using bash scripts
./run_vivado.sh clean
./run_nc.sh clean- File paths for compilation are managed central in
sim/compile.f. - State durations are parameters, so retiming for simulation or different real-world timing is a one-line change.
- Design idles after reset until
startis asserted, then free-runs through the sequence indefinitely.



