掌握 Verilog $timeformat:精度控制与显示格式化
Verilog `timescale 指令指定仿真时间单位和精度。
Verilog $timeformat 系统函数控制显示语句(如 $display、$strobe)中 %t 格式说明符的报告风格。
语法
$timeformat(<unit_number>, <precision>, <suffix_string>, <minimum field width>);
- unit_number 是源码中所有
`timescale指令中最小的时间精度 - precision 表示当前 timescale 下小数位数
- suffix_string 可选,显示时间单位后缀
| 单位编号 | 时间单位 |
|---|---|
| -3 | 1ms |
| -6 | 1us |
| -9 | 1ns |
| -12 | 1ps |
| -15 | 1fs |
示例 1:1ns/1ps
展示 $timeformat 如何影响时间单位显示格式。
`timescale 1ns/1ps module tb; bit a; initial begin #10.512351; $display("[T=%0t] a=%0b", $realtime, a); $timeformat(-9, 2, " ns"); $display("[T=%0t] a=%0b", $realtime, a); $timeformat(-9, 5, "ns"); $display("[T=%0t] a=%0b", $realtime, a); $timeformat(-12, 3, " ns"); $display("[T=%0t] a=%0b", $realtime, a); $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。
`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
- Verilog 入门:数字电路设计完整教程
- 掌握 Verilog 拼接操作:实用指南
- 深入理解 Verilog 赋值语句:类型、语法与最佳实践
- Verilog阻塞与非阻塞赋值:关键区别详解
- 掌握Verilog函数:高效RTL设计的复用利器
- 理解Verilog任务:函数vs任务、语法与用法全解析
- Verilog 门级设计实战:与/或/非门与 2x1 多路选择器
- Verilog 时钟发生器设计与实现指南
- 掌握 Verilog 数学函数:高效硬件设计的利器
- 理解与打印 Verilog 任意作用域下的 Timescale
- 掌握 Verilog 文件 I/O:打开、读取、写入和关闭
- Verilog 入门指南:Hello World 示例