i trying to understand the timescale feature using the below code #################################################


module timing;
`timescale 1ns/1ps
initial begin
$timeformat(-9, 3, "ns", 8);
#1 $display("%t", $realtime); // 1.000ns
#2ns $display("%t", $realtime); // 3.000ns
#0.1ns $display("%t", $realtime); // 3.100ns
#41ps $display("%t", $realtime); // 3.141ns
end
endmodule

################################################# after compiling and simulating using the below commands on Questa 10.3 vlog -reportprogress 300 -work work timing.sv vsim -gui work.timing run

i get the below result:

1.000ns
3.000ns
3.000ns
3.000ns

is that related to timescale or simulation options?

In reply to moustafaali:

Hi

`timescale must be used outside of design units. Directive will be ignored (IEEE Std 1364-2005). Try keeping it outside of design

In reply to srikanth_6313:

i tried that using the below “code 1” but nothing appeared on the result with no errors and no warnings. also i tried the below “code 2” using timeunit 1ns; and timeprecision 1ps; but also gave no results, i mean be no results that the $display function not return anything in the transcript


//code 1
`timescale 1ns/1ps
module timing;
initial begin
$timeformat(-9, 3, "ns", 8);
#1.0ns $display("%t", $realtime); // 1.000ns
#2.0ns $display("%t", $realtime); // 3.000ns
#0.1ns $display("%t", $realtime); // 3.100ns
#41ps $display("%t", $realtime); // 3.141ns
end
endmodule

//code 2
module timing;
timeunit 1ns;
timeprecision 1ps;
initial begin
$timeformat(-9, 3, "ns", 8);
#1 $display("%t", $realtime); // 1.000ns
#2ns $display("%t", $realtime); // 3.000ns
#0.1ns $display("%t", $realtime); // 3.100ns
#41ps $display("%t", $realtime); // 3.141ns
end
endmodule


In reply to moustafaali: Use the vsim command run -all or run 10 ns.

Both codes give me the same results


# 1.000ns
# 3.000ns
# 3.100ns
# 3.141ns

In reply to moustafaali:

I am running Code 1, and getting the correct output. What run commands are you using?


// Code 1
`timescale 1ns/1ps
module timing;
initial begin
$timeformat(-9, 3, "ns", 8);

#1.0ns $display("%t", $realtime); // 1.000ns
#2.0ns $display("%t", $realtime); // 3.000ns
#0.1ns $display("%t", $realtime); // 3.100ns
#41ps $display("%t", $realtime); // 3.141ns
end
endmodule





Output --
# run -all
# 1.000ns
# 3.000ns
# 3.100ns
# 3.141ns
# quit -f


In reply to dave_59:

thanks for your feedback, and excuse me for that mistake because i used to run using “run”. it seem that i forget to update the run time default to 100ns instead of 100ps. because after change the time scale the run time changed to 100ps.