interrupt mode clarification please

Hi People

I wonder if someone coulld please clarify an issue for me.

If I attach an interrupt with the mode of LOW, when exactly does the interrupt fire and for how long?

Does it just fire when the pin goes low, and then return, or does it keep firing while the pin is low?

I wwould like to attach a momentary button to the pin which will pull it low when pressed, but the button is a toggle style button so I don't want it firing continuously while the pin is low.

Cheers

I wwould like to attach a momentary button to the pin which will pull it low when pressed, but the button is a toggle style button so I don't want it firing continuously while the pin is low.

The way I read the documentation that is what would happen. So, use FALLING, to get notified only once, when the switch goes LOW.

Hi People

I wonder if someone coulld please clarify an issue for me.

If I attach an interrupt with the mode of LOW, when exactly does the interrupt fire and for how long?

Does it just fire when the pin goes low, and then return, or does it keep firing while the pin is low?

It will fire when the pin goes LOW, and when the attached ISR runs and then completes and returns to the sketch if the pin is still LOW it will fire again. FALLING is normally a better trigger option, but of course that depends on what your sketch is actually doing.

I wwould like to attach a momentary button to the pin which will pull it low when pressed, but the button is a toggle style button so I don't want it firing continuously while the pin is low.

Then use the FALLING trigger option, that will fire only on transition of high to low on the interrupt pin. However note that switch contact bounce can raise havoc causing in your program logic. Software debounce in the ISR routine is not always desirable, so external hardware debounce components may be the best method.

Lefty

Argh... some issues here...

I note the documentation talks about the value returned by millis() not being incremented and delay() not working.

Would it still be possible to place a static variable within the interrupt routine which could compare the value returned by millis() and only proceed if the difference is greater than some value?

Cheers

@retroLefty

suppose the IRQ returns and it is still LOW does it execute zero or one statements of loop() ?

AgeingHippy: Argh... some issues here...

I note the documentation talks about the value returned by millis() not being incremented and delay() not working.

Would it still be possible to place a static variable within the interrupt routine which could compare the value returned by millis() and only proceed if the difference is greater than some value?

Certainly, the millis() function will still return a value, but it's the value when the interrupt first occured and will not increment as long as you are inside the ISR routine as global interrupts are disabled until your ISR returns to the main sketch. So do your time calculation inside the ISR but just set a global flag variable and return, letting the main sketch test the flag and take the desired action and then reset the flag. That make sense?

Lefty Cheers

robtillaart:
@retroLefty

suppose the IRQ returns and it is still LOW does it execute zero or one statements of loop() ?

I believe it will perform just a single machine instruction from the place in the sketch where it was last interrupted from, but certainly not a complete C/C++ statement.

Lefty

Thanks people :)

OK lefty,

If true that would enable it to do some sort of "multiduo-tasking" ? Can an IRQ patch its return address? (think I have to experiment a bit here to explore boundaries ;)

robtillaart: OK lefty,

If true that would enable it to do some sort of "multiduo-tasking" ? Can an IRQ patch its return address? (think I have to experiment a bit here to explore boundaries ;)

Probably not impossible, but I'm sure in that path lies madness.

Lefty

but I'm sure in that path lies madness

Also called "preemptive multitasking". ;)

retrolefty: If I attach an interrupt with the mode of LOW, when exactly does the interrupt fire and for how long?

Does it just fire when the pin goes low, and then return, or does it keep firing while the pin is low?

All this blue - are you guys from Blizzard?

Anyway, the LOW mode is primary intended for waking the chip from a power-down mode. Thus closing a switch (grounding it) could generate a low interrupt which would wake the processor. You would then turn that mode off unless you wanted to be interrupted continuously after that.

robtillaart: Can an IRQ patch its return address? (think I have to experiment a bit here to explore boundaries ;)

I wouldn't go down that path myself. Interrupts can fire at (almost) any time (the "almost" being because you can turn off interrupts temporarily). To change the return address, even if possible, would very likely lead to a whole lot of obscure timing-dependent bugs.

There must be something in the air, that must be the third question in the last two days about changing the stack return address, or jumping out of interrupt service routines. There are almost certainly ways of coding to solve your problem that don't involve changing stack addresses or interrupt return addresses. Some kind of state machine, for example, where the interrupt changes the current state.

Also, the chips cost around $5. If you want multi-tasking, get two of them.