• AVR Freaks

Hot!Interrupt (timer) causing resets

Author
signalflow
Senior Member
  • Total Posts : 140
  • Reward points : 0
  • Joined: 2013/08/04 10:39:32
  • Location: 0
  • Status: offline
2015/11/18 11:08:40 (permalink)
0

Interrupt (timer) causing resets

Hi, I am using two of the timer modules in the PIC24FJ256GB210.  I am using timer1 and timer2 (both interrupt after every 1 second elapses).  I believe they appear to be causing my PIC to reset occassionally and I can't figure out why.  When each timer elapses 1 second, then it calls the corresponding interrupt function below:
 
void _ISR _T1Interrupt(void)
void _ISR _T2Interrupt(void)
 
Anyone know why it would cause the PIC to reset?  Sometimes it appears to cause SPI errors and sometimes it causes the whole PIC to reset.
 
Thanks.
#1

16 Replies Related Threads

    MatthewM
    Super Member
    • Total Posts : 204
    • Reward points : 0
    • Joined: 2014/08/08 03:49:49
    • Location: UK
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/11/18 11:49:52 (permalink)
    0
    Is the Watch Dog Timer disabled?
     
    Check the connections
    Be sure to have proper de-coupling, and that your reservoir capacitor (connected to Vcap) is large enough.
     
    Stack overflow is a possibility - are you nesting functions?
    Global variables - if you are using them, change them to volatile. 
    How long is the interrupt routine? - keep it short
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 17817
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Interrupt (timer) causing resets 2015/11/18 16:20:31 (permalink)
    3 (1)
    Check the Reset flags on boot.  They will tell you why.
    Do you have exception handlers?
    #3
    signalflow
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2013/08/04 10:39:32
    • Location: 0
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/11/19 16:12:30 (permalink)
    0
    My Vcap is 10uF (6.3V, 5ohm).
     
    I probably am nesting functions.  I put a return at the end of most functions now and it did not fix the problem.
    I am using a lot of global variables.
    The _T1Interrupt is 70 lines of code.
    The _T2Interrupt is 20 lines of code.
     
    I read the RCON register after an unexpected reset and it is showing bit 14=1.  Bit 14 is described below:
    bit 14 IOPUWR: Illegal Opcode or Uninitialized W Access Reset Flag bit
    1 = An illegal opcode detection, an illegal address mode or uninitialized W register is used as an
    Address Pointer and caused a Reset
    0 = An illegal opcode or uninitialized W Reset has not occurred
     
    What could be causing this?
     
    Thanks.
    #4
    signalflow
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2013/08/04 10:39:32
    • Location: 0
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/11/19 16:15:27 (permalink)
    0
    No I do not have exception handlers.  Can you point me to an example of how to do this?  Says bit 14 is high on the erroneous resets:
    bit 14 IOPUWR: Illegal Opcode or Uninitialized W Access Reset Flag bit
    1 = An illegal opcode detection, an illegal address mode or uninitialized W register is used as an
    Address Pointer and caused a Reset
    0 = An illegal opcode or uninitialized W Reset has not occurred
     
     
    Thanks.
     
    #5
    NKurzman
    A Guy on the Net
    • Total Posts : 17817
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Interrupt (timer) causing resets 2015/11/19 16:30:08 (permalink)
    3 (1)
    That error tells you that you had a exception.
    My guess would be you used an int pointer to a char buffer.  Ints must be word aligned.
     
    I forget, you can look in the compiler folders, or search (it might have been an App note).
    It is a file you can add to your project.
    It will help you find the exception, but you need to fix it.
    #6
    Aussie Susan
    Super Member
    • Total Posts : 3618
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/11/19 19:07:55 (permalink)
    0
    Another reason for that reset condition is that you have somehow messed up the stack and when the ISR (or another function etc.) tries to return, it sets the PC to some random location where it tries to interpret rubbish as an op-code.
    This sort of thing can easily happen if you assign a value through a pointer that is not under control.
    Susan
     
    Edit: I just noticed that you said you had put in return statements. I hope you did NOT put one in to the ISR! An ISR needs to use the 'return from interrupt' instruction and not a simple 'return'. While the compiler *might* be smart enough to handle this, my general rule is that returns in an ISR are simply bad news.
    post edited by Aussie Susan - 2015/11/19 19:11:01
    #7
    Chris A
    Super Member
    • Total Posts : 839
    • Reward points : 0
    • Joined: 2010/07/20 04:37:07
    • Location: 0
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/11/20 05:19:32 (permalink)
    0
    What is _ISR defined as?
     
    #8
    signalflow
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2013/08/04 10:39:32
    • Location: 0
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/11/20 13:53:59 (permalink)
    0
    I have searched the XC16 user manual and XC16 directory and am having a hard time finding any file.  I found a file that shows the interrupt vector table.  I also found the "trap vector details" in the PIC24F manual.  I also found that the INTCON1 (interrupt control register) contains the ADDRERR (Address Error Trap Status bit), but I'm not sure how to use that to find where the error is occuring.
     
     
    #9
    signalflow
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2013/08/04 10:39:32
    • Location: 0
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/11/20 13:59:09 (permalink)
    0
    I have tried this
    void _ISR _T2Interrupt(void)
    and this
    void __attribute__((interrupt,no_auto_psv)) _T2Interrupt(void)
     
    Neither works.
     
    #10
    signalflow
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2013/08/04 10:39:32
    • Location: 0
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/11/20 13:59:59 (permalink)
    0
    I have removed the "return" from the ISR but it is still having the reset problems (bit 14 is high upon reset in the RCON register).
     
    #11
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11329
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/11/20 14:13:57 (permalink)
    3 (2)
    "return" in an interrupt handler does not cause any problems in XC8 or XC16.  It is handled correctly by the compiler.
    #12
    signalflow
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2013/08/04 10:39:32
    • Location: 0
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/11/30 17:12:22 (permalink)
    0
    Could having the Data Memory Model not set to Large be causing this problem?  I tried to build for debugging and it gave me a Link Error: Could not allocate data memory error.  I changed the Data Memory Model to Large (from Default) and the reset glitch seems to have gone away.
    #13
    GlennP
    Super Member
    • Total Posts : 710
    • Reward points : 0
    • Joined: 2009/03/29 15:04:55
    • Location: El Paso County, CO, USA
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/11/30 19:16:07 (permalink)
    3 (1)
    OP:
     
    Can you estimate the longest path length in cycles for the interrupt handlers?
     
    Giving lines of code without knowing what the code does (especially calls) and without knowing the optimization level of the compiler makes it hard to guess how much time is spend in the interrupt handler.
     
    That said, the indication is bad pointer or bad code.  I'd bet on pointer.
     
    GP
    #14
    signalflow
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2013/08/04 10:39:32
    • Location: 0
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/12/01 07:55:28 (permalink)
    0
    My T1 and T2 interrupt code functions are below.
     
    void __attribute__((interrupt,no_auto_psv)) _T1Interrupt(void)
    {
        IEC0bits.T1IE=0; //timer1 interrupt disable
        IFS0bits.T1IF=0; //reset timer1 interrupt flag

        if (flag_testtimer==1) //if running, then count down the minutes and seconds
        {
                if ((timer1min==0) && (timer1sec!=0))
                {
                    timer1sec--;
                }
                else if (timer1min!=0)
                {
                    if (timer1sec==0)
                        {
                            timer1sec=59; //reset seconds counter
                            timer1min--;
                        }
                    else if (timer1sec!=0)
                        {
                            timer1sec--; //decrement seconds
                        }
                }
        }
        
        //For the right-side timer
        if (flag_testtimer2==1) //if running, then count down the minutes and seconds
        {
                if ((timer2min==0) && (timer2sec!=0))
                {
                    timer2sec--;
                }
                else if (timer2min!=0)
                {
                    if (timer2sec==0)
                        {
                            timer2sec=59; //reset seconds counter
                            timer2min--;
                        }
                    else if (timer2sec!=0)
                        {
                            timer2sec--; //decrement seconds
                        }
                }
        }
        IEC0bits.T1IE=1; //timer1 interrupt enable
    }
    //-----------------------END OF T1 Interrupt Function------------------


    void __attribute__((interrupt,no_auto_psv)) _T2Interrupt(void)
    {
        IEC0bits.T2IE=0; //timer2 interrupt disable
        IFS0bits.T2IF=0; //reset timer2 interrupt flag

        //Lift Timer

        if (((flag_lift_up_motor==1)||(flag_lift_down_motor==1))&&(lift_seconds!=0))
        {
            //counting down
            lift_seconds=lift_seconds-1; //decrement seconds
        }
        
        if (((flag_lift2_up_motor==1)||(flag_lift2_down_motor==1))&&(lift2_seconds!=0))
        {
            //counting down
            lift2_seconds=lift2_seconds-1; //decrement seconds
        }
        IEC0bits.T2IE=1; //timer2 interrupt enable

    }
    //-----------------------END OF T2 Interrupt Function------------------

    #15
    N_S_pole
    Starting Member
    • Total Posts : 46
    • Reward points : 0
    • Joined: 2015/05/11 06:49:06
    • Location: NY, USA
    • Status: offline
    Re: Interrupt (timer) causing resets 2015/12/01 12:37:58 (permalink)
    3 (1)
    Try not to enable/disable interrupt bit (IEC0bits.T2IE) in ISR. See if it works.
     
     
    #16
    vra
    Junior Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2014/07/14 18:35:19
    • Location: 0
    • Status: offline
    Re: Interrupt (timer) causing resets 2019/09/20 15:12:11 (permalink)
    0
    signalflow
    My T1 and T2 interrupt code functions are below.
     
    void __attribute__((interrupt,no_auto_psv)) _T1Interrupt(void)
    {
        IEC0bits.T1IE=0; //timer1 interrupt disable
        IFS0bits.T1IF=0; //reset timer1 interrupt flag

        if (flag_testtimer==1) //if running, then count down the minutes and seconds
        {
                if ((timer1min==0) && (timer1sec!=0))
                {
                    timer1sec--;
                }
                else if (timer1min!=0)
                {
                    if (timer1sec==0)
                        {
                            timer1sec=59; //reset seconds counter
                            timer1min--;
                        }
                    else if (timer1sec!=0)
                        {
                            timer1sec--; //decrement seconds
                        }
                }
        }
        
        //For the right-side timer
        if (flag_testtimer2==1) //if running, then count down the minutes and seconds
        {
                if ((timer2min==0) && (timer2sec!=0))
                {
                    timer2sec--;
                }
                else if (timer2min!=0)
                {
                    if (timer2sec==0)
                        {
                            timer2sec=59; //reset seconds counter
                            timer2min--;
                        }
                    else if (timer2sec!=0)
                        {
                            timer2sec--; //decrement seconds
                        }
                }
        }
        IEC0bits.T1IE=1; //timer1 interrupt enable
    }
    //-----------------------END OF T1 Interrupt Function------------------


    void __attribute__((interrupt,no_auto_psv)) _T2Interrupt(void)
    {
        IEC0bits.T2IE=0; //timer2 interrupt disable
        IFS0bits.T2IF=0; //reset timer2 interrupt flag

        //Lift Timer

        if (((flag_lift_up_motor==1)||(flag_lift_down_motor==1))&&(lift_seconds!=0))
        {
            //counting down
            lift_seconds=lift_seconds-1; //decrement seconds
        }
        
        if (((flag_lift2_up_motor==1)||(flag_lift2_down_motor==1))&&(lift2_seconds!=0))
        {
            //counting down
            lift2_seconds=lift2_seconds-1; //decrement seconds
        }
        IEC0bits.T2IE=1; //timer2 interrupt enable

    }
    //-----------------------END OF T2 Interrupt Function------------------





    Four years later but: in the timer 2 are you using 32 bits timer or 16 bits timer?. If you are using the 32 bits timer then you must use the _T3Interrupt handler routine.
    #17
    Jump to:
    © 2019 APG vNext Commercial Version 4.5