View previous topic :: View next topic |
Author |
Message |
arrow Guest
|
Interrupts Mix up question- Easy |
Posted: Tue Nov 09, 2004 10:13 pm |
|
|
Hi
I have another simple question: I have two types of interrupts, a RTCC interupt and a KeyBoardHit interrupt (I want to time the KBhits). What happens if while in the RTCC interrupt, the KB interrupt occurs?
Does the RTCC subroutine resume once the KB routine is finished?
Is there any way to get the RTCC routine to continue where it left off?
Thank you in advance for your help.
arrow |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Nov 09, 2004 10:15 pm |
|
|
What PIC are you using? In PIC16s you can not have an interrupt inside another interrupt. In PIC18 a priority interrupt can occur in the middle of the ISR of a normal interrupt (which will resume once the priority ISR is over). |
|
|
arrow Guest
|
|
Posted: Tue Nov 09, 2004 10:18 pm |
|
|
Hi
I am using the PIC 16F84A, and am trying to time a pulse width.
arrow |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Nov 09, 2004 11:33 pm |
|
|
From the datasheet:
Quote: | When an interrupt is serviced, the GIE bit is cleared to
disable any further interrupt, the return address is
pushed onto the stack, and the PC is loaded with
0004h. Once in the Interrupt Service Routine, the
source(s) of the interrupt can be determined by polling
the interrupt flag bits. The interrupt flag bit(s) must be
cleared in software before re-enabling interrupts to
avoid recursive interrupts. |
So basically you can't have an interrupt inside another interrupt. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Wed Nov 10, 2004 5:41 am |
|
|
Quote: | So basically you can't have an interrupt inside another interrupt. |
Can't is such a strong negative. If you want to take a walk on the wild side, you can, and in some rare corner cases it may be desirable, to do so. To make this happen inside your interrupt handler you first have to disable the source of the current interrupt to avoid recursion and then enable global interrupts. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Nov 10, 2004 7:14 am |
|
|
Quote: | To make this happen inside your interrupt handler you first have to disable the source of the current interrupt to avoid recursion and then enable global interrupts. |
Better have written your int handler. If you use the CCS's, the orginal working regs will get trashed. Posiible stack overflows. Bad idea to do this.
The other int still happens, it happens after the orginal int is finished. Now a trick that I used in the past was to insert a goto at the end of the int handler to goto the start of all the bit tests of CCS's int handler. This saves the time required to restore and then resave all the regs. You will have to make sure the int flags are cleared. Remember to keep those int handlers short!! This is a good reason why. |
|
|
|