Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

what happens if 2nd interrupt occurs while the ISR of the 1st is being executed

Status
Not open for further replies.

matrixofdynamism

Advanced Member level 2
Joined
Apr 17, 2011
Messages
565
Helped
24
Reputation
48
Reaction score
23
Trophy points
1,298
Activity points
7,369
An interrupt causes a microcontroller/microprocessor to leave the normal execution flow and execute an ISR. Interrupts can have priority over other interrupts.

What happens if an interrupt occurs and its interrupt service routine is being executed and before it finishes, another interrupt occurs? Will the processor move to executing this 2nd interrupt once the current service routing reaches its end? How is this usually dealt with as I am sure such a scenario is quite common.
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,428
Helped
290
Reputation
580
Reaction score
275
Trophy points
1,363
Location
France 01800
Activity points
10,022
on PIC MCU
GIE bit is OFF when entering inside interrupt treatment
and will be put ON at the end of interrupt
so only interrupts with the correspondig Flag interrupt allready "ON" could be executed inside one interrupt.
so next IT treatment will occur just after return to the main..

it is the main reason to keep interrupt treatment as short as possible
and do each specifique treatment in the main.


but you can have 2 levels of interrupt ...
or more with ehanced MCU (PIC24 PIC32 ) .. with many priority levels.
 

srizbf

Advanced Member level 5
Joined
Apr 3, 2010
Messages
1,995
Helped
417
Reputation
840
Reaction score
328
Trophy points
1,363
Activity points
10,985
...... Will the processor move to executing this 2nd interrupt once the current service routing reaches its end? How is this usually dealt with as I am sure such a scenario is quite common.

If an interrupt service routine is in progress , then that can be interrupted by a higher priority interrupt.
 

matrixofdynamism

Advanced Member level 2
Joined
Apr 17, 2011
Messages
565
Helped
24
Reputation
48
Reaction score
23
Trophy points
1,298
Activity points
7,369
OK, if an ISR is in progress and a lower priority interrupt occurs, will it be ignored or will it be carried as soon as the current ISR ends?
 

matrixofdynamism

Advanced Member level 2
Joined
Apr 17, 2011
Messages
565
Helped
24
Reputation
48
Reaction score
23
Trophy points
1,298
Activity points
7,369
OK, in that case, is it that interrupts will always have priority in every system? I mean, is this always held true?
 

srizbf

Advanced Member level 5
Joined
Apr 3, 2010
Messages
1,995
Helped
417
Reputation
840
Reaction score
328
Trophy points
1,363
Activity points
10,985
OK, in that case, is it that interrupts will always have priority in every system? I mean, is this always held true?

yes. priority is always there when there are more than one interrupt request.
 

hobbyckts

Advanced Member level 1
Joined
Mar 12, 2015
Messages
481
Helped
88
Reputation
176
Reaction score
85
Trophy points
28
Activity points
2,457
That's the reason for assigning interrupts. All the systems carry interrupts within themselves. Priority should be assigned if there is more than one interrupt.
 

Gorgon

Full Member level 6
Joined
Nov 10, 2005
Messages
345
Helped
75
Reputation
150
Reaction score
67
Trophy points
1,308
Location
Norway
Activity points
3,639
Normally interrupts are not reeabled when the interrupt service routine is run, so it will finish executing, and the pending interrupt with the highest priority will then take control when interrupts is reenabled at return from interrupt.

Note that you have to reeable the interrupt system in the ISR yourself. Before you do that, you need to be very certain that your code is fast enough to serve any interrupt situation, and it has to be reentrant in way that does not use up all the stack space before it is possible to clean out all pending interrupts. Stack space is the big question here.

Priority levels are normally processed only when more than one interrupt is pending at the same time.

Some processors have special interrupts that can not be disabled(non maskable interrupt), and will always be executed. This is a special superhigh priority interrupt, and used sparingly, even if available. I've seen it used only one time, and that was an emergency interrupt with higher priority than power fail. I suppose exactly power fail could be such a high priority source, in any system.
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,866
Helped
4,856
Reputation
9,730
Reaction score
4,640
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
126,539
Note that you have to reeable the interrupt system in the ISR yourself.

Gorgon, in the PIC family the interrupts for the current priority are automatically turned off as the ISR is enetered and re-enabled by the return ('retfie') instuction that terminates the ISR. If you enable it within the ISR it would likely cause problems.

Brian.
 

Gorgon

Full Member level 6
Joined
Nov 10, 2005
Messages
345
Helped
75
Reputation
150
Reaction score
67
Trophy points
1,308
Location
Norway
Activity points
3,639
Gorgon, in the PIC family the interrupts for the current priority are automatically turned off as the ISR is enetered and re-enabled by the return ('retfie') instuction that terminates the ISR. If you enable it within the ISR it would likely cause problems.

Brian.

Yes, I suppose that is the general idea of my post too? Most processors I've used from different brands will disable the interrupt when entering the ISR, and you need to control interrupt enable yourself to get a reentrant interrupt system. That is generally a very bad idea in itself , for any processor family.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top