Verification #69 · 2026-12-01 · UVM scoreboard with rare-event stimulus · Medium · about 30 min
Check a bank of saturating bin counters
hist_cnt.sv has four 3-bit bin counters. On any rising clock edge where valid is 1 it accepts one operation, chosen by op:
INC: adds 1 to counterbin. A counter that reaches 7 stays at 7 (it saturates).RD: one clock after the edge that accepted it,rd_validis 1 for one clock andrdataholds the count of counterbinas it was when the read was accepted.CLR: sets all four counters to 0 (binis ignored).
Reset clears the counters. Operations can follow each other on consecutive clocks, or after any number of idle clocks.
Write the verification components in components.sv. The monitor and environment in env.sv are provided, and they use your four classes by name:
hist_item:op(OP_INC,OP_RDorOP_CLR),bin, andgap, the number of idle clocks before the operation (0 to 3). MakeINCthe most common operation by far, reads fairly common, andCLRrare. Make gap 0 the most common value, but let gaps reach 3.hist_seq: sendscountrandom operations.hist_driver: waits out reset, then for each item waitsgapclocks withvalid0, presents the operation for exactly one clock withvalid1, and dropsvalidagain. With gap 0, operations go back to back.hist_scoreboard: the monitor reports every operation, in order, and reads arrive withrdatafilled in. Keep a model of the four counters, count every item inchecked, and compare each read'srdatawith the model (count mismatches inerrors, and report the first few withuvm_error).
One simulator quirk: a dist directly on an enum field doesn't give you the weights you ask for here. Put the weights on an integer and constrain the enum from it.
Run uses tb.sv: 100 random operations into the correct counter. Submit runs your testbench against the correct counter and against four 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.