View previous topic :: View next topic |
Author |
Message |
Nick Guest
|
can an interrupt interrupt itself? |
Posted: Mon Jan 31, 2005 10:55 am |
|
|
I have a timer2 setup as an interupt. It goes off at around 30hz, if one condition is true then it will delay for one second. but.... I'm wondering if the interrupt will interrupt itself or will it wait for the interrupt function to complete then continue at 30hz?
thanks,
Nick |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jan 31, 2005 11:44 am |
|
|
No it will not interrupt itself. On the PIC18's a high priority interrupt can interrupt a low priority one but not itself. The interrupt handler clears the interrupt flag at the end of the interrupt. I hope you are not sitting in an interrupt for 1 second, but if you are, you will miss any interrupts that occur (for that interrupt) and delay any other interrupts and possibly miss some of those. |
|
|
Nick Guest
|
|
Posted: Mon Jan 31, 2005 12:41 pm |
|
|
thanks, and yes I was sitting in a interupt for one second while testing if an major error occurs.
Nick |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 31, 2005 1:15 pm |
|
|
You can't do nested interrupts, but you can check if a different interrupt
has happened while you're inside the isr for the first interrupt.
You can do this by testing the hardware interrupt flag bit for the
other interrupt source. If it's set, then you can handle the interrupt
while still in the isr for your first interrupt. Then clear the hardware
interrupt flag for the 2nd interrupt with code.
Here's an example, below. In this code, I'm inside the CCP1 isr.
I want to know if a Timer1 interrupt has occurred. So I check
the hardware Timer1 interrupt flag. If it's set, then I handle
the Timer1 interrupt right there. I then clear the hardware flag.
So when the CCP1 isr finishes execution and control returns
to the main program, the Timer1 isr will not be entered.
That's because the hardware flag was cleared in the CCP1 isr,
and we don't want to enter it, because we've already handled it.
Note that this requires using global variables, instead of static
local variables in the Timer1 isr. You have to do it that way
so both isr's can access the variables. In the case of this example,
the global variable used by the Timer1 isr is the "global char"
gc_timer1_extension.
http://www.ccsinfo.com/forum/viewtopic.php?t=906 |
|
|
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Mon Jan 31, 2005 7:05 pm |
|
|
You are implementing a state machine that is hardcoded into the instruction structure, theoretically it can work allright but it can grow very confusing if your code becomes more complex.
You should consider coding a state machine that executes completely different (not overlapping) code segments depending on its state (based on certain variables, flags, ports = conditions)
I suggest you to read about coding state machines (those having flowcharts with that funny circles with arrows to each other), reaching a certain point of complexity, this new coding method will help you a lot. |
|
|
|