当前位置:网站首页>Accurate calculation of time delay detailed explanation of VxWorks timestamp
Accurate calculation of time delay detailed explanation of VxWorks timestamp
2022-07-24 06:00:00 【Joey Boye o (* ^ ^ ^ *) o】
Project scenario :
vxWorks Accurate to ms Time keeping method of , Use a timestamp sysTimeStamp() function
Method of accurately calculating time delay Demo
void timeAccurate()
{
int t2,t3,tt2,tt3;
int time1,time2,freq;
int a=0;
while(a<10)
{
freq = (sysTimestampFreq()/1000);
t2=sysTimestamp(); /* Get the timestamp */
tt2=tickGet();
//msDelay(1);
taskDelay(2);
t3=sysTimestamp(); /* Get the timestamp */
tt3=tickGet();
//logMsg("is : t2=%d t3=%d tt2=%d tt3=%d t3-t2=%d tt3-tt2=%d\n",t2,t3,tt2,tt3,(t3-t2),(tt3-tt2));
//logMsg("miao :%d ms %d\n",((t3-t2)/399783),a,0,0,0,0);
//logMsg("freq is :%d\n",freq,0,0,0,0,0);
//logMsg("time is : %d\n",((t3-t2)/freq),0,0,0,0,0);
abb[a]=(tt3-tt2);
acc[a]=((t3-t2)/freq);
a++;
}
}
void printacc() /* Print uses the timestamp difference to calculate the delay time */
{
for(int i=0;i<10;i++)
{
logMsg("time is : %d ms\n",acc[i],0,0,0,0,0);
}
}
void printabb() /* To print using tick Difference calculation delay time */
{
for(int i=0;i<10;i++)
{
logMsg("tick time is : %d ms\n",abb[i],0,0,0,0,0);
}
}
void msDelay(int ms) // Delay function encapsulation Use timestamp to delay
{
int t,t1,t2;
t1 = sysTimestamp(); /* Record the timestamp of the last round */
while(ms--)
{
t = 0; /* Counter reset */
while(t < sysTimestampFreq()/1000)
{
t2 = sysTimestamp(); /* Read the current timestamp */
if(t2 > t1)
t += (t2-t1);
else
t += t2;
t1 = t2;
}
}
}
CPU Time stamp :
sysTimeStamp() Also known as “ Time stamp ”. It is realized through the system clock . At first, I also felt puzzled , The timing cycle of the system clock is tick, How to realize high-precision clock ? By reading BSP Underlying code discovery ,sysTimeStamp In fact, high-precision timing is obtained by reading the current count value of the timer . adopt sysTimestampFreq() Function can get the frequency of the system timestamp , It often reflects CPU The reference frequency of the timer . Of course , Such a high resolution can only be an ideal value , Different systems may not be able to achieve . After all, the implementation of this timestamp has a fatal weakness : Through query . The system clock timing interrupt is based on ticb: Unit , Further improve the resolution and read the count value of the timer (CPU A special function register of ), It can only be realized by query .
To get the precise time interval of milliseconds , And frequent calls do not cause the system CPU High occupancy .
I suggest taking adopt CPU Machine cycle solution .
Basically, most mainstream CPU All one. 64 Bit registers are used to record CPU After power on Number of machine cycles .
You can write an assembly function to get this 64 Bit count .
Then you start the program , Make a 10 Second timing , Get it once before and after the timing CPU Machine cycle .
And then subtract , You can get every second CPU Machine cycle ,
Divide this number by 1000 It's every millisecond CPU Machine cycle .
This value can be used as a constant in operation , Use us to name it Millisecond factor
Then you take the previous execution and the next execution when you perform the last execution ,
In the next execution, take the previous execution and the next execution .
Subtract twice to get Spaced CPU Machine cycle . Then use the above millisecond factor to convert it into milliseconds .、
Using this method, you just want to be accurate to nanosecond It's OK, too .
Tick And timestamp difference
vxWorks Under the tick and timestamp There's no correlation . Nor is it the relationship between seconds and minutes that you said .
tick In fact, it can be regarded as the frequency of kernel scheduling , It's also a time slice 、watchdog Overtime 、 Unit of task delay , So it is system clock.timestamp Can get high-precision timing , Follow RTOS Scheduling doesn't matter . For example, the count of reading registers at a certain time is A, Read again after a period of time as B, The main frequency is f. that B and A The time distance between them is :T = (B-A)*f.( Suppose it is used as timestamp Of timer No, rollover) Corresponding to hardware ,tick as long as timer Capable of producing periodic The interruption is That's ok , Used as a timestamp Of timer Ask for a little more .
Timestamp common functions
If the support Timestamp,BSP The following functions should be provided
sysTimestampConnect() - Connection timestamp interrupted
sysTimestampEnable() - Enable timestamp
sysTimestampDisable() - No timestamps
sysTimestampFreq() - Frequency of obtaining timestamp
sysTimestampPeriod() - Get timestamp period
sysTimestamp() - Get a timestamp
sysTimestampLock() - No interruptions , Get a timestamp
sysTimestampInt() - Optional timestamp ISR
边栏推荐
- [FatFs] migrate FatFs manually and transfer SRAM virtual USB flash disk
- DeepSort 总结
- "Statistical learning methods (2nd Edition)" Li Hang Chapter 14 clustering method mind map notes and after-school exercise answers (detailed steps) K-means hierarchical clustering Chapter 14
- jupyter notebook一直自动重启(The kernel appears to have died. It will restart automatically.)
- How to solve the problem of large distribution gap between training set and test set
- STM32 DSP库MDK VC5\VC6编译错误: 256, (const float64_t *)twiddleCoefF64_256, armBitRevIndexTableF64_256,
- ++cnt1[s1.charAt(i) - ‘a‘];
- How to quickly connect CRM system and ERP system to realize the automatic flow of business processes
- 绘制轮廓 cv2.findContours函数及参数解释
- labelme转voc代码中的一个小问题
猜你喜欢

【FatFs】手动移植FatFs,将SRAM虚拟U盘

Learning rate optimization strategy
![[activiti] process example](/img/77/63d7d1ea8c634fb3741383f40f38e7.png)
[activiti] process example

《统计学习方法(第2版)》李航 第16章 主成分分析 PCA 思维导图笔记 及 课后习题答案(步骤详细)PCA 矩阵奇异值 第十六章

学习率优化策略

Chapter III summary of linear model

Machine learning (Zhou Zhihua) Chapter 3 Notes on learning linear models

信号与系统:希尔伯特变换

【树莓派4B】七、远程登录树莓派的方法总结XShell,PuTTY,vncServer,Xrdp

Thymeleaf快速入门学习
随机推荐
What do programmers often mean by API? What are the API types?
QT novice entry level calculator addition, subtraction, multiplication, division, application
Could not load library cudnn_ cnn_ infer64_ 8.dll. Error code 126Please make sure cudnn_ cnn_ infer64_ eight
Better CV link collection (dynamic update)
[raspberry pie 4B] VII. Summary of remote login methods for raspberry pie xshell, putty, vncserver, xrdp
Raspberry pie is of great use. Use the campus network to build a campus local website
单播、组播、广播、工具开发、QT Udp通讯协议开发简介及开发工具源码
JUC并发编程基础(6)--Lock锁
Jupyter notebook选择conda环境
js星星打分效果
【FatFs】手动移植FatFs,将SRAM虚拟U盘
Delete the weight of the head part of the classification network pre training weight and modify the weight name
On the concepts of "input channel" and "output channel" in convolutional neural networks
systemctl + journalctl
[activiti] activiti system table description
Positional argument after keyword argument
MySql下载,及安装环境设置
How to solve the problem of large distribution gap between training set and test set
《统计学习方法(第2版)》李航 第十三章 无监督学习概论 思维导图笔记
主成分分析计算步骤