• AVR Freaks

Hot!Problem with several interruptions PIC18F45K22

Author
xSkyMicro
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2018/12/20 07:38:20
  • Location: 0
  • Status: offline
2019/04/09 06:31:50 (permalink)
0

Problem with several interruptions PIC18F45K22

Hello, 
 
I have some problems with my PIC18F45K22 when i try to use differents intteruptions at the same time. 
For example, i have a Timer and i want to add ADC interruption, UART interruption, etc. But if i have ADC interruption and Timer interruption, my PIC will freeze. 
If i use them independently, it works. So i wonder if this PIC can really use several interruptions at the same time. 
 
Has anyone ever had this problem ? Does anyone have a solution ? 
 
Actually i use my timer interruption to regularly check the others modules. 
 
My PIC config : 

 
 
Thanks in advance
 
post edited by xSkyMicro - 2019/05/22 00:53:00

Attached Image(s)

#1

5 Replies Related Threads

    mpgmike
    Super Member
    • Total Posts : 258
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: online
    Re: Problem with severPIC18F45K22 2019/04/09 07:43:18 (permalink)
    +1 (1)
    You showed your CONFIGs, but no applicable code.  When the PIC triggers an interrupt and goes to the ISR, it automatically disables GIE.  When you RETFIE, it re-enables GIE.  If you simultaneously trigger 2+ PIRs, that could be the cause of your lock-up, though I doubt it.  Your ISR should filter through Interrupt Flags & Call the appropriate action depending on the set PIR flag.  If you're using Priority Interrupts, you may have UART as a lower priority and one of your Timers as a high priority.  UART Receive can overflow.
     
    Try adding one interrupt at a time to see when it locks up.  If it locks up with the 2nd interrupt added, try adding a different one.  Try starting with a different one.  It may be a quirky combination and/or your ISR code causing it.
    #2
    jack@kksound
    code tags!
    • Total Posts : 3203
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Problem with severPIC18F45K22 2019/04/09 07:45:53 (permalink)
    +3 (3)
    Did you think the problem was in your configuration words? Don't post only the part you think is relevant (because it isn't), post all your program code. My guess is that your ISR is wrong or your interrupt enables are wrong. None of that is in the config words. 
    #3
    pcbbc
    Super Member
    • Total Posts : 1255
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Problem with severPIC18F45K22 2019/04/09 18:53:44 (permalink)
    +2 (2)
    xSkyMicroActually i use my timer interruption to regularly check the others modules.
    If I have read and understood that correctly, then that is NOT how to do it.


    Each module has its own interrupt enable and interrupt flag. If you are enabling multiple interrupts, but then not checking them individually, but instead just relying on the timer occasionally firing and using that to check if a module requires some action - then sure, you will get a lockup almost for certain.

    As others have said, post your entire code. And as text, not as a image please. You can enclose the code in tags [CODE]//put your code here![/CODE] to get it formatted correctly. Note that the word “code” must be in lower case (I used upper case here deliberately so they do not work, but so you can see them).
    #4
    xSkyMicro
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2018/12/20 07:38:20
    • Location: 0
    • Status: offline
    Re: Problem with severPIC18F45K22 2019/05/22 00:49:32 (permalink)
    0
    Sorry for my late reply, i worked on other projects. 
    So, 
    pcbbc
    If I have read and understood that correctly, then that is NOT how to do it.



    I understand what you mean but no, i don't use my timer like this. It's just because, at the moment, i cannot use differents interruptions at the same time so i disabled all interruptions and i use my timer to check ADC for example. 
     
    This is my interruptions code : 
     
    void __interrupt() INTERRUPT_InterruptManagerHigh (void)

    {
    // interrupt handler

    if(INTCONbits.TMR0IE == 1 && INTCONbits.TMR0IF == 1)
    {
    TMR0_ISR();
    }
    /*
    else if(INTCONbits.INT0IE == 1 && INTCONbits.INT0IF == 1)
    {
    INT0_ISR();
    }
    else if(INTCON3bits.INT1IE == 1 && INTCON3bits.INT1IF == 1)
    {
    INT1_ISR();
    }*/

    //UART1
    else if(PIE1bits.TX1IE == 1 && PIR1bits.TX1IF == 1)
    {
    //EUSART1_TxDefaultInterruptHandler();
    }
    else if(PIE1bits.RC1IE == 1 && PIR1bits.RC1IF == 1)
    {
    // EUSART1_RxDefaultInterruptHandler();
    }

    //UART2
    //else if(PIE3bits.TX2IE == 1 && PIR3bits.TX2IF == 1)
    else if(PIE3bits.TX2IE == 1 && PIR3bits.TX2IF == 1)
    {
    // EUSART2_TxDefaultInterruptHandler();
    }
    else if(PIE3bits.RC2IE == 1 && PIR3bits.RC2IF == 1)
    {
    // EUSART2_RxDefaultInterruptHandler();
    }
    else if(PIE2bits.LVDIE == 1 && PIR2bits.LVDIF == 1)
    {
    //HLVD_ISR();
    }
    {
    //Unhandled Interrupt
    }

     
    TMR0 is my timer that i use in my code. 
    For EUSART, i just use the first one, not the second. 
    I need this EUSART to etablish a communication between my PIC 18F45K22 and a Bluetooth module. 
    To be honest, i tried to use differents interruptions few months ago and i didn't retry yet. 
     
     
    Actually, i succeeded to use all without interruptions but i think it can be better for the communication between the 2 components if i use interruptions. 
     
    If i post my configs code it's because when i tried, i tried to use them independently and i succeeded but if i have two of them, or 3, it doesn't works.  
     
    My function is "interrupt manager high" but all is "high", maybe i can try to put UART in low interruption. 
     
    post edited by xSkyMicro - 2019/05/22 00:52:25
    #5
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Problem with severPIC18F45K22 2019/05/22 01:07:12 (permalink)
    0
    We would need to see what is inside those service functions you are calling also.
     

    Nearly there...
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5