完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
我有一个计数器,一个一秒的计数器,SysSimtimes读错了吗?有人告诉我volatile也可以。000000取决于读如何工作。
以上来自于百度翻译 以下为原文 I have a counter sys_time which is a one milli second counter. Could sys_time be read incorrectly? Someone told me volatile would make it ok. volatile uint32_t sys_time; A snippet of the interrupt void _ISR __attribute__((interrupt, auto_psv)) _T3Interrupt(void) { // ms counter sys_time++; _T3IF = 0; } Then around my code i use it to check time has passed elapsed = sys_time - btn1_start_time; So I think this is unsafe because sys_time when being read could be interrupted by tmr3 and if sys_time is going from 0x0000FFFF to 0x00010000 i could get read 0x0001FFFF or 0x00000000 depending on how the read works. |
|
相关推荐
1个回答
|
|
|
这是一个16位的CPU。变量是一个32位的量。读取它需要一个以上的CPU周期(读取高6位,读取低16位),并且可以在读取之间发生中断。或者将其复制到临时变量中。这是安全的,因为如果在读取SysIt的几个指令期间发生了T3中断条件,那么T3IF将被设置,并且当您重新启用T3中断时,它将立即触发T3中断。
以上来自于百度翻译 以下为原文 This is a 16 bit CPU. Your variable is a 32 bit quantity. Reading it takes more than one CPU cycle (read high 6 bits, read low 16 bits) and an interrupt can occur between the reads. Just disable the T3 interrupt enable when reading sys_time. Perhaps copy it into a temp variable. This is safe because, if a T3 interrupt condition occurs during the few instructions to read sys_time, then the T3IF will get set and when you re-enable the T3 interrupt, it will immediately trigger an T3 interrupt. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1122浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
872浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 22:05 , Processed in 0.766814 second(s), Total 73, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1039