Does Arduino's clock (millis) continue counting in the background during interrupts?

旧城冷巷雨未停 提交于 2019-12-12 13:04:14

问题


I have a quick question which apparently isn't said online from what I've read: I know millis() on an Arduino doesn't change during a custom interrupt, but does the associated timer still counts in the background?

My program is time-sensitive and I would like to know if I should increase its value (how?) each time one of my interrupts is handled so that the main program's clock doesn't drift.

Thanks in advance, Regards, Mister Mystère


回答1:


The CPU-internal timer will count even when interrupts are disabled. BUT when the timer overflows an interrupt is generated which will increment some counter in the library. If that interrupt is blocked for a long time ... then you will have a drift.




回答2:


The CPU timer is hardware and not affected by any interrupt flags. Once it overflows the overflow bit is set / an interrupt is triggered. If interrupts are blocked at that time this interrupt will be queued. The queue size is 1, that is your must allow interrupts before the next interrupt is triggered. Since the timer overflows roughly once per millisecond you will need to ensure that you never block interrupts for longer than ~1ms.

Anyway you will have a drift since the Arduino's clock is not that precise at all. See my experiment on crystal deviations.



来源:https://stackoverflow.com/questions/17135805/does-arduinos-clock-millis-continue-counting-in-the-background-during-interru

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!