Practice
Cold Shower Token
The shower stalls at the Aspen Hollow campground take brass tokens. Drop one in, and the water starts. A big rubber soap button on the wall pauses the flow without eating your remaining time. The session clock stays frozen while the water is off, which is the whole reason campers accept token showers at all.
Since spring, the complaints book keeps filling with the same entry: token in, nothing out. It happens the morning after the attendant pressed the reset button on the panel. And it happens only when the previous camper walked off mid-shower with the water paused. In that case the reset gives the next camper a full session, then quietly refuses to open the valve. A second press of the soap button fixes it instantly. That is why maintenance has never caught it live.
Your task: the shipped firmware is in your editor. Find the bug and fix it in place.
Interface
| Port | Direction | Type | Description |
|---|---|---|---|
clk | in | 1 bit | Clock |
rst | in | 1 bit | Synchronous reset (active high), the panel button |
token | in | 1 bit | Token accepted, 1 cycle wide |
soap | in | 1 bit | Soap button pressed, 1 cycle wide |
water | out | 1 bit | Valve open, changes only at clock edges |
hold | out | 1 bit | Session paused indicator, changes only at clock edges |
Behavior
- After reset the stall is idle:
water = 0,hold = 0, no time on the clock - A
tokensampled while idle loads a session of exactly 8 cycles:wateris high from the next cycle - A
tokensampled while a session has time left is ignored, paused or not - A
soappulse during a session toggleshold; whilehold = 1the water is off and the clock is frozen - A
soappulse while the stall is idle is ignored - While a session is running unheld, the clock counts down one cycle per cycle
- Each token buys exactly 8 cycles of open valve, no matter how often the session is paused
rst = 1at any rising edge returns the stall to idle, clearing the session time and the pause, whatever was in flight
What the bench checks
- The testbench checks
waterandholdon every cycle - The testbench drives a plain session, an ignored mid-session token, a paused and resumed session, and a soap press while idle
- It also drives the complaint-book case: a reset in the middle of a paused session, followed by a fresh token
Constraints
everything is synchronous to clk; both outputs are decoded from registers and change only at clock edges.
this models the stall controller behind clean one-cycle token and soap pulses. The token mechanism, the valve hardware, and the water are out of scope.
The template contains the shipped controller: fix it in place rather than starting over.
Do not add ports.
Click Run to execute your code. Output will appear here.