Custom interrupt - help

For general Flowcode discussion that does not belong in the other sections.
Post Reply
jay_dee
Posts: 130
http://meble-kuchenne.info.pl
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 46 times
Been thanked: 29 times

Custom interrupt - help

Post by jay_dee »

Hi,
working with a PICF1615324 and using the internal comparitor. I think I have this part working. :)
There is an option to trigger an interupt when the comparitor changes state.
How would i go about this in FC, use the custom Interrupt I guess...

I'm not looking for help on this chips specific interrupt but what in general I should be doing to get a custom interupt to work.

Enable Code. Set the required register bits for correct operation of the interupt. Such as...

Code: Select all

st_bit(CM1CON0,C1ON);
st_bit(CM1CON0,C1POL);
st_bit(CM1CON1,C1INTP);
st_bit(PIE2,C1IE);
st_bit(INTCON,PEIE);
st_bit(INTCON,GIE);
Handler Code. Is this what to do when the interrupt is triggered?
If I have a macro called "TmrStart" I should insert...

Code: Select all

FCM_TMRSTART();
do I need to do anything else?
thanks, J.

jay_dee
Posts: 130
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 46 times
Been thanked: 29 times

Re: Custom interrupt - help

Post by jay_dee »

So I found an old project Ben helped me with... I think I need the following;
My method of setting/clearing bits was also not passing the compiler but thats a topic for another thread.
Enable:

Code: Select all

CM1CON0 = CM1CON0 | (1<<7); //Turn Comparitor 1 ON
CM1CON0 = CM1CON0 | (1<<4); // Set Polarity of Comparitor 1
CM1CON1 = CM1CON1 | (1<<1);  //Enable Comparitor 'Positive' Interupt 

PIR2 = PIR2 & ~(1<<0); //Clear Comparitor 1 Flag ( C1IF Bit 0) in Periferal Interrupt Request register.
PIE2 = PIE2 | (1<<0);  // C1IE Enable Comparitor C1 Interrupt

INTCON = INTCON | (1<<6); //PEIE Enable Peripheral Interrupts
INTCON = INTCON | (1<<7); //GIE Enable Global Interrupt
 
Handler:

Code: Select all

if ((PIR2 >>0)&1)              // If bit 0 of PIR2 register is set TRUE then. 
{
FCM_%n(); // call macro defined 
PIR2 = PIR2 & ~(1<<0);  // Clears the C1IF Flag which triggered this event. 
}
this seems to be working...early days but progess I think. ;)

Post Reply