Catching stuck interrupts

Hi,

My project has an important "compare" interrupt. The compare value is set by code in Loop(). There's a lot of variables in the Loop() code which makes the code inside the interrupt longer/shorter. Occasionally a combination of variables will cause the whole thing to seize up. Specifically: 1. Combination of variables set compare value to low number, but also activates code in if statements in interrupt code (i.e meaning it takes longer to process). 2. Interrupt gets stuck in a loop - i.e. as soon as code has processed it interrupts again 3. Code in Loop() either processes extremely slowly or stops altogether.

Are there any features of the Atmega328P that can help with this? If not, are there any standard good software practices for preventing this from happening? At the moment I'm just doing it by trial and error and it's all getting quite messy!

thanks Paul

P.S. Atmega328P/Uno and 1.0.6 software.

If not, are there any standard good software practices for preventing this from happening?

As a matter of fact there are. Keep your interrupt handler SHORT and FAST!

and it's all getting quite messy!

You are probably overdue for a peer review of your code.

I think my original question was a bit indirect! What I'm really wanting to know is: is the Watchdog timer appropriate in this situation to stop my code getting stuck? I've not used the Watchdog timer before, so don't know much about it. Paul

The watchdog will reset the board for you if you fail to pat the dog in time. If that's an acceptable solution to you then fine.

I think the better solution would be to look at the code and see if you can stop it from locking things up.

I think the better solution would be to look at the code and see if you can stop it from locking things up.

That's what I was hinting at. Too subtle, I guess.

Ah cool. That's what I needed to know. I'll just need to go over the code and put limits in where needed to make sure it can't ever lock up. cheers Paul