Hot!No jump into ISR after Flag is set

Author
TK50
New Member
  • Total Posts : 20
  • Reward points : 0
  • Joined: 2018/01/05 00:32:20
  • Location: 0
  • Status: offline
2018/01/31 05:28:19 (permalink)
0

No jump into ISR after Flag is set

Hello,
 
i having a trouble, that I cannot solve this.
For example i want Timer1 Overflow Interrupt or External Interrupt, the Flags gets high but the compiler doesnt jump into the ISR!
 
uint8_t External_Interrupt_Init(void)
{
    /* Set Port RB1 = INTB and RA1 = MON as digital Inputs */
    TRISAbits.TRISA1 = 1;
    TRISBbits.TRISB1 = 1;
    ANSAbits.ANSA1 = 0;
    ANSBbits.ANSB1 = 0;
    
    /* Enable Pulldown for RB1 */
    //IOCPUBbits.IOCPUB1 = 1;
    
    /* Enable Pullup for RA1 */
    IOCPUAbits.IOCPUA1 = 1;

    /* Assign External Interrupt 1 to Port RA1 */
    RPINR0bits.INT1R = 27;
    
    /* Assign External Interrupt 2 to Port RB1 */
    RPINR1bits.INT2R = 1;

    /* For External Interrupt 1 and 2, Interrupt should occur on negative edge */
    External_Interrupt1_NEG;
    External_Interrupt2_NEG;

    /* Enable External Interrupt 1 and 2 */
    IEC1bits.INT1IE = 1;
    IEC1bits.INT2IE = 1;
    /* Delete Flag */
    IFS1bits.INT2IF = 0;
    
    return EXT_INIT_OK;
}

uint8_t Timer1_Init(void)
{
    /* Stop Timer */
    TIMER1_STOP;
    
    /* Continue Module in Idle Mode */
    T1CONbits.TSIDL = 0;
    
    /* Delete Timer Counter content */
    TIMER1_RESET;
    
    /* Internal Clock Source */
    T1CONbits.TCS = 0;
    
    /* Clock Prescaler for 8ms */
    T1CONbits.TCKPS = 2;
    
    /* Enable Timer1 Interrupt */
    IEC0bits.T1IE = 1;
    
    /* Set Priority Level to 6 */
    IPC0bits.T1IP = 6;
    
    /* Reset Flag */
    IFS0bits.T1IF = 0;
    
    /* Start Timer */
    TIMER1_START;
    
    return TIMER1_INIT_OK;
 
void __attribute__((__Interrupt__)) _INT2Interrupt()
{
if(IFS1bits.INT2IF == 1)
{
/* Delete Flag */
IFS1bits.INT2IF = 0;
LATAbits.LATA0 = 1;
}
}
 
void __attribute__((__Interrupt__)) _T1Interrupt()
{
if(IFS0bits.T1IF == 1)
{
/* Delete Flag */
IFS0bits.T1IF = 0;
LATAbits.LATA0 = 1;
}
}

}

 
Global Interrupts are enabled and nested disabled.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
#1

13 Replies Related Threads

    Sobottech
    Super Member
    • Total Posts : 192
    • Reward points : 0
    • Joined: 2015/12/02 03:32:17
    • Location: 0
    • Status: offline
    Re: No jump into ISR after Flag is set 2018/01/31 05:42:13 (permalink)
    5 (1)
    Hm, have you started for example Timer1?
     
    T1CONbits.TON = 1;// Start Timer
     
     

    void __attribute__((__Interrupt__)) _T1Interrupt()
    {
    if(IFS0bits.T1IF == 1) //there is no need to test that, that interruptroutine is just for T1interrupt
    {
    /* Delete Flag */
    IFS0bits.T1IF = 0;
    LATAbits.LATA0 = 1;
    }
    }

     
    Try:

    void __attribute__((__interrupt__, no_auto_psv)) _T1Interrupt(void)
    {
    ..
    }

    post edited by Sobottech - 2018/01/31 05:45:37
    #2
    TK50
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2018/01/05 00:32:20
    • Location: 0
    • Status: offline
    Re: No jump into ISR after Flag is set 2018/01/31 05:44:13 (permalink)
    0
    Yes. TIMER1_START is T1CONbits.TON = 1
    And TIMER1_STOP is T1CONbits.TON = 0
    TIMER1_RESET    TMR1 = 0
    #3
    mbrinks
    Starting Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2011/05/03 04:57:32
    • Location: Denmark
    • Status: offline
    Re: No jump into ISR after Flag is set 2018/01/31 09:04:11 (permalink)
    5 (3)
    In the posted code the interrupt functions are declared inside Timer1_Init() function, so they become local functions.
    I think you need to declare them globally in order for the linker to place the address of the functions in the IVT (Interrupt Vector Table).
     
    Try moving the "}" at the end of your code up immediately after the return TIMER1_INIT_OK statement.
     
    Best regards,
    Michael Brinks
    #4
    TK50
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2018/01/05 00:32:20
    • Location: 0
    • Status: offline
    Re: No jump into ISR after Flag is set 2018/01/31 10:59:51 (permalink)
    0
    The Interrupt Functions are global. I didnt copied it well to here.
     
     
    #5
    rodims
    Super Member
    • Total Posts : 1067
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: online
    Re: No jump into ISR after Flag is set 2018/01/31 11:14:34 (permalink)
    4.5 (2)
    May be you copy again your real source code, including enabling / disabling your interrupts.
    And what about your interrupt priorities settings ?
    Which PIC24 ?
     
    #6
    Sobottech
    Super Member
    • Total Posts : 192
    • Reward points : 0
    • Joined: 2015/12/02 03:32:17
    • Location: 0
    • Status: offline
    Re: No jump into ISR after Flag is set 2018/01/31 13:05:15 (permalink)
    5 (1)
    Hm,
    yes, hard to tell what is missing/wrong without complete code.
    Perhaps priority setting is missing?
     
    IPC0bits.T1IP = 1;// Set Timer Interrupt Priority Level 0 disabled 7 highest
    #7
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 1916
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: No jump into ISR after Flag is set 2018/01/31 14:44:42 (permalink)
    0
    You need to set the Period.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #8
    Sobottech
    Super Member
    • Total Posts : 192
    • Reward points : 0
    • Joined: 2015/12/02 03:32:17
    • Location: 0
    • Status: offline
    Re: No jump into ISR after Flag is set 2018/01/31 14:52:38 (permalink)
    0
    Uh, well, yes, you are setting the priority.
     
     /* Set Priority Level to 6 */
        IPC0bits.T1IP = 6;

    //you can set period like this:
    PR1 = 32767; // Load the period value 32767

    #9
    Aussie Susan
    Super Member
    • Total Posts : 3044
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: No jump into ISR after Flag is set 2018/01/31 18:51:01 (permalink)
    5 (1)
    What is the actual device you are using - there are differences and what applies to one device may not apply to another.
    I have (almost) never needed to adjust the interrupt priorities - the default of 4 normally fine. Why do you need to alter the priorities?
    Susan
     
    #10
    TK50
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2018/01/05 00:32:20
    • Location: 0
    • Status: offline
    Re: No jump into ISR after Flag is set 2018/01/31 23:21:46 (permalink)
    0
    Its a PIC24FJ256GA705.
     
    I made a test project, with only the timer 1 interrupt.
     
    When I am debugging, I am only one time in the ISR after that I am stucking at the main loop.
    I noticed, that the flag is getting high again before the timer getting overflow.
     
    I added an attachement of the SFR from Timer 1
     

     
     
     
    #include <xc.h>
     
     
     
    /*
    Main application
    */
     
     
     
    // FSEC
    #pragma config BWRP = OFF // Boot Segment Write-Protect bit (Boot Segment may be written)
    #pragma config BSS = DISABLED // Boot Segment Code-Protect Level bits (No Protection (other than BWRP))
    #pragma config BSEN = OFF // Boot Segment Control bit (No Boot Segment)
    #pragma config GWRP = OFF // General Segment Write-Protect bit (General Segment may be written)
    #pragma config GSS = DISABLED // General Segment Code-Protect Level bits (No Protection (other than GWRP))
    #pragma config CWRP = OFF // Configuration Segment Write-Protect bit (Configuration Segment may be written)
    #pragma config CSS = DISABLED // Configuration Segment Code-Protect Level bits (No Protection (other than CWRP))
    #pragma config AIVTDIS = OFF // Alternate Interrupt Vector Table bit (Disabled AIVT)
     
     
     
    // FBSLIM
    #pragma config BSLIM = 0x1FFF // Boot Segment Flash Page Address Limit bits (Boot Segment Flash page address limit)
     
     
     
    // FSIGN
     
     
     
    // FOSCSEL
    #pragma config FNOSC = FRCPLL // Oscillator Source Selection (Fast RC Oscillator with divide-by-N with PLL module (FRCPLL) )
    #pragma config PLLMODE = PLL96DIV2 // PLL Mode Selection (96 MHz PLL. Oscillator input is divided by 2 (8 MHz input))
    #pragma config IESO = ON // Two-speed Oscillator Start-up Enable bit (Start up device with FRC, then switch to user-selected oscillator source)
     
     
     
    // FOSC
    #pragma config POSCMD = NONE // Primary Oscillator Mode Select bits (Primary Oscillator disabled)
    #pragma config OSCIOFCN = OFF // OSC2 Pin Function bit (OSC2 is clock output)
    #pragma config SOSCSEL = ON // SOSC Power Selection Configuration bits (SOSC is used in crystal (SOSCI/SOSCO) mode)
    #pragma config PLLSS = PLL_FRC // PLL Secondary Selection Configuration bit (PLL is fed by the on-chip Fast RC (FRC) oscillator)
    #pragma config IOL1WAY = ON // Peripheral pin select configuration bit (Allow only one reconfiguration)
    #pragma config FCKSM = CSDCMD // Clock Switching Mode bits (Both Clock switching and Fail-safe Clock Monitor are disabled)
     
     
     
    // FWDT
    #pragma config WDTPS = PS32768 // Watchdog Timer Postscaler bits (1:32,768)
    #pragma config FWPSA = PR128 // Watchdog Timer Prescaler bit (1:128)
    #pragma config FWDTEN = OFF // Watchdog Timer Enable bits (WDT and SWDTEN disabled)
    #pragma config WINDIS = OFF // Watchdog Timer Window Enable bit (Watchdog Timer in Non-Window mode)
    #pragma config WDTWIN = WIN25 // Watchdog Timer Window Select bits (WDT Window is 25% of WDT period)
    #pragma config WDTCMX = WDTCLK // WDT MUX Source Select bits (WDT clock source is determined by the WDTCLK Configuration bits)
    #pragma config WDTCLK = LPRC // WDT Clock Source Select bits (WDT uses LPRC)
     
     
     
    // FPOR
    #pragma config BOREN = ON // Brown Out Enable bit (Brown Out Enable Bit)
    #pragma config LPCFG = OFF // Low power regulator control (No Retention Sleep)
    #pragma config DNVPEN = ENABLE // Downside Voltage Protection Enable bit (Downside protection enabled using ZPBOR when BOR is inactive)
     
     
     
    // FICD
    #pragma config ICS = PGD2 // ICD Communication Channel Select bits (Communicate on PGEC2 and PGED2)
    #pragma config JTAGEN = ON // JTAG Enable bit (JTAG is enabled)
     
     
     
    // FDEVOPT1
    #pragma config ALTCMPI = DISABLE // Alternate Comparator Input Enable bit (C1INC, C2INC, and C3INC are on their standard pin locations)
    #pragma config TMPRPIN = OFF // Tamper Pin Enable bit (TMPRN pin function is disabled)
    #pragma config SOSCHP = ON // SOSC High Power Enable bit (valid only when SOSCSEL = 1 (Enable SOSC high power mode (default))
    #pragma config ALTI2C1 = ALTI2CDIS // Alternate I2C pin Location (ASDA1 and ASCL1 on RB5 and RB6)
     
     
     
    // #pragma config statements should precede project file includes.
    // Use project enums instead of #define for ON and OFF.
     
     
     

    void __attribute__((Interrupt,no_auto_psv)) _T1Interrupt(void)
    {
    /* Delete Flag */
    IFS0bits.T1IF = 0;
    TMR1 = 0;
    }
     
     
     
    int main(void)
    {
    // initialize the device
     
     
     

    /* Stop Timer */
    T1CONbits.TON = 0;

    /* Continue Module in Idle Mode */
    T1CONbits.TSIDL = 0;

    /* Delete Timer Counter content */
    TMR1 = 0;
    PR1 = 0xFFFF;

    /* Internal Clock Source */
    T1CONbits.TCS = 0;

    /* Clock Prescaler to 8ms */
    T1CONbits.TCKPS = 2;

    /* Enable Timer1 Interrupt */
    IEC0bits.T1IE = 1;

    /* Set Priority Level to 6 */
    IPC0bits.T1IP = 6; //With or without, the problems are the same
     
     
     

    /* Reset Flag */
    IFS0bits.T1IF = 0;

    /* Start Timer */
    T1CONbits.TON = 1;
    INTCON2bits.GIE = 1

    while (1)
    {
    // Add your application code
    }
     
     
     
    return 1;
    }
     
     
     

     
     
    post edited by TK50 - 2018/01/31 23:41:31

    Attached Image(s)

    #11
    TK50
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2018/01/05 00:32:20
    • Location: 0
    • Status: offline
    Re: No jump into ISR after Flag is set 2018/02/01 02:05:37 (permalink)
    0
    Hahahaha.
    I found that error :)
     
    void __attribute__((Interrupt,no_auto_psv)) _T1Interrupt(void)

    The Letter I in Interrupt has to be small, like interrupt. >.<
    #12
    rodims
    Super Member
    • Total Posts : 1067
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: online
    Re: No jump into ISR after Flag is set 2018/02/01 04:12:14 (permalink)
    0
    TK50Its a PIC24FJ256GA705.
     I made a test project, with only the timer 1 interrupt.
     
    When I am debugging, I am only one time in the ISR after that I am stucking at the main loop.
    I noticed, that the flag is getting high again before the timer getting overflow.

     
    No idea, how this can be, but good to hear that it works now.
    It seems that Sobotech (+1) already corrected this spelling error in the very first answer.
    #13
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 1916
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: No jump into ISR after Flag is set 2018/02/01 05:04:03 (permalink)
    0
    TMR1=0  is not needed.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #14
    Jump to:
    © 2018 APG vNext Commercial Version 4.5