HOW TO SAMPLE VALUES IN CURRENT TIME FOR ASSERTIONS

Hello guys,
As we all know assertion samples the values in pre pond region. Most of us are suffering to write assertion because of this issue as we are very comfortable with actual simulation time. Here we are going to learn how to sample the value of the signal in current time for assertion. We will also learn how to sample rise and fall of signal in current time.

Problem we face while writing assertion :


Say I want to check my input signal rising edge should be there on posedge or negedge of clock.

Demo_Code : 

property my_p;
  @ (posedge clock or negedge clock) 
  $rose(input);
endproperty

If I simply write my property like above I will not be able to capture any rising edge of input as for assertion sampling is done in pre pond region as we can see in above figure. It will always sample 0 instead of 0 to 1 transition.

SOLUTION :

 ASSUMPTION : CLK is having period of 100ns.

1) I want to check my signal A should be 1 or 0 on posedge of CLK.


DEMO_CODE :

 event e;

  always @ (posedge CLK) begin
    1ns;
    -> e ;
  end

property my_p;
  @ (e)
  1 |-> (A | !A);
endproperty

MY_P : assert property (my_p);

Here I am doing sampling on event e which is triggered on 1ns delay with posedge of CLK. By doing this we are making sure that our sampling of signal happens in current simulation time rather in pre pond region. 1 means always true so on triggering of that event my assertion will check for value of A should be either 1 or 0.

2) I want to check my signal i_a should have rising  edge on posedge of sig_clk.


DEMO_CODE :

 event assert_e;
wire  assert_signal_dummy;

assign #1ns assert_signal_dummy = i_a;

  always @ (posedge sig_clk) begin
    1ns;
    -> assert_e ;
  end

property my_p;
  @ (assert_e)
  1 |->  ( i_a  &&  ! assert_signal_dummy );
endproperty

MY_P : assert property (my_p);


Waveforms :



Here we have taken extra wire assert_signal_dummy for checking the rise in signal i_a. We are assigning i_a to assert_signal_dummy with 1ns delay. Now as we know our sampling for assertion is happening on 1ns delay so we are getting actual signal value ie. i_a will be sampled at 769ns as value 1 where assert_signal_dummy will be sampled as 0 here as we can see in the diagram so basically it show we are having positive edge of i_a at 768ns.

3) I want to check my signal i_a should have falling  edge on posedge of sig_clk.


DEMO_CODE :

event assert_e;
wire  assert_signal_dummy;

assign #1ns assert_signal_dummy = i_a;

  always @ (posedge sig_clk) begin
    1ns;
    -> assert_e ;
  end

property my_p;
  @ (assert_e)
  1 |-> ( ! i_a  &&  assert_signal_dummy );
endproperty

MY_P : assert property (my_p);


Waveforms :




NOTE : Here for generating an event I have used 1ns delay because I am assuming my timescale is 1ns/1ps. You can change that value as per your requirement of clock period and time scale.

Hope this article will be helpful to you guys to develop  assertions in some easier way.

Comments

Popular posts from this blog

'WITH' Operator in SV Coverage

Difference Between m_sequencer and p_sequencer

Cross Auto Bin Max