Plan the rules of an up/down counter, write one assertion per row, and catch six buggy counters.
Hardware context: A 4-bit up/down counter with synchronous reset, load and count enable. Plan one rule per spec sentence, priority included, and catch every planted counter bug.
A 4-bit counter has a synchronous active-low reset, a load, a count enable and a direction. Turn each spec sentence into a row of your plan, then write one assertion per row.
A copy of your rules is attached to the correct counter and to six buggy ones. The same three scenarios drive them all.
You pass when your count stays at 0 on the correct counter and goes up on every buggy one.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
clk | 1 | stimulus, the same for every design |
rst_n | 1 | stimulus, the same for every design |
load | 1 | stimulus, the same for every design |
ld_val | 4 | stimulus, the same for every design |
en | 1 | stimulus, the same for every design |
up | 1 | stimulus, the same for every design |
cnt | 4 | output of the design under test |
your errors | 32 | your checker's error count |
Full specification
module ctr_rules (
input logic clk, rst_n, load, en, up,
input logic [3:0] ld_val,
input logic [3:0] cnt,
output int errors
);
// your plan rows
endmodule
| Spec sentence (priority from top to bottom) | Result at the next edge |
|---|---|
| rst_n = 0 resets the counter | cnt = 0 |
| load = 1 loads ld_val | cnt = ld_val |
| en = 1 counts in the direction of up (1 = up, 0 = down) | cnt = old cnt + 1 or old cnt - 1, wrapping at 15 and 0 |
| Otherwise the counter holds | cnt unchanged |
Every scenario starts with a reset edge (cycle 1). Scenarios: 1. Load 14 and count up through the wrap; 2. Load 1 while enabled, then count down through zero; 3. Reset in the middle of a count, with a load during reset. Inputs change at falling edges and hold across the next rising edge.
Count each failure in errors from the else action (errors++). For each counter you get alarm = yes or no. For the correct one, you also get the scenario and cycle of your first alarm.
Simulator note: The grading simulator runs a measured subset of SVA. Goto [->n], [=n], sequence or, first_match, intersect, within, cover, ranged delays in an antecedent and $error/$fatal/$stop are refused before simulation. Every assertion needs an else action.
Examples
Example 1
The Correct Counter Must Not Raise an Alarm- Input
Counter: the correct design Scenarios: 3
- Output
alarm = no
Each rule checks the next edge. In scenario 3 reset is held for two edges, with a load on the second. Only the reset row applies there.
Example 2
A Reset Value of 1- Input
Counter: Wrong reset value Scenarios: 3
- Output
alarm = yes
Only the reset row sees it: the count rows compare with the old value, whatever it was.
Example 3
Load Beaten by the Enable- Input
Counter: Load loses to the count enable Scenarios: 3
- Output
alarm = yes
In scenario 2 load and en are both 1. The buggy counter steps down from 0 to 15 instead of loading 1.
Constraints and Contract
- Use only your ports.
- Every assertion has an else action that counts the failure in errors.
- Stay inside the supported SVA subset described in the specification.
Hints
Hint 1
Each register result appears at the next edge. Which implication operator starts the check one edge later?
Hint 2
A lower row applies only when no higher row does. Put that priority into each antecedent.
Hint 3
Compare the new value with $past(cnt). In a 4-bit comparison, 15 + 1 wraps to 0 by itself.
What the grader checks: Your rules run against the correct counter and six variants with one planted bug each, over three fixed scenarios. Passing shows they catch these bugs on this stimulus.
7 checks on Verilator · server. 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 steps and the final capstone