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