• AVR Freaks

Hot!PIC32MK - Changing interrupt priority causes a freeze

Author
Blue_Key
Senior Member
  • Total Posts : 130
  • Reward points : 0
  • Joined: 2011/12/20 04:48:22
  • Location: 0
  • Status: offline
2019/07/10 05:27:07 (permalink)
0

PIC32MK - Changing interrupt priority causes a freeze

I'm using a timer on the PIC32MK1024MCF100.
 
The code works fine, however, increasing the interrupt priority causes the chip to freeze and go reset (Watchdog).
 
This is not caused by starvation of CPU, as the timer is running for 200ms period at a time and the WDT is set to several seconds.
 
This is my init code:
 
void initTimer4()
{
    T4CON = 0x0;
    TMR4 = 0x0; 
    PR4 = 7500;
    T4CONbits.TCKPS = 0b11;
    
    IEC0bits.T4IE = 0;
    
    IPC4bits.T4IP = 3;
    IPC4bits.T4IS = 3;
    
    IFS0bits.T4IF = 0;
    IEC0bits.T4IE = 1;
    
    T4CONbits.ON = 0;
}

 
This works fine, however, if I change IPC4bits.T4IP to 4 or more, this causes the freeze/reset. Changing IPC4bits.T4IS seems not to affect.
 
Interrupt code:
void __ISR(_TIMER_4_VECTOR,IPL3SOFT)Timer4Handler(void)
{
    IFS0bits.T4IF = 0;
// do some other stuff
}

 
The background:
The code handled by this interrupt seems to sometimes, randomly, not work properly. It happens about 0.1% of the time. I naturally thought it could be caused by another interrupt being triggered, somewhat affecting it. Changing IPC4bits.T4IS from 1 to 3 seems to have reduced this occurrence to 0.001% of the time, but still does sometimes.
 
Interrupt on the PIC32MK are still quite vague to me despite reading the doc and some help would be very appreciated.
#1

4 Replies Related Threads

    andersm
    Super Member
    • Total Posts : 2623
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: online
    Re: PIC32MK - Changing interrupt priority causes a freeze 2019/07/10 06:43:55 (permalink)
    0
    The priority level must match that given in the ISR's attributes. So if you increase the interrupt's priority to 4, then you must also change the ISR's priority to IPL4SOFT. If you don't, the interrupt will recurse until stack exhaustion causes a fault.
    #2
    Blue_Key
    Senior Member
    • Total Posts : 130
    • Reward points : 0
    • Joined: 2011/12/20 04:48:22
    • Location: 0
    • Status: offline
    Re: PIC32MK - Changing interrupt priority causes a freeze 2019/07/10 22:34:08 (permalink)
    0
    Thanks andersm!
     
    Is it possible, for whatever reason, in PIC32MK that the interrupt code doesn't execute till the end?
     
    I seem to have this behavior on two different projects, both on the same PIC32MK, although I've never seen that on other pic (PIC24, 33...).
    post edited by Blue_Key - 2019/07/10 22:53:55
    #3
    andersm
    Super Member
    • Total Posts : 2623
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: online
    Re: PIC32MK - Changing interrupt priority causes a freeze 2019/07/11 06:21:44 (permalink)
    0
    Blue_KeyIs it possible, for whatever reason, in PIC32MK that the interrupt code doesn't execute till the end?

    I don't understand what you mean by that.
    #4
    maxruben
    Super Member
    • Total Posts : 3348
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re: PIC32MK - Changing interrupt priority causes a freeze 2019/07/13 03:57:25 (permalink)
    0
    Use the SET/CLR/INV register offset to change individual bits in SFR registers, especially important for bits that can be changed by the hardware and where several bits are shared by the same register such as interrupt flags. Using the SET/CLR/INV offsets results in atomic changing of the bit(s) while the register.bit= does not. Non atomicity may result in missed isrs or isrs executing twice due to read/modify/write issues. 
     
    See also this post: https://www.microchip.com/forums/FindPost/1101899
     
    /Ruben
     
     
    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5