Traffic Light FSM Controller
advanced · state_machine · 310 XP
Sign in to write your solution, run it in the simulator and submit it for grading.
Sign in or create a free account →Problem
Traffic Light FSM Controller
Implement a 3-state **traffic light controller** with **configurable timer durations**. Supports RED → GREEN → YELLOW → RED cycle.
**States & Durations**
- RED: `red_duration` cycles (default 30)
- GREEN: `green_duration` cycles (default 20)
- YELLOW: `yellow_duration` cycles (default 5)
**Interface**
| Port | Direction | Width | Description |
|------------------|-----------|-------|-------------------------------------|
| `clk` | input | 1 | Clock |
| `rst` | input | 1 | Sync reset (start at RED) |
| `red_duration` | input | 8 | RED light duration (cycles) |
| `green_duration` | input | 8 | GREEN light duration (cycles) |
| `yellow_duration`| input | 8 | YELLOW light duration (cycles) |
| `red` | output | 1 | RED light on |
| `green` | output | 1 | GREEN light on |
| `yellow` | output | 1 | YELLOW light on |
**Behavior:**
1. Reset → RED state, counter = 0
2. Count cycles; when counter == red_duration, transition to GREEN
3. Count cycles; when counter == green_duration, transition to YELLOW
4. Count cycles; when counter == yellow_duration, transition to RED
5. Cycle repeats
**Outputs:** One light on at a time (one-hot).
**Example:** red=30, green=20, yellow=5 → 55-cycle period
Constraints
- One-hot output: exactly one light on at a time.
- Synchronous state transitions (on clock edge).
- Reset initializes to RED with counter=0.
- Configurable durations via input ports.
Examples
Input: red_duration=30, green_duration=20, yellow_duration=5
Output: RED for 30 cycles, GREEN for 20, YELLOW for 5, repeat
Normal cycle
Input: rst=1
Output: red=1, green=0, yellow=0
Reset to RED
Common questions
- What does the Traffic Light FSM Controller problem ask you to build?
- Traffic Light FSM Controller Implement a 3-state **traffic light controller** with **configurable timer durations**. Supports RED → GREEN → YELLOW → RED cycle.
- What constraints does Traffic Light FSM Controller have?
- One-hot output: exactly one light on at a time.; Synchronous state transitions (on clock edge).; Reset initializes to RED with counter=0.; Configurable durations via input ports.
- What is an example input and output for Traffic Light FSM Controller?
- Input red_duration=30, green_duration=20, yellow_duration=5 gives output RED for 30 cycles, GREEN for 20, YELLOW for 5, repeat. Normal cycle
- Which Verilog concepts does Traffic Light FSM Controller practise?
- state_machine, FSM, control, interview, timer.