1. `timescale
`timescale是Verilog中的预编译指令,指定位于它后边的module的时间单位和时间精度,直到遇到新的`timescale指令或者`resetall指令。它的语法如下:
`timescale time_unit / time_precision
假如我们延时x个时间单位,那延时的总时间time = x*time_unit,但最后真正延时的时间是根据time_precision对time进行四舍五入后的结果,如下面的代码所示。
1 `timescale 100ns / 10ns // 时间单位100ns,时间精度10ns 2 module tb; 3 reg [4:0] set; 4 parameter d1 = 20, 5 d2 = 1.5, 6 d3 = 1.54, 7 d4 = 1.55; 8 9 initial begin 10 #d1 set = 0; // real_delay = round(20*100) = 2000ns, 以10ns为精度做四舍五入 11 #d2 set = 1; // real_delay = round(1.5*100) = 150ns 12 #d3 set = 2; // real_delay = round(1.54*100) = 150ns 13 #d4 set = 3; // real_delay = round(1.55*100) = 160ns 14 end 15 16 endmodule
注意事项:
1)时间单位和时间精度只能是1、10和100这三种整数,单位有s、ms、us、ns、ps和fs;
2)时间精度必须小于等于时间单位
2. `timescale时间精度对仿真时间的影响
`timescale的时间精度设置是会影响仿真时间的,如下面几种设置。最后一种设置可能是第一种的一倍还多,并且占用更多的内存,所以如果没有必要,应尽量将时间精度设置得更大一些。
1 `timescale 1ns / 1ns 2 `timescale 1ns / 100ps 3 `timescale 1ns / 10ps 4 `timescale 1ns / 1ps
转载至:https://blog.csdn.net/qq_16923717/article/details/81099833