完善资料让更多小伙伴认识你,还能领取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. |
|
|
|
只有小组成员才能发言,加入小组>>
5231 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3200 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
771浏览 1评论
659浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
588浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
669浏览 0评论
571浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-19 13:33 , Processed in 1.306416 second(s), Total 75, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号