RTL Design #64 · 2026-11-26 · Elevator FSM · Medium · about 30 min
A four-floor lift controller
Write lift in lift.sv: the controller of a lift that serves four floors, 0 to 3.
Requests come in on req: req[i] = 1 for a clock edge means someone asked for floor i. A request is remembered in pending[i] until floor i is served. All outputs are registers. On each rising edge, let p be pending | req (the old pending set plus the requests on this edge), and look at the first rule that applies:
- Door open (
door_open= 1): the door closes (door_openbecomes 0). The lift stays where it is, andpendingbecomesp. The door is open for exactly one clock. - Request for this floor (
p[floor]= 1): the door opens, andpendingbecomespwith bitfloorcleared. - Nothing pending (
p= 0): nothing changes. - Otherwise the lift moves one floor and
pendingbecomesp. It keeps going in the direction it is travelling (going_up) while any floor ahead of it in that direction is inp. If none is, it turns round:going_upflips and the lift moves one floor in the new direction.
rst_n is a synchronous active-low reset: the lift is at floor 0, door closed, going_up = 1, nothing pending. A request on a reset edge is ignored.
Example, right after reset with req = 4'b0100 for one edge, then 0:
| edge | floor |
door_open |
going_up |
pending |
|---|---|---|---|---|
| 1 | 1 | 0 | 1 | 0100 |
| 2 | 2 | 0 | 1 | 0100 |
| 3 | 2 | 1 | 1 | 0000 |
| 4 | 2 | 0 | 1 | 0000 |
Fill in lift.sv. Run sends one request for floor 2 and prints the outputs after each edge.
Write and run your answer in the browser. The hidden tests check it, and it’s free.