Timer1 interrupts handling

Hello,

just a couple of questions:

Can I disable the interrupts inside the interrupt handling function(ISR)? Do I have to do with cli() or can I use Timer1.detachInterrupt()?

I read on the main wiki that delay function dosen’t work inside the ISR function, I suppose this is still true also inside sub functions called from ISR function, is that true?

Thanks

Hello,

rspock:
Can I disable the interrupts inside the interrupt handling function(ISR)?

That is not necessary. Interrupt service routines are entered with interrupts disabled.

Do I have to do with cli() or can I use Timer1.detachInterrupt()?

Calling cli is not necessary. Assuming the Timer1 library is coded correctly, you can safely call detachInterrupt inside of an ISR.

I read on the main wiki that delay function dosen't work inside the ISR function,

That is correct. delay is not reliable in an ISR.

I suppose this is still true also inside sub functions called from ISR function, is that true?

Correct.

hi,
What you should try to do is set a flag inside the isr which you then check in loop - but if your application is critically time sensitive there are other approaches using the timer itself i.e. Simply add your delay period to one of the output compare registers and exit the isr. When your delay period has passed the isr will be called and you can do whatever it is that you wanted to do.

I.e. Note code but enough to give you the idea -

OCR1A = TCNT1 + DELAY/PRESCALE

Duane B

More than "not reliable" it will lock up the processor I believe. Think of what an interrupt routine does - it takes over the processor and stops everything else from happening - so you can only wait for external changes usefully - and in general you shouldn't take any more CPU cycles than is absolutely necessary. Typically an interrupt routine's job is to buffer some input or progress some output, and setting flags to communicate readiness for the next operation. ISR talks to the hardware, main program talks to the ISR...

many thanks to all. I'm going to try to move the delay associated task to the main loop.