摘要
为了消除计数器的捕获数据错误和保障数据安全,在阐述可编程计数器捕获测时的原理及方法的基础上,建立了软件计数器的读-写者模型,指出了软件计数器共享问题是造成65536数据出错的原因。从计数器的工作时序入手,引入了计数器新的工作态——竞争态,提出了工作状态检测+事件同步的软件解决方法,并在STM32单片机和FreeRTOS操作系统上对该方法进行了验证。实验表明,该新方法准确捕获了周期大于1个计数器周期的时间间隔信号,计数误差为±1,证明了新方法更正了计数器溢出中断和捕获中断调用的时序,消除了变量共享矛盾,避免了传统中断方法的65536计数错误,为捕获测时提供了安全可靠的设计与方法参考。
In order to eliminate the capture data errors of counter and ensure the data security,this paper established a reader-writer model of the software counter based on the principle and method of interval time measurement of programmable capture counter,the paper also indicated that the cause of 65536 data errors were the sharing of the software counter.This paper introduced the timing of the counter,explained the new working state of the counter,employed a new kind of competitive state,and put forward the software solution of the working state detection plus event synchronization.This new kind of method was verified on STM32 microcontroller and FreeRTOS operating system.The results suggest that the new method can be used to accurately capture the time interval signals with period greater than 1 counter cycle,with capture count error within±1.The study proves that this new kind of method can be used to improve the sequence of the counter overflow interrupt and the capture interrupt calls,eliminate the contradiction of the variable share,avoid the 65536 count error of the traditional interrupt method,so that can provide a safe and reliable method,as well as a new kind of design reference for the time measurement capture.
作者
李红波
李盛
王洋
陈恒
LI Hong-bo;LI Sheng;WANG Yang;CHEN Heng(School of Science,Xijing University,Xi’an 710123,China)
出处
《仪表技术与传感器》
CSCD
北大核心
2021年第7期65-70,共6页
Instrument Technique and Sensor
基金
国家自然科学基金项目(11974289)
陕西省重点研发计划项目(2018GY-091)
西京学院基金项目(XJ120102)
西京学院重点课程项目(XJZDKC20013)。