• AVR Freaks

Hot!nesting interrupt

Author
renatochiara
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2016/05/28 00:18:02
  • Location: 0
  • Status: offline
2019/06/25 06:42:28 (permalink)
0

nesting interrupt

Hi, I'm using dspic33ep512mu810 and MPLAB XIDE v.5.10.
I must use  external interrupt 1 - INT1- in nesting on the other interrupts, but I don't  know  how do it.
For example, I've one interrupt on timer1 and one on INT1. I set these two interrupt in this mode:
 
void initTimer1 (void)
{
....
        IPC0bits.T1IP = 1;     // Set Timer 1 Interrupt Priority Level
        IFS0bits.T1IF = 0;        // Clear Timer 1 Interrupt Flag
        IEC0bits.T1IE = 1;        // Enable Timer1 interrupt
        T1CONbits.TON = 1;        // Start Timer
}
 
void ExternalINT1 (void)
{
        IFS1bits.INT1IF = 0;          //EX_INT1_InterruptFlagClear();   
        INTCON2bits.INT1EP = 1;  //EX_INT1_NegativeEdgeSet();
        IEC1bits.INT1IE = 1;        //EX_INT1_InterruptEnable();
        IPC5bits.INT1IP = 6;
}
 
      INTCON1bits.NSTDIS=0;   // nesting interrupt enable
 
 
void __attribute__((__interrupt__, no_auto_psv)) _T1Interrupt(void)  // every 10 msec
{
   while (1) {}
   IFS0bits.T1IF = 0;
}   
 
void __attribute__ ( ( interrupt, no_auto_psv ) ) _INT1Interrupt(void)
{
    POSQEI1=POS1CNTL;
    POSQEI1 |= (uint32_t)POS1CNTH<<16;    
    IFS1bits.INT1IF = 0;    //EX_INT1_InterruptFlagClear();
 }
 
 when interrupt of timer1 occurs the firmware is close in the while cycle, but when the INT1 interrupt occurs, the firmware does not switch to manage INT1 routine.
In the reference manuale DS70000600D is made to the FALTREG register, but in the dspic33ep512mu810 this is not present.
Can you help me?
Best Regards.
Renato
 
 
 
#1

9 Replies Related Threads

    renatochiara
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2016/05/28 00:18:02
    • Location: 0
    • Status: offline
    Re: nesting interrupt 2019/06/26 00:15:57 (permalink)
    0
    Hi.
    Can anyone give me any suggestions or examples?
    Thanks.
    Renato
    #2
    mpgmike
    Super Member
    • Total Posts : 313
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: online
    Re: nesting interrupt 2019/06/26 03:44:48 (permalink)
    0
    What is your reason for lingering in the T1 ISR?  Why do you even have a TIMER1 Interrupt when you are just looping?  Is it for test purposes for Interrupt Priority?  Even so, after your INT1 ISR is finished, it just goes back to your T1 ISR.
     
    [edit]
    You might want to create a bit switch, clear it at the beginning of your main(), then in your T1 ISR

    while(bit_switch == 0);

    Set bit_switch = 1 in your INT1 ISR so you know you got there.
    [/edit]
    post edited by mpgmike - 2019/06/26 03:47:33

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #3
    renatochiara
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2016/05/28 00:18:02
    • Location: 0
    • Status: offline
    Re: nesting interrupt 2019/06/26 04:41:39 (permalink)
    0
    Hi mpgmike and thanks for your repsonse.
    The reason for delaying the Timer1 interrupt is to verify that the interrupt nesting is working properly.
    The firmware is in loop in the while (1) of the timer1 interrupt and when the int of the extrernal INT1 is triggered, the firmware should go to interrupt management INT1. For this I put a brekpoint at the instruction OSQEI1 = POS1CNTL;
    But it doesn't work and the firmware always remains closed in the while loop.
    do you have any idea where I'm wrong? do you have a sample code for nesting interrupt settings?
    Best regards.
    Renato
     

     
     
    #4
    mpgmike
    Super Member
    • Total Posts : 313
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: online
    Re: nesting interrupt 2019/06/26 07:49:22 (permalink)
    0
    I believe setting T1IP = 1 and INT1IP = 6 may be your issue.  You end up in a Priority=1 loop hoping a Priority=6 interrupt can get you out.  Try setting your INT1IP lower than your T1IP and see if it works.

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #5
    davekw7x
    Entropy++
    • Total Posts : 1827
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Second star on the right, straight on till morning
    • Status: offline
    Re: nesting interrupt 2019/06/26 09:16:28 (permalink)
    0
    renatochiara
    ...any idea...



    Without seeing your setup, we can only guess.
     
    Basic suggestion---without changing your code:
    • Show us your PPS assignment for INT1
     
    Question:
    • Does that pin have any analog functionality?  If so, did you enable Digital Input on that pin by clearing the appropriate bit of that port's ANSEL register?
    Enhanced suggestion---based on my testing methodology:
    I always make an initial test plan that does not depend on the debugger.  Otherwise, I always end up debugging the debugger
    Or, more usually, I end up debugging my expectations of the operation of the debugger and the IDE display.  Bottom line: I do preliminary testing with a production build (no debugger) running at full speed.
     
    So, for example in the INT1 ISR I toggle a pin to which I have attached an LED (and appropriate series resistor).  Unless the external signal is clean (no bouncing), there may be multiple toggles for every switch press and more upon releasing the switch.  If you repeate the press-release a few times you will surely (I claim) see some LED activity.
     
    I mean, I (almost) always have a way of debugging the application using UART I/O, so I make UART I/O among the very first things I validate during initial testing.  Right after verifying the clock frequency.
     
    Regards,

    Dave
    [Edit]
    mpgmike
    You end up in a Priority=1 loop hoping a Priority=6 interrupt can get you out.

    Well, that is exactly the point, right?  Make sure a higher priority interrupt can interrupt a lower priority interrupt.
    mpgmike
    Try setting your INT1IP lower than your T1IP and see if it works.

    But a lower priority interrupt can never interrupt a higher priority interrupt, so that will not (can not) work.
    The OP priority settings are correct for this test.
     
    Bottom line: Tested the OP code on my dsPIC33EP512MU810 except for the following:.
    SW1 was connected to RD6/RP70.  Made appropriate PPS function assignment and cleared bit 6 of ANSELD.
     
    Tested Production run: NOT with the Debugger.
    void __attribute__((__interrupt__, no_auto_psv)) _T1Interrupt(void)
    {
        // LED2 was initialized to zero (Off)
        LED2 ^= 1; // Stays On since it never leaves this ISR
        while (1) {        
        }
        IFS0bits.T1IF = 0;
    }

    void __attribute__((interrupt, no_auto_psv)) _INT1Interrupt(void)
    {
        LED1 ^= 1;
        IFS1bits.INT1IF = 0;
    }

    After resetting (or power-cycling) LED1 goes on and stays on.
    LED2 toggles one or more times every time I press/release the button.
    post edited by davekw7x - 2019/06/26 14:20:57

    Sometimes I just can't help myself...
    #6
    renatochiara
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2016/05/28 00:18:02
    • Location: 0
    • Status: offline
    Re: nesting interrupt 2019/06/27 08:00:20 (permalink)
    0
    Hi Dave.
    Tomorrow I should have time to do the tests you suggest. Then I'll tell you.
    Thanks.
    Renato
    #7
    renatochiara
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2016/05/28 00:18:02
    • Location: 0
    • Status: offline
    Re: nesting interrupt 2019/07/01 05:47:28 (permalink)
    0
    Hi Dave.
    it's OK.
    I have tested your suggestions with the interrupt of two timers.
    Timer1 with interrupt priority 1 (lower) and Timer 2 with interrupt priority 6 (higher)
    IPC0bits.T1IP = 1;     // Set Timer 1 Interrupt Priority Level
    IPC1bits.T2IP = 6;     // Set Timer 6 Interrupt Priority Level
     
    The interrupts routine are:
    void __attribute__((__interrupt__, no_auto_psv)) _T1Interrupt(void)
    {
          while (1)    {   }   
    IFS0bits.T1IF = 0;
    }   
     
    void __attribute__ ( ( interrupt, no_auto_psv ) ) _T2Interrupt (void)
    {
        LATDbits.LATD4 ^=1;        //toggle led
        IFS0bits.T2IF = 0;
    }
    the code is closed in the while loop (1) of the timer1, but exits the interrupt and manages the interrupt of the timer2.
     
    Thank you very much.
    Best regards
    Renato
    #8
    Aussie Susan
    Super Member
    • Total Posts : 3627
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: nesting interrupt 2019/07/01 19:13:53 (permalink)
    0
    What do you mean by "...exits the interrupt...": when the nested T2 interrupt completes you should return to the original T1 ISR code loop.
    Are you saying that this does NOT happen?
    Susan
    #9
    renatochiara
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2016/05/28 00:18:02
    • Location: 0
    • Status: offline
    Re: nesting interrupt 2019/07/01 23:16:02 (permalink)
    0
    Hi Susan,
    yes, when the nested T2 interrupt completes it should return to the original T1 ISR code loop.
    sorry for my bad English
    Thanks.
    Renato
    #10
    Jump to:
    © 2019 APG vNext Commercial Version 4.5