PIC18 Interrupt Priority

Forum for problems or queries regarding the Flowcode application and compiler usage.

Moderators: Benj, Mods

Post Reply
JACQUOT
Posts: 2
Joined: Mon Feb 15, 2010 4:29 pm
Contact:

PIC18 Interrupt Priority

Post by JACQUOT »

Hello,

I'm programming pic 18f4550 with flowcode V3 for pic .
I have to use the high (int0,int1,int2) and low(tmr1) Interrupt priorities of the pic18.
Is there a simple way to program these interrupt priorities in flowcode3 ?

Best Salutations

JFJ

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC18 Interrupt Priority

Post by Benj »

Hello,

The INTCON2 and INTCON3 registers allow you to set priority on some interrupt channels.

You can write to these registers using a C code icon.

eg.

Code: Select all

intcon2 = intcon2 | 0x80;     //Enables INT2 as high priority

JACQUOT
Posts: 2
Joined: Mon Feb 15, 2010 4:29 pm
Contact:

Re: PIC18 Interrupt Priority

Post by JACQUOT »

Hello benj,
At first, many thanks for your quick answer,
In your example, you set the register intcon2. bit 7 to 1 to set high priority to INT2. To do this action with 18f4550, you must set intcon3.bit7 to 1 rather than intcon2. bit 7, but it's not the problem.

After compiling, I look at the c code . With interrupt priority enable, I expect to find two interrupt routines, one called :interrupt and another called :interrupt_low. There is never second interrupt routine (interrupt_low) in the code. It seems that the compiler gives code without priority (pic16 mode). All the compiler and linker options are set for pic18.

My version of flowcode is 3.6.11.53.

Thanks by advance for your help,
Best Salutations,
JFJ

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC18 Interrupt Priority

Post by Benj »

Hello,

Not all the PIC devices have separate handlers and interrupt priority is more fundamental.

For example tmr0 is high priority and tmr1 is low priority.

tmr1 fires and is serviced, half way through the routine tmr0 fires and straight away it is serviced before jumping back to finish tmr1.

On the other hand, tmr0 fires and is services, halfway through the routine tmr1 files and has to wait until tmr0 finishes before being serviced.

At least that's what I think is happening.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC18 Interrupt Priority

Post by Benj »

Hello Benj,

I agree with your interrupt priority explanation, but to do what you describe, the controller (pic18f4550) must have several interrupt vectors (2 for pic18). This process is describe in the interrupt priority chapter, Boostc manual.

In your first answer you tell me to set different registers to use interrupt priority. It's ok, but the c code must contain 2 interrupt handlers. Without these 2 routines you can enable the interrupt priority register but all interrupts are treated by the processor with the same priority level and it's not what we expect.

Do you know a way to set the compiler to pic18 mode with interrupt priority enable (2 interrupt handlers)?

Please could you transfer my post to your colleages, It's quite important for us to use these pic18 fonctions.

Flowcode is a very convenient and powerfull tool, we use it every day in our lab and for the first time we meet an incontournable problem.

Thanks a lot for your help.

JFJ
Hello,

Hm let me have a think on this and see if there is a way to make this work. I'm thinking of maybe adding the low priority interrupts via C code in the supplementary code window would work.

For example, you create your program as normal using default interrupts. Once you have this working you take the Flowcode output C file and copy out the Interrupt code from the interrupt handler function that you wish to make low priority. Next after you enable a low priority interrupt you will need to add a C code icon to make the interrupt low priority. Once you have done this you can add your copied code into a function created in the supplementary code window.

Code: Select all

void interrupt_low(void)
{
//Interrupt Code Goes Here
}

Post Reply