Society of Robots - Robot Forum

Software => Software => Topic started by: airman00 on September 24, 2009, 08:10:11 PM

Title: What happens if ISR lasts too long?
Post by: airman00 on September 24, 2009, 08:10:11 PM
Take this scenario:
I have an ISR ( interrupt routine) that gets called by the hardware timer every second
The ISR routine itself takes 1.5 seconds to run from beginning to end

So what happens in this case, where the interrupt routine takes too long? Would the second calling of the interrupt go through? ( the first was called at 0 seconds, and the second was called at 1 second)
Title: Re: What happens if ISR lasts too long?
Post by: Webbot on September 24, 2009, 09:06:54 PM
First time in:
Timer requests interrupt and sets 'interrupt request'
Assuming interrupts are enabled then your foreground is interrupted and it goes to your ISR.

Whilst in your ISR the interrupts are disabled.

One second later the timer sets the 'interrupt request' flag - but since interrupts are disabled then nothing happens

When your ISR routine exits then interruprs are re-enabled.

The mcu sees that another timer interrupt is 'pending' and so it calls your ISR again.

So your ISR will be called immediately - meaning that the main program will grind to a complete standstill - bad.

The processor will spend 99.99999% of its time calling your ISR.

An ISR should be short and sweet - if its taking 1.5 seconds then your code design is definitely very wrong!!!
Also bear in mind that during the 1.5seconds then no other interrupts are working either. So if you have an ISR to receive UART chars then these will also be killed off and you will miss all the incoming data.

What are you trying to do that needs 1.5 seconds?
Title: Re: What happens if ISR lasts too long?
Post by: airman00 on September 24, 2009, 10:13:32 PM
Thanks for the explanation. I think I understand.

What are you trying to do that needs 1.5 seconds?
Absolutely nothing. Its an entirely theoretical case , I just chose an easy unit of time.