Interrupt service function

Hi,

Is it ok to put ” noInterrupts()” within an Interrupt service routine?
Haven’t started it yet, but have a project ( cat flap with in and out switches - the flap can bounce in the other direction after opening ) where I will use two interrupts - when which ever one triggers first I will want to stop the other or any repeat triggers for a time period .
I realise I can do this as soon as I come out of the service function , but thought it would be tidy to put it inside and wondered if this was ok
? ( my timer will be outside)

Yeah, fine.

But is you're cat really going supersonic speeds? Liquid, yes, supersonic, no :stuck_out_tongue: So just poll the switches. Way easier :slight_smile:

Interrupts are automatically paused while inside an ISR.

I suspect what you want to do is use the code inside your ISR to turn off the other interrupt so that only one of them is triggered - that is perfectly feasible and quite common. All you need to do is clear (or is it set?) the flag in the appropriate register that enables the interrupt.

However cats are very unlikely to be so fast that you need an interrupt to detect one of them.

…R

Lol - thanks for the help .

It’s mainly after the cat has entered ( or gone out ) the door swings rapidly and the other contact trips . It gets complex because the cat sometimes just looks in … simple problem that gets more difficult .

Anyway …
Yes I could prob get away with polling ; but useful to me as a further learning exercise to use the interrupts .

hammy:
Yes I could prob get away with polling ; but useful to me as a further learning exercise to use the interrupts .

Then why not take the opportunity to learn how to do it the right way, rather than wasting time doing it in absolutely the wrong way. Disabling interrupts for long periods of time is completely unnecessary, and almost always causes problems. There is no need to even use interrupts for what you describe, and even if you DO insist on using them, using them in the way to want is absolutely the wrong way to use them. Never mind that won't even work anyway, as you will no doubt find out if you do try it...

Regards,
Ray L.

Robin2:
All you need to do is clear (or is it set?) the flag in the appropriate register that enables the interrupt.

Just to add a little to that. It is possible that the second interrupt has already been triggered after your first interrupt was triggered but before your code gets around to turning off the second interrupt. That means that the instant you re-enable the second interrupt it will fire. To avoid that you should clear the interrupt flag before you re-enable the second interrupt.

RayLivingston:
Disabling interrupts for long periods of time is completely unnecessary,

The way I am thinking about the problem interrupts (in general) will never be disabled for more than a brief period. However a specific interrupt could be turned of for as long as necessary without interfering with the general working of the system.

I agree with you that I would use polling for this project but if the OP wishes to use it to learn about interrupts that seems fine to me.

...R

Just been googling - what I proposed , will not, I think work , as interrupts are already off within a service routine and turned back on afterwards , so adding the noInterrupts statement makes no difference. Think I just need to clear/set the appropriate register before coming out of the service routine so any other waiting interrupt is cleared and not then acted on

hammy:
Just been googling - what I proposed , will not, I think work , as interrupts are already off within a service routine and turned back on afterwards , so adding the noInterrupts statement makes no difference. Think I just need to clear/set the appropriate register before coming out of the service routine so any other waiting interrupt is cleared and not then acted on

What I said :slight_smile:

...R

so adding the noInterrupts statement makes no difference. Think I just need to clear/

And do as LITTLE as possible inside the interrupt routine.

hammy:
Just been googling - what I proposed , will not, I think work , as interrupts are already off within a service routine and turned back on afterwards , so adding the noInterrupts statement makes no difference. Think I just need to clear/set the appropriate register before coming out of the service routine so any other waiting interrupt is cleared and not then acted on

You underestimate the speed of the Arduino. The processor can execute hundreds of thousands of instructions, maybe a few million instructions while the flap is still flapping. It has left the interrupt and been working on something else for the human equivalent of a week before the next interrupt is triggered.