五、一些说明关于在testbench里使用`timescale的问题
`timescale是编译器指令,用来定义时延精度和时延单位,命令格式为
`timescale time_unit/time_precision
其中time_unit定义时延单位,即后面模块中出现的时延数值的单位,time_precision定义时延精度。例如
`timescale 1ns/100ps 表示时延单位为1ns,时延精度为100ps。
如果后面有语句 #5.22 a=1;
此时时延值5.22ns应该对应为5.2ns,因为精度为0.1ns。
如果设计中多个模块带有自身的`timescale,编译时模拟器总是定义在所有模块的最小时延精度上,并且所有模块中的时延都自动地换算为到最小试验精度上。
附录:Counter源代码:
`timescale1ns/100ps
moduleCounter (
input CLK,
input RST_N,
output[3:0] CNT
);
reg[3:0] cnt;
assignCNT = cnt;
always@(posedgeCLK, negedge RST_N) begin
if(!RST_N)
cnt <= #5 4'h0;
else
cnt <= #0 cnt + 1'b1;
end
endmodule
Counter_tb源代码:
`timescale1ns/100ps
moduleCounter_tb ;
wire [3:0] CNT ;
reg RST_N ;
reg CLK ;
Counter
DUT (
.CNT (CNT ) ,
.RST_N (RST_N ) ,
.CLK (CLK ) );
//http://wenku.baidu.com/view/cd93f34ecf84b9d528ea7a95.html
initialbegin
#0CLK = 1'b0;
RST_N = 1'b0;
#5RST_N = 1'b1;
end
//50MHz
always#10 CLK = ~CLK;
endmodule |