RTL Design #56 · 2026-11-18 · Traffic light FSM · Medium · about 25 min

Pedestrian crossing light

Design ped_light, the controller for a pedestrian crossing. Cars see one of three lights, and pedestrians see walk. The controller sits on green until a pedestrian asks to cross, then runs a fixed sequence:

  1. GREEN: green is 1. It lasts at least 4 cycles. After that it stays green until a request is waiting.
  2. YELLOW: yellow is 1 for exactly 2 cycles.
  3. RED: red and walk are both 1 for exactly 3 cycles.
  4. Back to GREEN.

Exactly one of green, yellow and red is 1 in every cycle, and walk equals red. The outputs depend only on the current state.

Requests. ped_req is sampled on each rising edge. A request is remembered in every state except RED, and a request sampled on an edge can first change the state on the next edge. Remembering stops while the light is RED: requests sampled during RED are dropped, and nothing is waiting when GREEN comes back. A request that is held high for many cycles is just a request on every one of those edges.

Reset. rst_n is synchronous and active low. It puts the controller in the first cycle of GREEN with no request waiting. A ped_req sampled on a reset edge is ignored.

Example. Reset has just been released, ped_req is 1 on edge 7 only. Letters give the light after each edge:

edge 1 2 3 4 5 6 7 8 9 10 11 12 13
ped_req 0 0 0 0 0 0 1 0 0 0 0 0 0
light G G G G G G G Y Y R R R G

Write and run your answer in the browser. The hidden tests check it, and it’s free.