verilog 中的 timescale

原文链接: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
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值