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): cnt becomes cnt + val, clamped at 255. If it clamped, sat is 1 for the next cycle.
  • THR (op = 2): the threshold becomes val. A threshold of 0 disables the interrupt.
  • ACK (op = 3): cnt becomes 0 and irq becomes 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: random op (only 1, 2 or 3), val and gap (idle clocks before the item). Make ADD the most common operation, then THR, with ACK least often. Make val often 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). Constrain gap to 0 to 3.
  • cnt_seq: sends count random items.
  • cnt_driver: waits out reset, waits gap clocks, then drives op and val for exactly one clock, and returns op to 0. With gap 0, 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 compare cnt, irq and sat with the model on every item. Count items in checked and mismatches in errors; report the first few with uvm_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.