Continue to Site

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
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
 

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.
 
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
 

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
 

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
 

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
 

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

Back
Top