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.

Interrupt an Interrupt in PIC16F877

Status
Not open for further replies.

octron

Junior Member level 1
Joined
Oct 19, 2001
Messages
18
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
83
Hi,
is it possible for an interrupt subroutine in an 16F877 to be interrupted by an other interrupt ???

Thanks
 

klug

Advanced Member level 1
Joined
Jul 4, 2002
Messages
476
Helped
12
Reputation
24
Reaction score
7
Trophy points
1,298
Activity points
4,382
When interrupt is started all other interrupts are disabled automatically by clearing GIE flag, but controller is setting corresponding flag if any interrupt event is coming. At the end of interrupt, RETFIE instruction is returning from interrupt with GIE setting (allow interrupt). If any other interrupt event is comming during interrupt, it will be executed after this interrupt.
 

Mr.Cool

Advanced Member level 2
Joined
Jun 20, 2001
Messages
664
Helped
87
Reputation
178
Reaction score
60
Trophy points
1,308
Activity points
7,113
actually, it is possible.

typically when you write an interrupt service routine (ISR) the very first thing you do when entering the ISR loop is to dissable all interrupts. then you service the interrupt (fix the reason why it was called in the first place). then before exiting the ISR you enable all interrupts again.

however, if you do NOT disable all interrupts then i suppose it would be possible to call an interrupt while within an interrupt. keep in mind that the program counter only has an 8 level stack.

here is a test. set PIC chip to interrupt on some counter value... then when interrupt occurs, have the code say:

ISR: * do not disable interrups
endless_loop:
goto endless_loop
END ISR

the code gets stuck in an endless loop. while it is looping around cause an "interrupt on change" to the PIC chip. inside that ISR have an LED turn ON.

this could probably be simulated in Proteus...

Mr.Cool



Mr.Cool
 

toxadi

Junior Member level 2
Joined
Mar 8, 2002
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Greece
Activity points
177
As Mr. Cool said, it can be done. Usually, after servicing an interrupt you run a retfie command that sets back the GIE bit. No one can stop you from re-enabling the interrupt before fully servicing the previous interrupt, so can be re-interrupted.

BUT, it is very risky and several things should be considered. It is very important to first acknowledge the interrupt and then set the GIE bit. Because if you don't clear the xxxIF bit, re-setting the GIE will keep firing again and again the same interrupt endlessly and poof, you're stuck...

Next have in mind that the same code at the beginning of the interrupt will be re-executed. For example, usually you save W and STATUS when entering the int and restore it on exit. If using a static save method e.g. a single memory position for each register, if you re-interrupt you will loose the initial W and STATUS values.

And of course there is always the 8-level deep stack

I guess that it would be best to use polling inside the interrupt, but only you can decide that.

Regards
toxadi
 

C-Man

Advanced Member level 4
Joined
Jul 19, 2001
Messages
1,059
Helped
90
Reputation
180
Reaction score
17
Trophy points
1,318
Activity points
10,189
If you really need this you should use a PIC18 cpu for example PIC18F452 which is pin compatible to the 16F877.

This cpu has 2 interrupt priorities and the high priority interrupt can interrupt the low priority interrupt.

best regards
 

Yaric

Newbie level 4
Joined
Dec 18, 2003
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
45
I think there is no way to save W & SFR correctly in nested interrupt for PIC16 series
For PIC18 series it can be made by using one of FSRs
 

mrm

Full Member level 1
Joined
Dec 11, 2002
Messages
97
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
859
Remember U have only 7 position into your stack to save the Program Counter....sometimes they're few...You should save the PC by yourself by neglecting the retfie and performing a Jump far.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top