亿迅智能制造网
工业4.0先进制造技术信息网站!
首页 | 制造技术 | 制造设备 | 工业物联网 | 工业材料 | 设备保养维修 | 工业编程 |
home  MfgRobots >> 亿迅智能制造网 >  >> Industrial programming >> Verilog

Verilog 时间格式

Verilog timescale 指令指定模拟的时间单位和精度。

Verilog $timeformat 系统函数指定 %t $display 等显示语句中的格式说明符报告样式 和 $strobe .

语法

  
  
$timeformat(<unit_number>, <precision>, <suffix_string>, <minimum field width>);

  

单元号 时间单位
-3 1 毫秒
-6 1us
-9 1ns
-12 1ps
-15 1fs

示例 #1:1ns/1ps

下面是一个 $timeformat 的例子 影响时间单位显示的格式。

  
  
`timescale 1ns/1ps

module tb;
  bit 	a;
  
  initial begin
    
    // Wait for some time - note that because precision is 1/1000 of
    // the main scale (1ns), this delay will be truncated by the 3rd
    // position
    #10.512351;
    
    // Display current time with default timeformat parameters
    $display("[T=%0t] a=%0b", $realtime, a);
    
    // Change timeformat parameters and display again
    $timeformat(-9, 2, " ns");
    $display("[T=%0t] a=%0b", $realtime, a);
    
    // Remove the space in suffix, and extend fractional digits to 5
    $timeformat(-9, 5, "ns");
    $display("[T=%0t] a=%0b", $realtime, a);
    
    // Here suffix is wrong, it should not be "ns" because we are
    // setting display in "ps" (-12) 
    $timeformat(-12, 3, " ns");
    $display("[T=%0t] a=%0b", $realtime, a);
    
    // Correct the suffix to ps
    $timeformat(-12, 2, " ps");
    $display("[T=%0t] a=%0b", $realtime, a);
  end
endmodule

  
模拟日志
xcelium> run
[T=10512] a=0
[T=10.51 ns] a=0
[T=10.51200ns] a=0
[T=10512.000 ns] a=0
[T=10512.00 ps] a=0
xmsim: *W,RNQUIE: Simulation is complete.

示例 #2:1ns/100ps

这是上面的相同示例,但时间尺度不同。

  
  
`timescale 1ns/100ps

  
模拟日志
xcelium> run
[T=105] a=0
[T=10.50 ns] a=0
[T=10.50000ns] a=0
[T=10500.000 ns] a=0
[T=10500.00 ps] a=0
xmsim: *W,RNQUIE: Simulation is complete.

示例 #3:100ns/1ns

  
  
`timescale 100ns/1ns

  

#1 代表 100ns,因此 #10 产生 1000ns

模拟日志
xcelium> run
[T=1051] a=0
[T=1051.00 ns] a=0
[T=1051.00000ns] a=0
[T=1051000.000 ns] a=0
[T=1051000.00 ps] a=0
xmsim: *W,RNQUIE: Simulation is complete.


Verilog

  1. Verilog 教程
  2. Verilog 连接
  3. Verilog 作业
  4. Verilog 阻塞和非阻塞
  5. Verilog 函数
  6. Verilog 任务
  7. Verilog 门级示例
  8. Verilog 时钟发生器
  9. Verilog 数学函数
  10. Verilog 时间刻度范围
  11. Verilog 文件 IO 操作
  12. Verilog Hello World