当前位置:网站首页>After CANopen starts PDO timing transmission, the heartbeat frame time is wrong, PDO is delayed, and CANopen time axis is disordered
After CANopen starts PDO timing transmission, the heartbeat frame time is wrong, PDO is delayed, and CANopen time axis is disordered
2022-04-23 18:22:00 【Things will turn when they reach the extreme 1024】
CANopen In the case of , A simple way to use a lot is to use a 1ms Timer interrupt , Then rewrite... With global variables sertimer and getElapsedTime function , Then add... To the interrupt service function timerForCan
//Set the next alarm //
void setTimer(TIMEVAL value)
{
NextTime=(TimeCNT+value)%TIMER_MAX_COUNT;
}
// Get the elapsed time since the last occured alarm //
TIMEVAL getElapsedTime(void)
{
int ret=0;
ret = TimeCNT> last_time_set ? TimeCNT - last_time_set : TimeCNT + TIMER_MAX_COUNT - last_time_set;
last_time_set = TimeCNT;
return ret;
}
But there is a fatal problem with this approach , The time calculated in this way , When there are only heartbeat frames, there is no problem , Join in PDO Regularly send , Will be chaos , for example 1s Heartbeat frame 300msPDO timing , The phenomenon is 1s Heartbeat frame retention , stay 1s After heartbeat frame 300ms There will be one more heartbeat frame , and PDO Timed transmission does not appear !!!!!!, In this case, it should be changed to last_time_set = TimeCNT; Put it in timerForCan Before !!!!
```c
//Set the next alarm //
void setTimer(TIMEVAL value)
{
NextTime=(TimeCNT+value)%TIMER_MAX_COUNT;
}
// Get the elapsed time since the last occured alarm //
TIMEVAL getElapsedTime(void)
{
int ret=0;
ret = TimeCNT> last_time_set ? TimeCNT - last_time_set : TimeCNT + TIMER_MAX_COUNT - last_time_set;
//last_time_set = TimeCNT; The culprit
return ret;
}
In addition, there will be a 1 Millisecond timer , Every time 1 Call the following function in milliseconds .
void timerForCan(void)
{
TimeCNT++;
if (TimeCNT>=TIMER_MAX_COUNT)
{
TimeCNT=0;
}
if (TimeCNT==NextTime)
{
TimeDispatch();
}
}
//1ms Interrupt service function
void TIM7_IRQHandler(void)
{
if(TIM7->SR&0X0001)// interrupt
{
}
TIM7->SR&=~(1<<0);// Clears the interrupt flag bit
last_time_set = TimeCNT;
timerForCan();
}
版权声明
本文为[Things will turn when they reach the extreme 1024]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210610057187.html
边栏推荐
- 【ACM】70. 爬楼梯
- Mode of interprocess communication
- Jenkspy package installation
- The vivado project corresponding to the board is generated by TCL script
- Analysez l'objet promise avec le noyau dur (Connaissez - vous les sept API communes obligatoires et les sept questions clés?)
- Reptile efficiency improvement method
- Gobang game based on pyGame Library
- Halo 开源项目学习(七):缓存机制
- Const keyword, variable and function are decorated with const
- The difference between deep copy and shallow copy
猜你喜欢
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
Imx6 debugging LVDS screen technical notes
In win10 system, all programs run as administrator by default
Docker 安装 MySQL
Docker installation MySQL
由tcl脚本生成板子对应的vivado工程
SSD硬盘SATA接口和M.2接口区别(详细)总结
Creation and use of QT dynamic link library
Install the yapiupload plug-in in idea and upload the API interface to the Yapi document
Nodejs installation
随机推荐
Qt读写XML文件(含源码+注释)
Crawling mobile game website game details and comments (MQ + multithreading)
Daily CISSP certification common mistakes (April 14, 2022)
Daily CISSP certification common mistakes (April 12, 2022)
Closure type of rust (difference between FN, fnmut and fnone)
Log4j2 cross thread print traceid
kettle庖丁解牛第17篇之文本文件输出
Nodejs installation
Using transmittablethreadlocal to realize parameter cross thread transmission
Rust: shared variable in thread pool
According to the result set queried by SQL statement, it is encapsulated as JSON
Pointers in rust: box, RC, cell, refcell
GDAL + ogr learning
【ACM】509. Fibonacci number (DP Trilogy)
Const keyword, variable and function are decorated with const
Cygwin64 right click to add menu, and open cygwin64 here
线上怎么确定期货账户安全的?
Crawl the product data of Xiaomi Youpin app
Daily network security certification test questions (April 14, 2022)
QT reading and writing XML files (including source code + comments)