CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

can an interrupt interrupt itself?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Nick
Guest







can an interrupt interrupt itself?
PostPosted: Mon Jan 31, 2005 10:55 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 31, 2005 11:44 am     Reply with quote

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







PostPosted: Mon Jan 31, 2005 12:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 31, 2005 1:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 31, 2005 7:05 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group