对`timescale的深入理解

  • Post author:
  • Post category:其他


#1,

The question is,timescale min setting is what? It is for what?

1.1 timescal


e只具有仿真意义,是仿真的精度,


在可编程器件的逻辑设计时,将它定义为所用

的器件的引脚到引脚延时

,这样可以仿真可编程器件的固有延时。在进行语言及仿真时,逻辑语句的执行时间是没有延时的,在语句中人为加入延时语句,使得仿真的逻辑结果接近综合布线后的仿真结果,也接近实际器件运行时的效果。

至于最小时间单位,我只见过飞秒(fs)

1.2 这个是仿真用的,不是真正时钟频率。

比如你写`timescale 1ns / 1ps

那么写#1就是延时1ns,

1ps是仿真的精度。

#2, Timescale设置在顶层文件设置,模块设置的规则


1. `timescale 1ns / 1ps,含义为:时延单位为1ns,时延精度为1ps。


​2. 在编译过程中,`timescale会影响其后面所有模块中的时延值,直至遇到另一个


`timescale指令或`resetall指令。


3. 当一个设计中的多个模块带有自身的`timescale编译指令时,

模拟器将定位



在所有模块的最小时延精度上,并且所有时延都相应地换算为最小时延精度


在实际应用过程中,如网口IP CORE调试过程中,就会出现不同文件的module在不同的时间单位和精度的情况之下,因此,有必要对这个问题进行深入透彻地了解和分析。下面进行详细分析。

I.                    在顶层文件里instantiates each module,本身不写`timescale命令,但据说对modelsim的默认情况是`timescale 1ps/1ps,现看看波形图和各模块程序:

待测信号

Posedge time

`timescale

延迟时间表达式

b, d, f

5 ns

NONE

NONE

A

5 ns + 1.6 ns

1ns / 100ps

#1.55

C

5 ns + 1.55 ns

1ns / 10ps

#1.55

e

5 ns + 0.16 ns

100ps / 10ps

#1.55

分析:top文件完全没有干涉各模块的时间单位和精度。

程序如下:

// top.v文件,无` timescale

module top(a,b,c,d,e,f

);

output a,c,e;

input  b,d,f;

timescale_t t_1(.A(a),.B(b));

timescale_tt t_2(.C(c),.D(d));

timescale_ttt t_3(.E(e),.F(f));

endmodule

//timescale_t.v文件

`timescale 1ns / 100ps

module timescale_t(

A,B

);

output A;

input  B;

assign #1.55 A =  B;

endmodule

//timescale_tt.v文件

`timescale 1ns / 10ps

module timescale_tt(

C,D

);

output C;

input  D;

assign  #1.55 C = D;

endmodule

//timescale_ttt.v文件

`timescale 100ps / 10ps

module timescale_ttt(

E,F

);

output E;

input  F;

assign #1.55 E = F;

endmodule

II.                 在顶层文件里写上`timescale 1ns/1ps,其他设置和程序不变,看看波形图:

待测信号

Posedge time

`timescale

延迟时间表达式

b, d, f

5 ns

1ns / 1ps

NONE

A

5 ns + 1.660 ns

1ns / 100ps

#1.55

C

5 ns + 1.550 ns

1ns / 10ps

#1.55

E

5 ns + 0.160 ns

100ps / 10ps

#1.55

分析:可


见如果顶层写明了`timescale命令,那么它将会影响其模块内部各子模块的精度,而不会对时间单位产生任何影响


。但是,如果top.v中的时间精度比某个子模块的大,程序将如何处理呢?答案是,结果和I中的一样!

III.               在顶层文件的各实例化文件前面写上不同的`timescale,其他不变,看看效果:

显示,在一个module内部不可以编写`timescale命令!程序如下:

`timescale 1ns/100ps

module top(a,b,c,d,e,f

);

output a,c,e;

input  b,d,f;

`timescale 1ns / 100ps

timescale_t t_1(.A(a),.B(b));

`timescale 1ns / 10ps

timescale_tt t_2(.C(c),.D(d));

`timescale 100ps / 10ps

timescale_ttt t_3(.E(e),.F(f));

endmodule

对书中和网上疯狂转载的一段话进行修正:


“一

个设计中的多个模块带有滋生的`timescale指令,模拟器总是定位在所有模块的最小时延精度上

。”

这里的所有模块,

指的是跟模块和某一个子模块相比较,并采用二者之间最小的精度

,对于多个并行的子模块而言,它们是不会相互干扰对方的精度的。