Checking clock period using system verilog assertion

In reply to silverace99:

Should be
(1, pass=check_period(current_time))##0 pass;
This makes the assertion pass or fail.

In reply to raghav kumar:

Hi, can you tell me that why '1 is used in ('1,current_time=$realtime)?
Also whats the difference if we write 1 instead of '1 or if we write any other number 2,3 etc.

In reply to akashsoni29:

Actually, it should be 1’b1 as that is the standard definition of “true”.
Of course, any number other than zero would work.
I had a typo when I wrote '1,apologies.
Better stick to a standard.
Ben

In reply to ben@SystemVerilog.us:

FYI: '1 used in a self-determined context is the same as 1’b1.

In reply to ben@SystemVerilog.us:

Hi Ben,

Ive been following your book on assertions(SystemVerilog Assertions Handbook, 4th Edition) and on page 331 it says:

property period_chk;
realtime current_time, deltat;// deltat used for debug, as a temp
('1,current_time = $time) ##1 (1, deltat=current_time) ##0 deltat == 10ns;
endproperty ap_time:

assert property(@(posedge clk) period_chk);

should there be a difference in the underlined portion.

regards
Vijay

In reply to vijay kumar uba:

I don’t know where that property came from. The correct answer is
(('1,current_time=$realtime) |=>(clk_period==$realtime-current_time));
Ben

In reply to ben@SystemVerilog.us:

Hi Ben
What is difference when declaring clk_period to be real type instead of realtime type?

In reply to peter:

There is no difference between the keywords real and realtime. Very early versions of Verilog did not specify the precision of “whole” datatypes like time, integer, realtime, real. Implementations could choose different precisions to get the best performance in different situations. Later versions have now fixed the precision so there is no longer any difference.

In reply to dave_59:
From a “readability” standpoint, it seems to make more sense to type a variable that deals with “time” as realtime instead of real. But is there an issue by declaring a variable real and then comparing that with a value obtained from $realtime?
1800’2017: 5.8 Time literals
Time is written in integer or fixed-point format, followed without a space by a time unit (fs ps ns us ms s). For example: 2.1ns 40ps The time literal is interpreted as a realtime value scaled to the current time unit and rounded to the current time precision.

This, if I do


timeunit 1ns;  timeprecision 100ps;
initial begin  
  real vr; 
  realtime vt;
  vr=2.0; // What if I wrote vr=$realtime? Any difference 
  vt=$realtime;
  #12;
  if($realtime == vr*1ns) action(); 
   // DO I need the *1ns? 
  if($realtime == vt) action(); 
   // Here you definitely don't need the *1ns because 
   // VT was declared as realtime 

Question: Are my statements above correct?
Somehow, that makes more sense to me.

Hi Ben,

For the checking the clock period, can you please check if this way of writing is correct ?

I am using a var to send to the the property which can be any freq (XMHz). So if its 10MHz freq, then the clk period is 100ns, so i will ensure that the clk is high for 50ns and low for next 50ns giving me a 100ns clk period.

timeunit 1ns;
property pclk (int freq);
int lv;
lv = 1.0/freq;

ref_clk[*lv] |-> ! ref_clk[*lv];
endproperty

assert property (@(posedge clk) pclk(10);

In “sig[*n]”, n has to be a static number.

So, your code is non-complilable.
Also, if freq==10, then in
ref_clk[*lv] |-> ! ref_clk[*lv]; you get
ref_clk[*0.1] |-> ! ref_clk[*0.1];
// which is nonsense, sorry!
Ben