Verification #60 · 2026-11-22 · Scoreboard with sticky flags and corner stimulus · Medium · about 30 min
Build the testbench for a threshold event counter
cnt.sv is an 8-bit saturating event counter with a threshold interrupt. Each clock edge where op is not 0 performs one operation:
- ADD (
op= 1):cntbecomescnt + val, clamped at 255. If it clamped,satis 1 for the next cycle. - THR (
op= 2): the threshold becomesval. A threshold of 0 disables the interrupt. - ACK (
op= 3):cntbecomes 0 andirqbecomes 0.
After the operation, if the threshold is not 0 and cnt is at least the threshold, irq is set. It stays set until an ACK. cnt, irq and sat are registered: they show the result of the previous edge. sat is 1 only for the cycle after an ADD that clamped.
Write the verification components in components.sv. The monitor and environment in env.sv are provided, and they use your four classes by name:
cnt_item: randomop(only 1, 2 or 3),valandgap(idle clocks before the item). Make ADD the most common operation, then THR, with ACK least often. Makevaloften tiny (0 to 3, so counts and thresholds meet exactly and a threshold of 0 happens), sometimes medium (4 to 40), and sometimes large (200 to 255, so the counter saturates). Constraingapto 0 to 3.cnt_seq: sendscountrandom items.cnt_driver: waits out reset, waitsgapclocks, then drivesopandvalfor exactly one clock, and returnsopto 0. Withgap0, the next item follows on the very next clock.cnt_scoreboard: for each item the monitor reports, in order, apply it to a model (counter, threshold, interrupt flag), then comparecnt,irqandsatwith the model on every item. Count items incheckedand mismatches inerrors; report the first few withuvm_error. The monitor fills in the result fields (cnt,irq,sat) of the item from the pins, one clock after the operation.
Run uses tb.sv: 50 random items into the correct counter. Submit runs your testbench against the correct counter and five faulty ones. Your scoreboard must stay quiet on the first and catch each of the others.
Write and run your answer in the browser. The hidden tests check it, and it’s free.