I am trying to use an encoder and want to use interrupts, but I cannot figure out how to enable them! How do you enable interrupts? I have it programmed, just not enabled! :o
You need to call âInitialize_Interrupts();ââŚ
âŚwhich is called in user_routines.c under function âvoid User_Initialization (void)â (at least in my teams code it works there)
Heâs refering to Kevin Watsonâs interrupt code which is avialable at http://www.kevin.org/frc.
If you want to just turn on the interrupts without having to go through that, then youâll have something like this in User_Initialization() (Or somewhere are there. You just have to do this before the interrupts are on)
I just copied this from the function in Watsonâs code which was referred to earlier, with one change (in bold) which actually enables the interrupt. Kevinâs code just sets it up.
TRISBbits.TRISB2 = 1; // make sure the RB2/INT2 pin is configured as an input [108]
INTCON3bits.INT2IP = 0; // 0: interrupt 1 is low priority (leave at 0 for IFI controllers) [91]
// 1: interrupt 1 is high priority
INTCON2bits.INTEDG2 = 0;// 0: trigger on the falling-edge [90]
// 1: trigger on the rising-edge
INTCON3bits.INT2IF = 0; // 0: external interrupt 1 hasn't happened (set to 0 before enabling the interrupt) [91]
// 1: external interrupt 1 has happened
INTCON3bits.INT2IE = **1**; // 0: disable interrupt 1 [91]
// 1: enable interrupt 1
That enables the interrupt on digital input 1. To learn how to do the rest, Iâd look at Mr. Watsonâs code and read this white paper.