15. Find the bug: pulse stretcher
Write a test that passes the correct design and fails every buggy version.
The spec: a one-cycle pulse on trig is too short for a slow receiver, so stretch it.
- When a rising clock edge sees trig = 1, out goes to 1 after that edge and stays 1 for exactly 3 clock cycles, then returns to 0.
- It is retriggerable: an edge that sees trig = 1 while out is already 1 restarts the 3-cycle window from that edge.
- out comes from registers. rst (synchronous, active high) makes out 0 and cancels any window. Registers start unknown, so begin with a reset.
Ports
| Port | Dir | Bits | What it is |
|---|---|---|---|
clk | in | 1 | Clock. |
rst | in | 1 | Synchronous reset, active high. |
trig | in | 1 | Trigger pulse. |
out | out | 1 | Stretched pulse. |
Example
trig is 1 at edge 1 only: out is 1 after edges 1, 2 and 3, and 0 after edge 4.
Writing the test
The test is a table of steps, as on the Verilog playground. Each step can set inputs, tick the clock (clk) a number of times, then check outputs. Inputs start at 0 and registers start unknown, so begin with a reset. It must pass the correct design and fail all 5 buggy versions.
{ "set": { "rst": 0, "en": 1 }, "tick": 3, "expect": { "count": 3 }, "note": "counts up" }Written hints
AI hint
Submissions
No submissions yet. Submit your answer and it shows here. Sign in to keep them.
1 step, 0 with checks.
Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.