有时,需要确保在实例树下为每个模块应用正确的时间单位和精度,尤其是当不同模块使用不同时间刻度并使用时间刻度参数时。
在Verilog, SystemVerilog中打印 `timescale
使用$printtimescale(path)仿真器指令
// timescale
`timescale 1ns/10ps
// top testbench module
module tb();
// DUT instance
dut dut_i();
initial begin
$printtimescale($root.tb); // prints the timescale of this module
$printtimescale($root.tb.dut_i);// prints the timescale dut_i module instance
$printtimescale($root.tb.dut_i.cpu_i);// prints the timescale dut_i.cpu_i module instance
end
endmodule
results:
Time scale of (tb) is 1ps / 1fs
Time scale of (tb.dut_i) is 1ps / 1ps
Time scale of (tb.dut_i.cpu_i) is 1ns / 10ps
在systemverilog类中,可以直接使用这个指令
该条指令,帮助我解决了,一个奇怪的问题。在我的一个package有一个类,假设是a,我加入打印信息或者delay,总是显示不正确,后来加入printtimescale来debug,发现timescale和我想要的不一致。
另外 $timeformat 系统任务也会影响display中%t的格式。调用一次即可。多次调用,最后一次调用生效。
$timeformat(<units>, <precision>, <suffix>, minimum field width>);
units : log base 10 of the unit (eg -9 is ns)
precision : the number of decimal places
suffix : a string (eg "ns")
minimum field width : the minimum field width
如果没有调用过这个系统任务,将会使用默认值(即`timescale设置的值)
units : the simulation precision (10ps in your case)
precision : 0
suffix : null string
minimum field width : 20