In reply to muralidar:
I used your model as a guideline. Usually, in assertions, clocks are used to sample signals. You used events on A, instead of sampling A based on a clock.
The model I wrote seems to do what you want. I used the sequence_match_item with a function call to do the last calculations. Also, realtime is real, the count is integer. I did a type cast.
/*I need to calculate the width of the particular pulse of signal A and
should compare with the particular register based on cnt no.so here cnt_no can be 1 to 32;
Please help how can i write generic assertion code for this. */
import uvm_pkg::*; `include "uvm_macros.svh"
module TB;
bit clk, A;
// default clocking @(posedge clk); endclocking
initial forever #10 clk=!clk;
bit[3:0] cnt;
int v_t, v_t_hi;
bit [31:0] cnt_reg_1=32'H12345678;
bit [31:0] cnt_reg_2=32'H9ABCDEF0;
function void check_cnt(realtime vt_hi);
automatic int vthi;
vthi=int'(vt_hi); // Casting needed? Better practice!
cnt++;
if(cnt ==0)
a0: assert(vthi == cnt_reg_1[11:0]);
if(cnt == 1)
a1: assert(vthi == cnt_reg_1[23:12]);
if(cnt ==2)
a2: assert(vthi == cnt_reg_2[11:0]);
if(cnt ==3)
a3: assert(vthi == cnt_reg_2[23:12]);
endfunction : check_cnt
property p_width;
realtime v_t, v_t_hi;
@(posedge A) (1, v_t = $realtime) ##0
@(negedge A) (1, v_t_hi = $realtime-v_t, check_cnt(v_t_hi));
endproperty
cover property(p_width);
initial begin
repeat(200) begin
@(posedge clk);
if (!randomize(A) with
{ A dist {1'b1:=1, 1'b0:=3};
}) `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
- SVA Handbook 4th Edition, 2016 ISBN 978-1518681448
- A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
- Using PSL/SUGAR for Formal and Dynamic Verification 2nd Edition, 2004, ISBN 0-9705394-6-0
- Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn 978-1539769712
- Component Design by Example ", 2001 ISBN 0-9705394-0-1
- VHDL Coding Styles and Methodologies, 2nd Edition, 1999 ISBN 0-7923-8474-1
- VHDL Answers to Frequently Asked Questions, 2nd Edition ISBN 0-7923-8115