• AVR Freaks

AnsweredHot!PIC32MK Interrupt not working

Author
AdamG
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2009/01/31 14:28:54
  • Location: 0
  • Status: offline
2020/04/03 17:32:21 (permalink)
0

PIC32MK Interrupt not working

Hey everyone, I have a good one here. I've been at this for hours and can't figure out what I'm doing wrong from everyone else. I'm trying to get to Timer1 to trigger an interrupt once every 1ms.
 
I can see TMR1 counting, PR1 has the correct value in it, and IFS0bits.T1IF is set, but the interrupt never triggers. Here's my code snippets:
 
//Configure Timer1
    T1CONbits.TCKPS - 0b01; //1:8 prescaler
    T1CONbits.ON = 0; //Turn off Timer 1
    PR1 = ((PERIF_CLK2/8/1000)-1); //at a 1:8 pre scaler, 1000 ms per second

//Configure Interrupt
    INTCONbits.MVEC = 1; //use multi vectored interrupts

    IPC1bits.T1IP = 1; //Timer1 is priority 1
    //IPC1bits.T1IS = 1; //Timer1 is subpriority 1
    IEC0bits.T1IE = 1; //Timer1 interrupt enable
    IFS0CLR = 16;               //clear the T1 interrupt flag

//Last second config
    TMR1 = 0; //reset Timer1
    T1CONbits.ON = 1; //turn the timer on

 
And here's my Interrupt Code:
 
/* 
 Interrupt every 1ms
 */
void __ISR(_TIMER_1_VECTOR, IPL1SOFT) msTimer (void){
    //Reset the timer
    TMR1 = 0; //reset timer 1
    IFS0CLR = 16; //clear the T1 interrupt flag
    
    *do things*
    
}//void __ISR(_TIMER_1_VECTOR, IPL1SOFT) msTimer (void)

 
I'm sure it's something silly and hopefully someone will spot it instantly.
 
Thanks,
Adam
post edited by AdamG - 2020/04/03 17:36:13
#1
Liem Dung Phan
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2017/09/14 21:09:39
  • Location: 0
  • Status: offline
Re: PIC32MK Interrupt not working 2020/04/03 18:45:21 (permalink) ☼ Best Answerby AdamG 2020/04/04 13:44:56
0
Hi,
Did you enable the global interrupt?
__builtin_enable_interrupts();
#2
TechnoGilles
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2011/08/02 11:44:46
  • Location: 0
  • Status: offline
Re: PIC32MK Interrupt not working 2020/04/03 19:51:31 (permalink)
0
T1CONbits.TCKPS - 0b01; //1:8 prescaler

 
Also that line has a "minus" character instead of "equal" which is actually not setting the prescaler.
 
#3
AdamG
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2009/01/31 14:28:54
  • Location: 0
  • Status: offline
Re: PIC32MK Interrupt not working 2020/04/04 09:51:07 (permalink)
0
liem.phan
Hi,
Did you enable the global interrupt?
__builtin_enable_interrupts();


 
I didn't, I'm from the 8 bit and old school 32 bit world, I looked for a GIE or similar bit but came up empty. Do you know what this function does?

TechnoGilles
T1CONbits.TCKPS - 0b01; //1:8 prescaler

 
Also that line has a "minus" character instead of "equal" which is actually not setting the prescaler.


That probably would have been a pain to find, thank you!
#4
Jump to:
© 2020 APG vNext Commercial Version 4.5