I want to print the $realtime - current time so that i can see what frequency it is when it fails? Is there way to do it using display statements or other methids?
It looks like you need to add an acceptable tolerance because of the resolution of the real type. Something like:
v >= period - 1fs || v <= period +1fs
Ben , need to know why without tolerance it wont work .
with real datatype - what i have observed is always we need to add the tolerance range for checker .
Understanding real, realtime and shortreal variables of SystemVerilog
This post will help you to understand the difference between real, realtime and shortreal data types of SystemVerilog and its usage.
We faced some issue with real and realtime variable while writing a timing check.
Below is a simplified example of that check.
`timescale 1ns/1fs;
module test;
real a,b;
realtime t1, t2;
initial
begin
#1ns;
t1 = $realtime;
#1.8ns;
t2 = $realtime;
b = 1.8;
a = t2 - t1;
if(a == b)
$display("PASS a = %f b = %f", a,b);
else
$display("FAIL a = %f b = %f", a,b);
end
endmodule
/* and here is what we got the display
FAIL a = 1.800000 b = 1.800000
How that happened !!! is really 1.800000 != 1.800000 !!!!
Now let's try something else, instead of using real we use shortreal */
`timescale 1ns/1fs;
module test;
shortreal a,b;
realtime t1, t2;
initial
begin
#1ns;
t1 = $realtime;
#1.8ns;
t2 = $realtime;
b = 1.8;
a = t2 - t1;
if(a == b)
$display("PASS a = %f b = %f", a,b);
else
$display("FAIL a = %f b = %f", a,b);
end
endmodule
/* Now the result was as expected !!
PASS a = 1.800000 b = 1.800000
To understand this lets go to SystemVerilog LRM. As per LRM
The real data type is from Verilog-2001, and is the same as a C double.
The shortreal data type is a SystemVerilog data type, and is the same as a C float. */