I am knocking my head for some time now. It seams that I cant get multi vector interrupt to work, like it has stuck to single vector interrupt ie. no priority.
This code triggers timer 2 and then loops for some time inside.. Timer1 should interrupt Timer2 routine because it is much faster but it never does. Only when Timer2 ISR exits Timer1 ISR enters.
Code: Select all
unsigned int br;
void Timer1Interrupt() iv IVT_TIMER_1 ilevel 7 ics ICS_SOFT {
LATB.B15 = !LATB.B15;
T1IF_bit = 0; // Clear T1IF
}
void Timer2Interrupt() iv IVT_TIMER_2 ilevel 6 ics ICS_SOFT {
LATB.B12 = 1;
for (br=0;br<0xFFFF;br++){asm nop;}
LATB.B12 = 0;
T2IF_bit = 0; // Clear T2IF
}
void InitMCU(){
/////Unlock writing to registers
SYSKEY = 0x0; // ensure OSCCON is locked
SYSKEY = 0xAA996655; // Write Key1 to SYSKEY
SYSKEY = 0x556699AA; // Write Key2 to SYSKEY
INTCONbits.MVEC = 1; //turn on multi vector interrupts
TRISB = 0b0010100010010011;
TRISA = 0b00111;
ANSELA = 0;
ANSELB = 0b1100; //analog inputs AN2 i AN3
CNPUA = 0; // turn off pullups
CNPUB = 0;
CNPDA = 0; // turn off pulldowns
CNPDB = 0;
///////////////////////////////////////////////////////configure Timer1/////////////////////////////////////////////////////////////////////
PMD4bits.T1MD = 0;
T1CONbits.ON = 1;
T1CONbits.TCKPS = 0b00; //prescaler 0b11 -> 256, 0b10 -> 64, 0b01 -> 8, 0b00 -> 1
IPC1bits.T1IP = 7; //set priority to 7
IPC1bits.T1IS = 2;
IEC0bits.T1IE = 1;
IFS0bits.T1IF = 0;
TMR1 = 0;
///////////////////////////////////////////////////////configure Timer2/////////////////////////////////////////////////////////////////////
PMD4bits.T2MD = 0;
T2CONbits.ON = 1;
T2CONbits.TCKPS = 0b11; //prescaler 0b11 -> 256, 0b10 -> 64, 0b01 -> 8, 0b00 -> 1
IPC2bits.T2IP = 6; //set priority to 6
IPC2bits.T2IS = 2;
IEC0bits.T2IE = 1;
IFS0bits.T2IF = 0;
TMR2 = 0;
EnableInterrupts(); // Enable all interrupts
}
void main() {
InitMCU();
while(1);
}
What am I doing wrong?
Maybe I am not initializing multi vector interrupts properly.
I have attached whole project if anybody has time and this MCU to test it.
P.S.
I have written same program in MPLABx and it works fine.