Practice
Bottling Line Eject Delay
Line 2 caps six hundred bottles a minute. A camera watches each cap go on, and when one goes on crooked it raises flag for one clock cycle. The conveyor then carries the bad bottle three positions downstream to an air jet that blows it off the line. The conveyor moves exactly one position per clock cycle.
The block that shipped gets the delay wrong: one cycle instead of three. The jet fires while the bad bottle is still two positions away. It blasts a good bottle off the line, and the crooked cap sails on into a shipped case.
Your task: fix the shipped block in place so that eject copies flag with a delay of exactly 3 cycles. Whatever flag was 3 cycles ago is what eject must be now. The three delay registers are already declared and named in the template. The wiring between them is the bug; don't start over.
Interface
| Port | Direction | Type | Description |
|---|---|---|---|
clk | in | 1 bit | Clock, one conveyor position per cycle |
rst | in | 1 bit | Synchronous reset (active high) |
flag | in | 1 bit | Reject flag from the camera, 1 cycle wide |
eject | out | 1 bit | Ejector fire command (registered) |
Behavior
eject reproduces flag delayed by exactly three clock cycles. eject during any cycle equals flag three cycles earlier.
- Pulse shapes are preserved exactly: single-cycle flags come out single-cycle, back-to-back patterns come out unchanged
rst = 1at a clock edge clearsejectand every delay stage; flags already in flight are discarded and must never emerge after the reset- After reset is released,
ejectstays 0 until the first post-reset flag has had its three cycles
One trace tells the whole story: a flag in cycle 1 fires the jet in cycle 4, three positions later.
cycle : 0 1 2 3 4 5
flag : 0 1 0 0 0 0
eject : 0 0 0 0 1 0
What the bench checks
- The testbench checks
ejecton every cycle - A single
flagpulse must produce oneejectpulse exactly three cycles later - Two flags with a one-cycle gap must emerge with the same gap, without extra pulses
- Four consecutive flag cycles must become four consecutive eject cycles after the fixed delay
- Reset while flags are in flight must flush them, prevent ghost ejects, and leave the delay ready for a new flag
Constraints
everything is synchronous to clk and eject is registered.
this models the three-cycle delay between the camera's flag and the air jet. The camera, the conveyor, and the jet hardware are out of scope.
The template contains the shipped implementation: fix it in place rather than starting over. The three delay stages are already declared and the structure is right.
Do not add ports.
Click Run to execute your code. Output will appear here.