当前位置:网站首页>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
边栏推荐
- "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
- 【树莓派4B】七、远程登录树莓派的方法总结XShell,PuTTY,vncServer,Xrdp
- 《统计学习方法(第2版)》李航 第十三章 无监督学习概论 思维导图笔记
- PLSQL query data garbled
- 用指针访问一维数组
- Xshell远程访问工具
- HAL_ Delay() delay error about 1ms
- C语言链表(创建、遍历、释放、查找、删除、插入一个节点、排序,逆序)
- js星星打分效果
- DeepSort 总结
猜你喜欢

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

labelme转voc代码中的一个小问题

"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

AD1256

PDF文本合并

树莓派大用处,利用校园网搭建一个校园局域网站

DeepSort 总结

A small problem in labelme to VOC code

"Statistical learning methods (2nd Edition)" Li Hang Chapter 16 principal component analysis PCA mind map notes and after-school exercise answers (detailed steps) PCA matrix singular value Chapter 16

删除分类网络预训练权重的的head部分的权重以及修改权重名称
随机推荐
STM32 DSP library MDK vc5\vc6 compilation error: 256, (const float64_t *) twiddlecoeff64_ 256, armBitRevIndexTableF64_ 256,
KMP代码分布详解
Machine learning (zhouzhihua) Chapter 1 Introduction notes learning experience
如何解决训练集和测试集的分布差距过大问题
What do programmers often mean by API? What are the API types?
PLSQL query data garbled
信号与系统:希尔伯特变换
HAL_Delay()延时误差约1ms的问题
Erp+rpa opens up the enterprise information island, and the enterprise benefits are doubled
Positional argument after keyword argument
[deep learning] handwritten neural network model preservation
Deepsort summary
[MYCAT] MYCAT installation
第四章 决策树总结
【FatFs】手动移植FatFs,将SRAM虚拟U盘
Better CV link collection (dynamic update)
目标检测带标签数据增强代码
YOLOv5学习总结(持续更新)
Commands for quickly opening management tools
数据归一化