Electronic – PIC32, XC32, timer interrupt vector not entered

interruptspic

I have the below timer 5 interrupt vector that is not entered, even when both the corresponding Interrupt enable bit for timer 5 is set, and the corresponding interrupt flag for timer 5 is set.

Here is my interrupt vector handler:

void __ISR(_TIMER_5_VECTOR,IPL4SOFT) _T5Interrupt(void)
{
    PORTDbits.RD2 = 1;  // << -- LED will light when here. 
    T4CONbits.ON = 0;
    TMR4 = 0;
    TMR5 = 0;
    Global_TimeOut = 1;
    IFS0bits.T5IF = 0;
}

My global interrupts are set to accept multi-vector interrupts and is initialized as follows:

void Init_Global_Interrupts(void)
{
    // Initializing Global Interrupts
    //INTCON
    // 16 Single Vector is not presented with a shadow register set
    INTCONbits.SS0 = 0;
    // 12 Interrupt Controller configured for multi vectored mode
    INTCONbits.MVEC = 1;
    // 10 - 8 Disables interrupt proximity timer
    INTCONbits.TPC = 0;
    // 4 External interrupt 0 falling edge interrupt
    INTCONbits.INT0EP = 0;
    // 4 External interrupt 1 falling edge interrupt
    INTCONbits.INT1EP = 0;
    // 4 External interrupt 2 falling edge interrupt
    INTCONbits.INT2EP = 0;
    // 4 External interrupt 3 falling edge interrupt
    INTCONbits.INT3EP = 0;
    // 4 External interrupt 4 falling edge interrupt
    INTCONbits.INT4EP = 0;
}

Timer 4 and timer 5 is being used in 32 bit mode. As the data sheet states, in this configuration, it is timer 5 interrupts that is used:

void Init_Timer4_5(void)
{
    // 15 - Timer 4 is off
    T4CONbits.ON = 0;
    // 13 - Continue operation when device enters idle mode
    T4CONbits.SIDL = 0;
    // 7 - Gated time accumulation is disabled
    T4CONbits.TGATE = 0;
    // 6 - 4 - 1:8 prescale to achieve a 1uS unit time
    T4CONbits.TCKPS = 3;
    // 3 - Timer 4 and 5 set for 32 bit operation
    T4CONbits.T32 = 1;
    // 1 - Use internal Peripheral clock
    T4CONbits.TCS = 0;

    // Setting Timer 5 priority to level 4 of 7
    IPC5bits.T5IP = 4;
    // setting timer 5 sub priority to level 1 of 3
    IPC5bits.T5IS = 1;
    // Clear timer interrupt flag
    IFS0bits.T5IF = 0;
    // Enable timer interrupts
    IEC0bits.T5IE = 1;
}

The timers are started with the following function:

void Time_Out(unsigned int uTime)
{
    T4CONbits.ON = 0;
    TMR4 = 0;
    TMR5 = 0;
    Global_TimeOut = 0;

    PR4 = uTime;

    T4CONbits.ON = 1;
}

As far as I can tell, I have done everything necessary.

Let me know if you require any additional information.

Best Answer

I also had to turn on the global interrupts. Its somewhat of a hidden bit.

It is a bit within the Coprocessor status register, and you can enable it by using:

__asm__("EI");

or disable it by using:

__asm__("DI");