What happens if two interrupts happen at the same time ?

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am working on a project where A small robot will use sensors to detect square wooden targets along the sides of a track .When It sees the target it will cease to move and hit the target with water. I am planning to put a right sensor and a left sensor but while I was writing the flow chart I encountered this problem : What if there are two targets(interrupts) at the same time on the left and the right how will the micro act ?
And worse , If there is a target on the left and the robot detects it and executes the ISR . What if there is another target (interrupt) on the right that is seen while the robot is in the middle of the ISR ? Will he ignore it because global interrupt is turned off inside ISR ?

So mainly I am asking : -What happens if two external interrupts happen at the same time ?
-How do I make the micro sensitive to other interrupts while it is in the middle of ISR of one interrupt?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I explain this in my tutorial on the traps when using interrupts. Short answer is the micro will not ignore a pending interrupt as an internal flag for the interrupt source will be set.
The exception to this is external level triggered interrupts.

The AVR has a fixed order of resolution of multiple pending interrupts. This is outlined in the data sheet.

Last Edited: Sat. Jul 31, 2010 - 10:53 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This has been discussed hundreds of times so maybe search out the prior threads but the bottom line is that when an ISR is entered the AVR code clears the I flag so further interrupt cannot occur. HOWEVER almost every possible interrupt source has an interrupt flag bit (??IF) in one of its status registers and if that interrupt source triggers all that happens (initially) is that the IF bit for the interrupt is set. When the interrupt that is currently being handed performs RETI the I bit in SREG is re-enable and the core fetches/executes one opcode from the non-interrupt code. Before it fetches the next opcode it checks all the ??IF flags in the order in which they appear in the interrupt vector table. The first one it finds to be set will trigger an entry into the associated ISR and the whole processes starts again.

So the interrupt will be "seen" and serviced but it may be "late" which is why all ISRs should be written to execute in just a few microseconds so they don't overly delay others that might be waiting for service. The worst that can happen is when the current ISR delays for so long that TWO or more of the delayed interrupt occurs. As there's only one ??IF bit and no counter the system only knows that one has occurred - not how many.

Because flags are checked in vector table order this means there is a fixed "priority" system in the AVR - those with lower vector numbers have priority over the later ones. But this is not true priority in the sense of Xmega and other MCUs in that one interrupt cannot interrupt another ones handler (unless it does an SEI but that is VERY dangerous!)

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the great clarification . Regarding the search there is a weird problem when I search for a string consists of more than 1 word it returns an empty page so I always get bad results .

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Curious - I clicked the Search link near the top of the page (between FAQ and Memberlist). Entered "two interrupts happen at the same time" into the search box, ticked the "all these items" blob then under category I selected "8bit technical" and it then hit 57 threads.

Moderator.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The best way to search avrfreaks is with Google using 'my search terms site:AVRFreaks.net'
I never use the actual AVRFreaks search.

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good tip . Ty .

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You linked to a dynamically populated page, so it's empty for all those who haven't completed a search. Make sure you select "Search for all terms", as clawson said. I also get 57 hits.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To defend the OP somewhat: You can occasionally get blank result pages on your own searches. I have not been able to see a clear pattern for when it happens but one thing I am suspecting is very large search result sets, eg when you don't tick "search for all...".

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]