Timeline for Using interrupts as flags/latches without any ISR
Current License: CC BY-SA 4.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 3, 2023 at 8:58 | comment | added | Mark Morgan Lloyd | @hobbs actually, OP specifies "Arduino Mega" rather than a specific chip- even if that is tightened up somewhat in subsequent discussion. However using the interrupt flags in this way appears (to me at least) to be a fundamental design decision, and even if this is expected to be a one-off hobby project that sort of thing is risks cause enormous problems in the future if somebody else tries to use the code, or if a more appropriate chip comes onto the market. | |
Jul 3, 2023 at 7:24 | comment | added | Edgar Bonet | @hobbs: Not my Mega, nor the one shown on the Arduino store. Unless you are talking about the quartz clocking the 16U2 that does the USB-to-serial conversion, which is irrelevant to the question being asked. | |
Jul 3, 2023 at 7:01 | comment | added | hobbs | @MarkMorganLloyd the entire code is specific to one particular chip, so that doesn't really make sense. | |
Jul 3, 2023 at 6:49 | comment | added | Mark Morgan Lloyd | It seems to me that the question of whether the flag is set or not might be somewhat implementation-specific. Even if it is 100% guaranteed for AVR chips it might not be for others, hence relying on that behaviour is not very good practice. | |
Jul 2, 2023 at 23:43 | vote | accept | Nicholas | ||
Jul 2, 2023 at 23:43 | comment | added | Nicholas | I left a comment above, too, but the actual process period is ~200µs (repeated many times) while exposing an image to a camera sensor. And it's less sensitive to any particular clock rate. I just want each identical busy-wait to take the same wall-clock time so there isn't any brightness difference between each exposure. Even that 2.6µs gives around 1.3% additional illumination. On a 12-bit sensor, that starts to add up quickly. The UART intentionally isn't sending or receiving during that period, so hopefully it's alright to just leave it enabled... | |
Jul 2, 2023 at 12:34 | comment | added | Edgar Bonet | @NickGammon: In edge-detection mode, the flag is set even if the interrupt is disabled (I just checked). However, this is a bad example, as the interrupt flag does not work in level-detection mode: "These flags are always cleared when INT7:0 are configured as level interrupt." I changed the example in my answer. | |
Jul 2, 2023 at 12:33 | history | edited | Edgar Bonet | CC BY-SA 4.0 |
Vecter interrupt flag example.
|
Jul 2, 2023 at 10:31 | comment | added | Nick Gammon♦ | I might be wrong about that, I admit. | |
Jul 2, 2023 at 10:29 | comment | added | Nick Gammon♦ | Are you certain about that? In the datasheet it says The External Interrupts 7 - 4 are activated by the external pins INT7:4 if the SREG I-flag and the corresponding interrupt mask in the EIMSK is set. My reading of that was that the flag is set if the interrupt is enabled. Otherwise, how would it know if it is rising or falling? | |
Jul 2, 2023 at 10:09 | history | answered | Edgar Bonet | CC BY-SA 4.0 |