当前位置:网站首页>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 !
边栏推荐
- 解析机器人与人类情感共鸣的主观意识
- Source code of Jiugongge heart puzzle Applet / source code of main wechat applet with traffic
- Mongodb index (3)
- etcd实现大规模服务治理应用实战
- C语言:判断字母
- 盘点国内外项目协同管理软件:SaaS和定制化成趋势
- PHP process communication series (I) named pipes
- DHCP协议详细解析
- 架构师进阶,微服务设计与治理的 16 条常用原则
- Wechat applet - Advanced chapter Lin UI component library source code analysis button component (II)
猜你喜欢

Which is a good automatic account distribution system?

QT compilation of IOT management platform 48 characteristic function design

区区区间---线段树lazy标记板子题

Jinshan cloud returns to Hong Kong for listing: Hong Kong stock rush of Chinese to B cloud manufacturers

每周推荐短视频:如何让产品开发更加有效?

Implementation principle of golang synergy

New conch movie theme template m3.1 fully decrypted version multifunctional apple cmsv10 background adaptive theme open source fully decrypted version

Wechat applet - Advanced chapter Lin UI component library source code analysis button component (II)

Multiple inheritance and derived class member identification

C语言:判断字母
随机推荐
会议OA之反馈功能
MySQL compound query (important)
数据截断及估计
融云实时社区解决方案
HTB-Blocky
Stm32c8t6 encoder motor speed measurement and Arduino photoelectric module speed measurement
解析Steam教育中的项目式学习创造力
多线程实现多用例文件并发读取执行+Selenium Grid4实现测试框架分布式部署
mysql大表联合查询优化,大事务优化,规避事务超时,锁等待超时与锁表
Interpreting AI robots' pet raising and leading fashion trends
(job) C language: Simulation Implementation of ATOI and strncpy, strncat, strncmp
10.书写规则-文件搜寻
Day 10 notes
Flink kernel source code (VII) Flink SQL submission process
A good-looking IAPP donation list source code
FTP协议详解
[opencv] use OpenCV to call mobile camera
Analyzing the subjective consciousness of emotional resonance between robots and human beings
04 | 后台登录:基于账号密码的登录方式(上)
解析机器人与人类情感共鸣的主观意识