System tasks $time and $realtime are used to return current simulation time.
'timescale <time unit> <time precision>
Examples
'timescale 1ns/1ps
'timescale 10ns/1ns
'timescale 1ns/1ns
Example-1
In third case, #0.50 delay is (1000ps*0.50) 500 ps, therefore, total delay is 1490+500=1990 ps
In fourth delay, #0.51 delay is (1000*0.51) 510 ps, therefore, total delay is 1990+510= 2500 ps
Last delay is #5 which is equal to 5000 ps, therefore, total delay =2500+5000=7500 ps
Therefore, the simulation blog is as follows:
# run 1000ns
Time=1000 At time #1
Time=1490 At time #0.49
Time=1990 At time #0.50
Time=2500 At time #0.51
Time=7500 End of simulation
Example-2
Second timedelay, #0.49 is multiplied by 10ns (10*0.49=4.9ns) and this value is more than precision value 1ns, therefore, simulator will round of this value to 5ns. The total time delay is 10+5=15 ns
In third case, #0.50 delay is (10ns*0.50) 5 ns, therefore, total delay is 15+5.0=20 ns
In fourth delay, #1.51 delay is (10*1.51) 15.1 ns, therefore, total delay is 20+15.1= 35 ns
Last delay is #5 which is equal to 50 ns, therefore, total delay =35+50=85 ns
Therefore, the simulation blog is as follows:
Time=10000 At time #1
Time=15000 At time #0.49
Time=20000 At time #0.50
Time=35000 At time #1.51
Time=85000 End of simulation
Example-3
Second timedelay, #0.49 is multiplied by 1ns (1*0.49=0.49ns) and this value is less than precision value 1ns. Therefore, the simulator will round off this value to 0 delay as this value is less than 0.50. With the result, The total time delay is (1ns+0ns)=1ns.
In third case, #0.50 delay is (1ns*0.50) 0.5 ns, therefore, the simulator will round of this value to 1 ns. The total delay is (1ns+1ns)=2ns
In fourth delay, #1.51 delay is (1*1.51) 1.51 ns, therefore, the round off delay is 2ns. So the total delay is 2+2= 4 ns
Last delay is #5 which is equal to 5 ns, therefore, total delay =4+5=9 ns
Therefore, the simulation blog is as follows:
Time=1000 At time #1
Time=1000 At time #0.49
Time=2000 At time #0.50
Time=4000 At time #1.51
Time=9000 End of simulation
'timescale <time unit> <time precision>
Examples
'timescale 1ns/1ps
'timescale 10ns/1ns
'timescale 1ns/1ns
Example-1
/ Declare the timescale where time_unit is 1ns // and time_precision is 1ps `timescale 1ns/1ps // NOTE: Testbench is the same as in previous example module top; // To understand the effect of timescale, let us // drive a signal with some values after some delay reg data; initial begin // Initialize the signal to 0 at time 0 units data <= 0; // Advance by 1 time unit, display a message and toggle val #1 $display ("Time=%0t At time #1", $realtime); data <= 1; // Advance by 0.49 time unit and toggle val #0.49 $display ("Time=%0t At time #0.49", $realtime); data <= 0; // Advance by 0.50 time unit and toggle val #0.50 $display ("Time=%0t At time #0.50", $realtime); data <= 1; // Advance by 0.51 time unit and toggle val #0.51 $display ("Time=%0t At time #0.51", $realtime); data <= 0; // Let simulation run for another 5 time units and exit #5 $display ("Time=%0t End of simulation", $realtime); end endmoduleIn first time delay, #1 is multiplied with time 1ns=1000ps (1000*1=1000ps) while time precision is 1ps. second timedelay, #0.49 is multiplied by 1000ps (1000*0.49=490ps) and this value is more than precision value 1ps, therefore, total time delay is 1000+490=1490 ps
In third case, #0.50 delay is (1000ps*0.50) 500 ps, therefore, total delay is 1490+500=1990 ps
In fourth delay, #0.51 delay is (1000*0.51) 510 ps, therefore, total delay is 1990+510= 2500 ps
Last delay is #5 which is equal to 5000 ps, therefore, total delay =2500+5000=7500 ps
Therefore, the simulation blog is as follows:
# run 1000ns
Time=1000 At time #1
Time=1490 At time #0.49
Time=1990 At time #0.50
Time=2500 At time #0.51
Time=7500 End of simulation
Example-2
/ Declare the timescale where time_unit is 1ns // and time_precision is 1ps `timescale 10ns/1ns // NOTE: Testbench is the same as in previous example module top; // To understand the effect of timescale, let us // drive a signal with some values after some delay reg data; initial begin // Initialize the signal to 0 at time 0 units data <= 0; // Advance by 1 time unit, display a message and toggle val #1 $display ("Time=%0t At time #1", $realtime); data <= 1; // Advance by 0.49 time unit and toggle val #0.49 $display ("Time=%0t At time #0.49", $realtime); data <= 0; // Advance by 0.50 time unit and toggle val #0.50 $display ("Time=%0t At time #0.50", $realtime); data <= 1; // Advance by 0.51 time unit and toggle val #1.51 $display ("Time=%0t At time #0.51", $realtime); data <= 0; // Let simulation run for another 5 time units and exit #5 $display ("Time=%0t End of simulation", $realtime); end endmoduleIn first time delay, #1 is multiplied with time 10ns (10*1=10 ns) while time precision is 1ns.
Second timedelay, #0.49 is multiplied by 10ns (10*0.49=4.9ns) and this value is more than precision value 1ns, therefore, simulator will round of this value to 5ns. The total time delay is 10+5=15 ns
In third case, #0.50 delay is (10ns*0.50) 5 ns, therefore, total delay is 15+5.0=20 ns
In fourth delay, #1.51 delay is (10*1.51) 15.1 ns, therefore, total delay is 20+15.1= 35 ns
Last delay is #5 which is equal to 50 ns, therefore, total delay =35+50=85 ns
Therefore, the simulation blog is as follows:
Time=10000 At time #1
Time=15000 At time #0.49
Time=20000 At time #0.50
Time=35000 At time #1.51
Time=85000 End of simulation
Example-3
/ Declare the timescale where time_unit is 1ns // and time_precision is 1ps `timescale 1ns/1ns // NOTE: Testbench is the same as in previous example module top; // To understand the effect of timescale, let us // drive a signal with some values after some delay reg data; initial begin // Initialize the signal to 0 at time 0 units data <= 0; // Advance by 1 time unit, display a message and toggle val #1 $display ("Time=%0t At time #1", $realtime); data <= 1; // Advance by 0.49 time unit and toggle val #0.49 $display ("Time=%0t At time #0.49", $realtime); data <= 0; // Advance by 0.50 time unit and toggle val #0.50 $display ("Time=%0t At time #0.50", $realtime); data <= 1; // Advance by 0.51 time unit and toggle val #1.51 $display ("Time=%0t At time #0.51", $realtime); data <= 0; // Let simulation run for another 5 time units and exit #5 $display ("Time=%0t End of simulation", $realtime); end endmoduleIn first time delay, #1 is multiplied with time 1ns (1*1=1 ns=1000 ps) while time precision is 1ns.
Second timedelay, #0.49 is multiplied by 1ns (1*0.49=0.49ns) and this value is less than precision value 1ns. Therefore, the simulator will round off this value to 0 delay as this value is less than 0.50. With the result, The total time delay is (1ns+0ns)=1ns.
In third case, #0.50 delay is (1ns*0.50) 0.5 ns, therefore, the simulator will round of this value to 1 ns. The total delay is (1ns+1ns)=2ns
In fourth delay, #1.51 delay is (1*1.51) 1.51 ns, therefore, the round off delay is 2ns. So the total delay is 2+2= 4 ns
Last delay is #5 which is equal to 5 ns, therefore, total delay =4+5=9 ns
Therefore, the simulation blog is as follows:
Time=1000 At time #1
Time=1000 At time #0.49
Time=2000 At time #0.50
Time=4000 At time #1.51
Time=9000 End of simulation
Comments
Post a Comment