Assert number of times an event occurs

In reply to ben@SystemVerilog.us:
Here is a potential solution, assuming “n” is a constant at elaboration time.


import uvm_pkg::*; `include "uvm_macros.svh" 
module top; 
  timeunit 1ns;     timeprecision 100ps;    
    bit clk, a, b, c;  
    let n=4;
    default clocking @(posedge clk); endclocking
    initial forever #10 clk=!clk; 
    //  Sig "a" shall change values "n" times between sig "b" and sig "c".
    ap_abc: assert property( $rose(b) |-> $changed(a)[=n] intersect c [->1]);
   
    // Sig "a" shall ==1 values "n" times between sig "b" and sig "c".
    ap_abc2: assert property( $rose(b) |-> a[=n] intersect c [->1]);

    initial begin 
      repeat(200) begin 
        @(posedge clk);   
        if (!randomize(a, b, c)  with 
        { a dist {1'b1:=1, 1'b0:=2};
         b dist {1'b1:=1, 1'b0:=6};
         c dist {1'b1:=1, 1'b0:=10};
        
      }) `uvm_error("MYERR", "This is a randomize error")
    end 
    $stop; 
  end 
endmodule     

Ben Cohen
http://www.systemverilog.us/ ben@systemverilog.us
For training, consulting, services: contact Home - My cvcblr


See Paper: VF Horizons:PAPER: SVA Alternative for Complex Assertions | Verification Academy