IMPORTANT NOTICE: Please be advised that the Verification Academy Forums will be offline for scheduled maintenance on Sunday, April 6th at 2:00 US/Pacific.
Is there any way to detect the timeunit from `timescale
For Example, I have a generic code like this where some $display is there some string in needs to change as per the timescale.
`timescale 1ns/1ns
module test();
realtime var_1;
initial begin
#10;
if(detect_timescale == 1ns) begin
suffix=e-9;
end
var_1 = $realtime;
$display("var_1=%f%s",var_1,suffix);
end
endmodule
I dont want to use %t since I need to change it manually each time when I am running with different timescale.
My aim is to convert the time captured in var_1 to seconds regardless of the unit Need some operation to perform that.
Please ignore the arrow anti-pattern, basically you can try to cast to int to get the time unit
`timescale 1ns/1fs
module test;
initial
begin
if (int'(1us) == 1) begin
$display("It's us");
end
else begin
if (int'(1ns) == 1) begin
$display("It's ns");
end
else begin
if (int'(1ps) == 1) begin
$display("It's ps");
end
else begin
if (int'(1fs) == 1) $display("It's fs");
end
end
end
end
endmodule
It gives
# KERNEL: It's ns
If the time unit matches the value in the cast then the expression int’(1[timeunit]) == 1 will become true.