Traffic Light Controller with Pedestrian Request

Problem Description

Design a traffic light FSM that normally cycles GREEN (4 cycles) -> YELLOW (2 cycles) -> RED (4 cycles) -> back to GREEN, repeating forever. If ped_req is pulsed while the light is GREEN, the FSM must still finish the current GREEN duration (for safety, it doesn't cut green short), then go through YELLOW as normal, then hold RED for an EXTENDED 6 cycles (instead of 4) with ped_walk asserted for the first 4 of those 6 RED cycles, giving pedestrians a safe walk window. If ped_req arrives during YELLOW or RED, it's captured and honored on the very next RED phase. If no ped_req was captured, RED lasts the normal 4 cycles and ped_walk stays low throughout.
Interface Table
Port | Direction | Width | Description |
|---|---|---|---|
clk | input | 1-bit | Positive-edge triggered clock |
reset | input | 1-bit | Active-high synchronous reset; goes to GREEN, count=0 |
ped_req | input | 1-bit | Pulse; captured any time, honored on the next RED phase |
light | output | 2-bit | Registered: 00=RED, 01=YELLOW, 10=GREEN |
ped_walk | output | 1-bit | Registered; high during first 4 cycles of an extended RED |
Edge Cases
ped_req pulses during GREEN → GREEN still completes its full 4 cycles (not cut short)
ped_req pulses during RED itself (after RED has already started) → NOT honored this RED phase, must wait for the next RED phase
Multiple ped_req pulses before the next RED → treated as a single request (no queuing/counting)
reset fires mid-cycle → immediately returns to GREEN, count and pending request clear
No ped_req ever → RED is always exactly 4 cycles, ped_walk never asserts
All Scenarios
Scenario | Key State | Output fires? |
|---|---|---|
Normal cycle, no ped_req | GREEN→YEL→RED(4) | ped_walk=0 throughout ✗ |
ped_req during GREEN → next RED extended | RED(6) | ped_walk=1 for 4 cycles ✓ |
ped_req during RED itself (too late) | pending cleared | honored NEXT red only ✗ |
Reset mid-FSM | GREEN, count=0 | ped_walk=0 ✗ |
ped_req pulsed twice before RED | single request | ped_walk=1 once, not doubled ✓ |
Verilog
Code Editor Access
Log in to write, run and submit your solution to this interview question. It's free.
