Timeline for Using millis() in unsynchronized manner
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 4, 2021 at 12:13 | comment | added | Edgar Bonet |
@EmbSysDev: You may indeed disable selectively TIM0, although that would take a few more cycles than cli() . This critical section is very short, so globally disabling interrupts is fine here. Re "they don't seem to be enabling the interrupts again": that's what SREG = oldSREG; does: re-enable interrupts, but only if they were initially enabled when the function was called.
|
|
May 4, 2021 at 7:11 | comment | added | EmbSysDev | @EdgarBonet: cli() disables all interrupts, so too many calls to millis() would affect all interrupt based events.Would it not be sufficient to only disable TIM0 ? In the function they don't seem to be enabling the interrupts again, is it being done elsewhere(otherwise no interrupt would be enabled).Would make sense to enable the interrupts again before exiting millis() ? Thanks for your time ! | |
May 1, 2021 at 21:33 | comment | added | Edgar Bonet | @EmbSysDev: There is no need to "prevent read while timer is updating the variable": the ISR is not interruptible, so nothing can read the variable while it is being updated. You need to prevent the update while the main program is reading it. | |
May 1, 2021 at 19:57 | comment | added | EmbSysDev | @Edgar Bonet ,Just as an aside ( I am actually writing a millis() like function for another uC ) : Is it valid, to say , use a lock bit to prevent read while timer is updating the variable , instead of disabling the interrupt? Thanks much ! | |
May 1, 2021 at 19:40 | vote | accept | EmbSysDev | ||
Apr 30, 2021 at 17:54 | comment | added | PMF | Sure, a 64 bit Arduino with 2k of RAM :-) | |
Apr 30, 2021 at 17:47 | history | answered | Edgar Bonet | CC BY-SA 4.0 |