I'm trying to get the Timer2 period match interrupt on my dsPIC33FJ128GP802 working. I want it to interrupt after ~480 cycles. I'm using MPLAB C30.
I have, to initialize the timer and interrupt:
// Initialize Timer2, which is used for output timing.
T2CONbits.TON = 1;
T2CONbits.TSIDL = 0;
T2CONbits.TCKPS = 0;
T2CONbits.TCS = 0;
T2CONbits.T32 = 0;
// Initialize Timer2 interrupt with a slightly
// higher priority.
IPC1bits.T2IP = 5;
IFS0bits.T2IF = 0;
IEC0bits.T2IE = 0;
(the timer interrupt is initially disabled)
I have already got pin change interrupts working with a priority of 4. I want the Timer2 interrupt to have a higher priority.
And to set up the interrupt I have this:
T2CONbits.TON = 1;
TMR2 = 0;
timer2_osd = 480 + vid_hoffset;
PR2 = timer2_osd;
IEC0bits.T2IE = 1;
I also have an ISR,
void _MY_ISR _T2Interrupt()
{
IFS0bits.T2IF = 0;
return;
}
However I find the processor just resets and will not run with this enabled. It will work with a busy loop checking the timer, but that wastes cycles.
Can anyone see where I've gone wrong?