21. Find the bug: 101 detector
Write a test that passes the correct design and fails every buggy version.
The spec: one bit arrives on din at each rising clock edge. found is 1 for the clock cycle right after the edge that received the final 1 of the pattern 1, 0, 1, and 0 otherwise (a Moore output). Matches may overlap: in 10101 the middle 1 ends the first match and starts the second, so found is 1 twice.
rst (synchronous, active high) forgets everything received so far. 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. |
din | in | 1 | Serial input. |
found | out | 1 | 1 for one cycle after each 101. |
Example
Input 1, 0, 1, 0, 1: found is 1 after the third bit and again after the fifth.
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 4 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.