The two-line counter specification has been answered, question by question. Build the counter it now describes: counting, holding, wrapping after 9, a clear that wins over enable, and a one-cycle wrap pulse.
Hardware context: A decade counter and a small UART transmitter, each with a short written specification. Building a counter whose wrap and clear rules match the agreed reading.
The lesson's specification read "The counter counts up when enable is high. After 9 it goes back to 0." It could be read three ways. The verification engineer sent the open questions to the owner of the specification, and the answers are below.
Write the counter they describe. The bench drives each pattern and reads the count after every clock, so every rule shows.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
scenario | 4 | input of each check |
Full specification
| Question | Answer from the owner of the specification |
|---|---|
| Every clock, or every press? | Every rising edge of clk while en is 1. |
| "After 9" means? | After the value 9 the count goes to 0: it shows 0 to 9. |
| Enable low? | The count holds. |
| Reset? | rst is synchronous and active high: count becomes 0 at the next rising edge. |
| A clear input? | clr is synchronous: count becomes 0 at the next rising edge. If clr and en are both 1, clr wins. |
| A wrap signal? | wrap is 1 for exactly the one cycle after the edge where count went from 9 to 0 by counting. A clear or a reset never makes a wrap pulse; both set wrap to 0. |
Examples
Example 1
Enable Held High for 16 Clocks- Input
en 1111111111111111, clr 0000000000000000
- Output
wrap_pulses = 1, after_1 = 1, after_2 = 2, after_3 = 3, after_4 = 4, after_5 = 5, after_6 = 6, after_7 = 7, after_8 = 8, after_9 = 9, after_10 = 0, after_11 = 1, after_12 = 2, after_13 = 3, after_14 = 4, after_15 = 5, after_16 = 6
Sixteen enabled clocks: 1 to 9, then 0 and on to 6. One wrap pulse, after the clock that went from 9 to 0.
Example 2
Enable with Gaps: The Count Holds While En Is 0- Input
en 1100111000111111, clr 0000000000000000
- Output
wrap_pulses = 1, after_1 = 1, after_2 = 2, after_3 = 2, after_4 = 2, after_5 = 3, after_6 = 4, after_7 = 5, after_8 = 5, after_9 = 5, after_10 = 5, after_11 = 6, after_12 = 7, after_13 = 8, after_14 = 9, after_15 = 0, after_16 = 1
With en at 0 the count holds: it stays 2 for two clocks and 5 for three.
Example 3
Clear at Count 5 While En Is High- Input
en 1111111111111111, clr 0000010000000000
- Output
wrap_pulses = 1, after_1 = 1, after_2 = 2, after_3 = 3, after_4 = 4, after_5 = 5, after_6 = 0, after_7 = 1, after_8 = 2, after_9 = 3, after_10 = 4, after_11 = 5, after_12 = 6, after_13 = 7, after_14 = 8, after_15 = 9, after_16 = 0
The clear arrives with the count at 5 and en still 1. Clear wins, so the next count is 0, and counting carries on from there.
Constraints and Contract
- Keep the module name and the ports.
- Each case starts with two clocks of reset.
Hints
Hint 1
Write the priority in order: reset or clear first, then counting.
Hint 2
wrap is a flip-flop too: decide its next value from count and en at the same edge.
Hint 3
After 9 the next count is 0, not 10.
What the grader checks: Nine patterns of en, clr and rst, each 16 clocks after two clocks of reset. The bench reads the count after every clock and counts the cycles wrap is 1. It does not test what happens with x on an input, or longer than 16 clocks.
9 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path