9. Find the bug: mod-12 counter
This time you write the test, not the design. Several engineers implemented the spec below; one version is correct and the others each hide one bug. Write a step table that passes the correct design and fails every buggy one.
The spec: a counter that counts 0, 1, ..., 11 and then wraps to 0, like the hours on a 12-hour clock face numbered from 0.
- On each rising clock edge: rst = 1 sets count to 0; otherwise, when en = 1, count goes up by one, and from 11 it goes to 0; when en = 0, count holds (even at 11).
- tc (terminal count) is combinational: it is 1 when count is 11 and en is 1, meaning "the next edge wraps".
- rst is synchronous and active high. Registers start unknown, so begin your test with a reset.
Ports
| Port | Dir | Bits | What it is |
|---|---|---|---|
clk | in | 1 | Clock. |
rst | in | 1 | Synchronous reset, active high. |
en | in | 1 | Count enable. |
count | out | 4 | The count, 0 to 11. |
tc | out | 1 | count is 11 and en is 1. |
Example
After reset count = 0. With en = 1, eleven edges later count = 11 and tc = 1; one more edge gives count = 0 and tc = 0.
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.