View previous topic :: View next topic |
Author |
Message |
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
#priority |
Posted: Thu Sep 26, 2013 12:12 pm |
|
|
Hi, In a recent project with an 18F2550, I was able to use the #priority directive to prioritise interrupts.
My current project uses an 18LF2620 at 10MHz on 3.3V. When I include the #priority directive, the compiler says "invalid preprocessor directive".
However the datasheets of both devices says the interrupts can be prioritised.
What am I doing wrong and how do you set their priorities?
PCWH v3.249 |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Sep 26, 2013 12:34 pm |
|
|
have you used the search feature of the forum?
i believe your answer is there.
i searched on the term
#PRIORITY
and liked what i found
wisdom in there ...
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 26, 2013 1:27 pm |
|
|
If I compile a test program with only a main() and just #priority, I get
this message from a modern version of the compiler:
Quote: | *** Error 7 "PCH_Test.c" Line 13(0,1): Invalid Pre-Processor directive No interrupts listed |
|
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
#Priority |
Posted: Thu Sep 26, 2013 1:48 pm |
|
|
Yes, I did search the forum and didn't find the answer. If I had, I wouldn't have posted the question!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Thu Sep 26, 2013 2:32 pm |
|
|
First, 'priority' has nothing to do with the PIC 18 chip's hardware priority.
All it does is set the order in which interrupts are 'scanned' in the global handler. It won't allow an interrupt to interrupt another.
It'll only work, with some interrupt names.
If (for instance), you have INT_RDA, and INT_EXT, then:
Code: |
#PRIORITY INT_RDA,INT_EXT
|
will mean that INT_RDA will be checked _first_ in the global handler.
If it is not used, interrupts are checked in the order they are declared.
It won't have been enabling hardware priorities with your 2550 code.
#PRIORITY dates in CCS, from before any chips had hardware priorities.
Hardware prioritising, is done with three separate directives:
First at the top of the program (just after the processor type is defined), you need:
#DEVICE HIGH_INTS=TRUE
This enables interrupt hardware levels to be used.
Then the interrupt that you want to be 'high priority' (in hardware), needs to have it's declaration followed by 'HIGH'. So:
There is a third directive 'FAST', but this should only be used if you know exactly what you are doing. This sets up a hardware high priority interrupt, but does not save the registers for you (equivalent to #INT_GLOBAL for the normal interrupts).
Now you need to be aware that INT_EXT, is _always_ high priority, if hardware priorities are enabled. This is a hardware limitation of the PIC.
Your "Invalid Pre-Processor directive" message comes because you have not included any interrupt names in the declaration, or the names are not ones that are enabled.
Asmboy is right, that the has been answered many times before here. I know, I've typed several of these answers.
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Sep 26, 2013 2:45 pm |
|
|
Update: I see Ttelmah posted an answer while I was typing mine. For extra info I'll have it here as it is.
The hint you were given is that the error message you list does not match the code as you describe it.
One golden rule on this forum is that for the best response you should always post an example program demonstrating your problem. Make the program small, about 10 lines, and complete including the #fuses line so we can copy/paste it into our compiler.
Often when creating the tiny program you will discover the problem cause yourself.
In your project I suspect a small syntax error.
Also from your description I notice that you misunderstand how to configure the interrupt priorities. Your processor has hardware support for two interrupt levels: normal and high.
The processor's #priority directive has nothing to do with these hardware priorities. #priority is used for the special case where two interrupts of the same hardware interrupt priority occur at exactly the same moment. In that special case you can define which priority is placed higher in the list of the (software based) interrupt dissector. In my opinion an (almost) useless compiler directive. Interrupts should be handled as fast as possible, meaning that never 1 interrupt can be missed. Having designed your software that way there is no need for handling this special case.
By default the compiler sets all interrupts at the 'normal' hardware level. You create a 'high' level interrupt by adding the keyword 'HIGH': Code: | #INT_xxx // normal interrupt level
#INT_xxx HIGH // High interrupt level | More info in the compiler manual in the #INT_xxxx chapter.
Note 1: INT_EXT on most chips is hard wired to the High level. This will interfere with any other High level interrupt you create.
Note 2: The CCS compiler also has a FAST directive. This is similar to the GLOBAL directive on the normal interrupt level. I do not recommend to use this unless you have extreme tight timing requirements and know exactly what you are doing as you will have to write your own assembly code for saving / restoring the registers you touch. This can change with every feature you add to your program and can even change with a new compiler release. |
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
Priority |
Posted: Fri Sep 27, 2013 2:04 am |
|
|
Thank you both for your replies which have made matters much clearer. I found the reason for the error message as I had used int_rda instead of just rda! |
|
|
|