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 CCS Technical Support

Understanding interrupt handler on PIC18

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



Joined: 22 Feb 2007
Posts: 55

View user's profile Send private message

Understanding interrupt handler on PIC18
PostPosted: Mon Aug 16, 2010 3:06 am     Reply with quote

Hello super forum,

I want to use both high and low priority interrupts.
My question is: What happen to my low priority interrupt when the high priority interrupt comes and the low priority interrupt is running?

Does the return from high priority interrupt then return to the low priority interrupt?
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Mon Aug 16, 2010 3:59 am     Reply with quote

First thing, you have to distinguish two different 'types' of priority.

Historically, CCS, has a 'priority' instruction. This affects _only_ the order in which interrupts are checked within the interrupt handler. If not present, this is instead set by the order the interrupts are defined in the code. This 'priority', has no ability for one interrupt to be called inside another. This is available for all chips with interrupts.

Then you have the 'hardware priority'. This is not available on the PIC12/PIC16 chips. It allows two separate interrupt handlers to be used. This is enabled, by selecting 'HIGH_INTS=TRUE' in the device configuration, and then flagging the individual interrupt handler as 'HIGH', or 'FAST' (use the first, unless you very specifically need the second - the second does effectively the same job as #int_default for the low priority interrupts, adding no code to save registers etc., to the handler...). With this done, you then have two complete global interrupt handlers. The first 'low priority' one, handles all the interrupts not flagged as 'HIGH', and the second, the hardware 'high priority' interrupts. These interrupts can then interrupt the low priority interrupts, or the normal code, and since the handlers are separate, there is no 're-entrancy' problem, but not each other.
Big 'caveat' here. If you declare any interrupt handler as 'HIGH', and you also have INT0 (INT_EXT) in use, this interrupt will also be set as 'HIGH'. This is a hardware limitation of the PIC, (not CCS's fault!...), but it does mean that it is worth avoiding INT_EXT, unless you _want_ it to he high priority.....

Having high priority hardware interrupts enabled, will make the interrupt latency to the normal interrupts, slightly worse (the 'RETFIE 1' instruction, which saves the need to save a couple of the registers on entry to the interrupt handler, is used by the high priority handler).

Best Wishes
Mortenc



Joined: 22 Feb 2007
Posts: 55

View user's profile Send private message

PostPosted: Mon Aug 16, 2010 5:46 am     Reply with quote

Thanks for respond,

To be sure I understand this correct.

I use PIC18 family. (I known that PIC12 and PIC16 can't do this).

I want to use:

#INT_CCP1 HIGH
#INT_RDA
#INT_TBE
#INT_RDA
#INT_TIMER1

I you can see one with high priority and 4 with low priority.
The setup for the CCP1 shall be with timer3.

After CCP1 interrupt has taken place the program will return to the other interrupt if they where active when CCP1 was comming. Right?
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Mon Aug 16, 2010 8:57 am     Reply with quote

Yes.
I see you are not using INT_EXT, so that caveat vanishes. :-)
You are listing INT_RDA twice. Presmably (hopefully) the second is INT_RDA2?.

Best Wishes
Mortenc



Joined: 22 Feb 2007
Posts: 55

View user's profile Send private message

PostPosted: Tue Aug 17, 2010 3:00 am     Reply with quote

Sorry the failure in listing,

I'm only want to using INT_RDA one time.

1000 thanks for your help.
neverlog



Joined: 02 May 2010
Posts: 36

View user's profile Send private message

PostPosted: Tue Aug 24, 2010 4:49 am     Reply with quote

Ttelmah wrote:
Yes.
I see you are not using INT_EXT, so that caveat vanishes. :-)
You are listing INT_RDA twice. Presmably (hopefully) the second is INT_RDA2?.

Best Wishes


Will the caveat appear if I use INT_EXT2?

Hope to hear from you.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Aug 24, 2010 4:58 am     Reply with quote

No.
Look at the data sheet..
The 'point' about 'INT0', is it doesn't have a programmable bit specifying whether it is to be high priority or not.
If (for example), you go to the data sheet for the 18F4550, then select the 'interrupts' section, and look at the diagram for 'interrupt logic', you will find that all the interrupts except this one, are present on both the 'high', and 'low' branches of the interrupt hardware wiring, with three inputs to each gate selecting them, one from each of the enable, flag, and priority bits (and inverted from the priority bit, on the 'low' branch). INT0, alone, does not have any connections at all to the low priority branch.

Best Wishes
neverlog



Joined: 02 May 2010
Posts: 36

View user's profile Send private message

PostPosted: Tue Aug 24, 2010 9:33 pm     Reply with quote

Thank you, Ttelmah.
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