-
关于
`timescale
()
在
Verilog
HDL
模型中,所有时延都用单位时间表述。使用
`timescale
编译器指令将时间单位与实际时间相关联。该指令用
于定义时延的单位
和时延精度。
`timescale
编译器指令格式为:
`timescale
time_unit
/
time_precision
time_unit
和
time_precision
<
/p>
由值
1
、
10<
/p>
、和
100
以及单位
s
、
ms
、
us
、
ns
、
ps
和
fs
组成。例如:
`timescale
1ns/100ps
表示时延单位为
1ns
,
时延精度为
100ps
。
`timescale
编译器指令在模块说明外部出现
,
并且影响后面所有的时延值。例如
:
`timescale
1ns/
100ps
MODULE
AndFunc
(Z,
A,
B);
OUTPUT
Z;
input
A,
B;
and
#
(5.22,
6.17
)
Al
(Z,
A,
B);
//
规定了上升及下降时延值。
endMODULE
p>
编译器指令定义时延以
ns
为单位,并且时
延精度为
1/10
ns
(
100
ps
)。因此,时延值
5.22
对应
5.2
ns,
时延
6.17
对应
6.2
n
p>
s
。如果用如下的
`timescale<
/p>
程序指令代替上例中的编译器指令
,
`timescale
10ns/1ns
那么
5.22
对应
52ns,
6.17
对应
p>
62ns
。
p>
在编译过程中,
`timescale
指令
影响这一编译器指令后面所有模块中的时延值,直至遇到另一个
`timescale<
/p>
指令或
`resetall
指令。
当一个设计中的多个模块带有自身的
`timescale
编译指令时将发生什么?在这种情况下,模拟器总是定位在所有模块的最小时延精度
上,并且所有时延都相应地换算为最小时延精度。
例如,
`timescale
1ns/
100ps
MODULE
AndFunc
(Z,
A,
B);
OUTPUT
Z;
input
A,
B;
and
#
(5.22,
6.17
)
Al
(Z,
A,
B);
endMODULE
`timescale
10ns/
1ns
MODULE
TB;
reg
PutA,
PutB;
WIRE
GetO;
initial
begin
PutA
=
0;
PutB
=
0;
#5.21
PutB
=
1;
#10.4
PutA
=
1;
#15
PutB
=
0;
end
AndFunc
AF1(GetO,
PutA,
PutB);
endMODULE
在这个
例子中,每个模块都有自身的
`timescale
编译器指令
。
`timescale
编译器指令第一次应用于时延。因此,
在第一个模块中,
5.22
对应
5.2
ns,
6.17
对应
6.2
ns;
在第二个模块中
5.21
p>
对应
52
ns,
10.4
对应
104
ns,
15
对应
150
ns
。如果仿真模块
TB
,设计<
/p>
中的所有模块最小时间精度为
100
p
s
。因此,所有延迟(特别是模块
TB
中的延迟)将换算成精度为
100
ps
。
延迟
52
ns
< br>现在对应
5
20*100
ps
,
104
对应
1040*100
ps
,
150
p>
对应
1500*100
ps
。更重要的是,仿真使用
100
ps
为时间精度。如果仿真模块
And
Func
,
由于模块
TB
不是模块
AddFunc
的子模块,模块
TB
中的
`timescale
< br>程序指令将不再有效。
参考资料:
1.
na./thinkker/159517/
关于
verilog
中
timescale
的讨论
在
verilog
< br>中是没有默认
timescale
的。一个没有指定
p>
timescale
的
verilog
p>
模块就有可能错误的继承了前面编译模块的无效
times
cale
参数。
<
/p>
所以在
verilog
的
LRM
中推荐
“
在每个
module
的前面指定
`timescal
e,
并且相应的在最后加一个
`resetall
来确保
timescale
的局部有效
”
为了确认这种用法,
我编写了一个小
小的包含两个模块
module_a
和
module_b
的
testbench
,
其中
module_a,module_b
与
testbe
nch
指定了
不同的
timescale
精度。通过
simulation
的波形可以发现
,Simulator<
/p>
的确在不同的
module
中使用了不同
的
times
精度。
代码如下:
文件名:
module_a.v
`timescale
100ps/1ps
module
a
(clk)
;
input
clk;
wire
clk_a
;
assign
#5
clk_a
=
clk;
endmodule
`resetall
文件名:
module_b.v
`timescale
10ps/1ps
module
b
(clk)
;
input
clk;
wire
clk_b
;
assign
#5
clk_b
=
clk;
endmodule
`resetall
文件名:
testbench.v
`timescale
1ns/10ps