go_away

Author Topic: What happens if ISR lasts too long?  (Read 1789 times)

0 Members and 1 Guest are viewing this topic.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
What happens if ISR lasts too long?
« 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)
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,154
  • Helpful? 110
Re: What happens if ISR lasts too long?
« Reply #1 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?
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: What happens if ISR lasts too long?
« Reply #2 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.
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

 


Get Your Ad Here