当前位置:网站首页>Verilog's time system tasks - $time, $stime, $realtime
Verilog's time system tasks - $time, $stime, $realtime
2022-07-29 02:57:00 【Lonely single knife】
List of articles
summary
When doing simulation , It is often necessary to obtain the simulation time in order to understand the test situation of the tested module .Verilog Syntax provides 3 A system task ----$time、$stime、$realtime, this 3 All system tasks can be simulated ( Unable to synthesize ) Get the time value of the current simulation time , But its use also has a little difference .
$time
Call the system task $time, Will get one 64 Bit integer Type variable , It represents the simulation time when the system task is called . It should be noted that , Its value will be automatically scaled to `timescale The time unit defined by the task . Here's an example :
`timescale 10 ns / 1 ns
module tb_time_test;
reg set;
parameter p = 1.55;
initial begin
$monitor($time,,"set=",set);
#p set = 0;
#p set = 1;
end
endmoduleThe simulation results are as follows :

- In the example above , The simulation time unit is defined as 10ns, Time accuracy is defined as 1ns.
- The first 1 That's ok ,set Unassigned , So the output set = x, The time is 0
- The first 2 That's ok ,set The assignment is 0, So the output set = 0, The time is 1.55*10=15.5ns, Because the accuracy is 1ns, So round to 16ns, At the same time, because the time unit is 10ns, So it doesn't mean 16ns, It means rounded 2( Company 10ns)
- The first 3 That's ok ,set The assignment is 1, So the output set = 1, The time is 16+1.55*10=31.5ns, Because the accuracy is 1ns, So round to 32ns, At the same time, because the time unit is 10ns, So it doesn't mean 32ns, It means rounded 3( Company 10ns)
Next, we change the simulation time unit of the above code to 1ns, The time precision is reserved as 1ns, It looks easier to understand .
`timescale 1 ns / 1 ns
module tb_time_test;
reg set;
parameter p = 1.55;
initial begin
$monitor($time,,"set=",set);
#p set = 0;
#p set = 1;
end
endmoduleThe simulation results are as follows :

- In the example above , The simulation time unit is defined as 1ns, Time accuracy is defined as 1ns.
- The first 1 That's ok ,set Unassigned , So the output set = x, The time is 0
- The first 2 That's ok ,set The assignment is 0, So the output set = 0, The time is 1.55*1=1.55ns, Because the accuracy is 1ns, So round to 2ns, The unit of time is 1ns, So directly show 2( Company 1ns)
- The first 3 That's ok ,set The assignment is 1, So the output set = 1, The time is 2+1.55*1=3.55ns, Because the accuracy is 1ns, So round to 4ns, The unit of time is 1ns, So directly show 4( Company 1ns)
$stime
Call the system task $stime, Will get one 32 Unsigned bit integer Type variable , It represents the simulation time when the system task is called . It should be noted that , Its value will also be automatically scaled to `timescale The time unit defined by the task .
The usage of this system task is basically the same as $time It's the same , Just because it only 32 position , Therefore, the time range represented will be relatively small , Be careful not to overflow when using .
$realtime
Call the system task $realtime, Will get one real Type variable , It represents the simulation time when the system task is called . It should be noted that , Its value will be automatically scaled to `timescale The time unit defined by the task .
Because its return value is a real number real type , So it can represent decimal time . Also take the above code as an example :
`timescale 10 ns / 1 ns
module tb_time_test;
reg set;
parameter p = 1.55;
initial begin
$monitor($realtime,,"set=",set);
#p set = 0;
#p set = 1;
end
endmoduleThe simulation results are as follows :

- In the example above , The simulation time unit is defined as 10ns, Time accuracy is defined as 1ns.
- The first 1 That's ok ,set Unassigned , So the output set = x, The time is 0
- The first 2 That's ok ,set The assignment is 0, So the output set = 0, The time is 1.55*10=15.5ns, Because the accuracy is 1ns, So round to 16ns, At the same time, because the time unit is 10ns, So it doesn't mean 16ns, It means 1.6( It can express decimals , Company 10ns)
- The first 3 That's ok ,set The assignment is 1, So the output set = 1, The time is 16+1.55*10=31.5ns, Because the accuracy is 1ns, So round to 32ns, At the same time, because the time unit is 10ns, So it doesn't mean 32ns, It means 3.2( It can express decimals , Company 10ns)
Summary and reference
- $time、$stime、$realtime These three system tasks can obtain the current simulation time , The difference lies in the type of time value returned , General applications use $time that will do
- During the simulation, the simulation time can be observed 、 Monitor the test condition of the tested module , It is helpful to improve the test efficiency
Reference material 1:IEEE Standard for Verilog Hardware Description Language(IEEE Std 1364-2005)
- Blog home page :wuzhikai.blog.csdn.net
- This paper is written by Lonely single blade original , First appeared in CSDN platform
- Do you have any questions , You can communicate with me in the comment area !
- It's not easy to create , Your support is the biggest driving force for me to continuously update ! If this article helps you , Please give me more praise 、 Reviews and collections !
边栏推荐
- 混淆矩阵学习笔记
- R语言ERROR: compilation failed for package ‘****‘
- 场景分类任务可用数据集(部分)
- 百度副总裁李硕:数字技术加持下中国劳动力成本上升是好事
- Cloud development workers must go to work fishing and paddling wechat applet source code
- 6-21 vulnerability exploitation MySQL weak password cracking
- 10.书写规则-文件搜寻
- Zone --- line segment tree lazy marking board sub problem
- 每周推荐短视频:如何让产品开发更加有效?
- RestfulAPI——C#——增加header用户名密码验证
猜你喜欢

瀚高数据库最佳实践配置工具HG_BP日志采集内容

cuda-gdb提示:/tmp/tmpxft_***.cudafe1.stub.c: No such file or directory.

看机器人教育引领素质教育主流

MySQL - the difference between count (field), count (primary key), count (1), count (*)

第2章 VRP命令行

并发模式之异步回调Future模式

vasp计算任务报错:M_divide:can not subdivide 8 nodes by 6

【OpenCV】使用OpenCV调用手机摄像头

Flink内核源码(七)Flink SQL提交流程

Thirty years of MPEG audio coding
随机推荐
Rocbos open source micro community light forum source code
数据截断及估计
12. Writing rules - static mode
Analyzing the subjective consciousness of emotional resonance between robots and human beings
常用hooks总结
Source code of Jiugongge heart puzzle Applet / source code of main wechat applet with traffic
Weekly recommended short videos: how to make product development more effective?
每周推荐短视频:如何让产品开发更加有效?
HTB-Blue
DataGrip 如何导出和恢复整个数据库数据,使用单个 SQL 文件
idea配置web容器与war打包
看机器人教育引领素质教育主流
[QNX Hypervisor 2.2用户手册]9.11 ram(更新中)
Cloud development pocket toolbox wechat applet source code
kubernetes-1.24.x 特性
navicat新建数据库
并发模式之单例和不变模式
Zone --- line segment tree lazy marking board sub problem
并发模式之生产者消费者模式
centos安装mysql8