Interrupts no longer being called.

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Can anyone see what the heck I am doing wrong? This code for Timer1 interrupt used to work now it no longer interrupts :

The chip is a Pic 18F27J53 running 8MHZ internal OSC.


Rich (BB code):
void main()
{
    TRISBbits.TRISB3 = 0;
    LATBbits.LATB3 = 0;

    // 8MHZ  for 18F27J53
    OSCCONbits.IRCF0 = 1;  
    OSCCONbits.IRCF1 = 1;
    OSCCONbits.IRCF2 = 1;

    // Set up global interrupts
    RCONbits.IPEN = 1;              // Enable priority levels on interrupts
    INTCONbits.GIEL = 1;            // Low priority interrupts allowed
 
    
    IPR1bits.TMR1IP = 0;    // Timer1 is low priority interrupt  
    PIE1bits.TMR1IE = 1;    // Enable interrupts for Timer 1 
    
    //Timer1 Registers Prescaler= 1 - TMR1 Preset = 65475 - Freq = 32786.89 Hz - Period = 0.000030 seconds
    T1CONbits.T1CKPS1 = 0;   // bits 5-4  Prescaler Rate Select bits
    T1CONbits.T1CKPS0 = 0;   // bit 4
    T1CONbits.T1OSCEN = 1;   // bit 3 Timer1 Oscillator Enable Control bit 1 = on
    T1CONbits.NOT_T1SYNC = 1;    // bit 2 Timer1 External Clock Input Synchronization Control bit...1 = Do not synchronize external clock input
    T1CONbits.TMR1CS = 0;    // bit 1 Timer1 Clock Source Select bit...0 = Internal clock (FOSC/4)
    TMR1H = 255;             // preset for timer1 MSB register
    TMR1L = 195;             // preset for timer1 LSB register
    T1CONbits.TMR1ON = 1;    // bit 0 enables timer
    

    while(1);


}
Here is the interrupt routine:

Rich (BB code):
void InterruptServiceLow(void);


// Low priority interrupt vector
#pragma code InterruptVectorLow = 0x18
void InterruptVectorLow (void)
{
  _asm
    goto InterruptServiceLow //jump to interrupt routine
  _endasm
}

/** D E C L A R A T I O N S *******************************************/
#pragma code    // declare executable instructions


#pragma interruptlow InterruptServiceLow
void InterruptServiceLow(void)
{
    int i;
   
    i=1;    

    // Check for Timer1 Overflow Interrupt
    if  (PIR1bits.TMR1IF)
    {        
        i = 1;
        LATBbits.LATB3 =~ LATBbits.LATB3;
        TMR1H = 255;             // preset for timer1 MSB register
        TMR1L = 195;             // preset for timer1 LSB register
        PIR1bits.TMR1IF = 0;          // clear flag        
    }

}
I set a breakpoint in on i=1 and it never breaks there. Plus LATB3 is not being toggled though I can toggle in in a loop in my main code.
 
Last edited:

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
BTW I know the timer is running because I have additional code that enables and displays an RTC output and the clock is indeed being updated though not accurate at all because Timer 1 interrupt is not pre loading.

And yes I plan to add an external 32.768K xtal but just want to get it working on the internal rc for now.
 

nsaspook

Joined Aug 27, 2009
13,265
Have you tried moving the timer ISR configs after the timer configuration?


Rich (BB code):
IPR1bits.TMR1IP = 0; 
PIE1bits.TMR1IE = 1;
INTCONbits.GIEL = 1;

while(1);
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Have you tried moving the timer ISR configs after the timer configuration?


Rich (BB code):
IPR1bits.TMR1IP = 0; 
PIE1bits.TMR1IE = 1;
INTCONbits.GIEL = 1;

while(1);
Tried that and it doesn't work. I have never had to do that before.

I'm going to build a new project with just some test code for the timer interrupt.

Is there any chance something happened to the Pic where the interrupts are permanently disabled but everything else works???
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
I'm not seeing the Global Interrupt Enable bit, INTCON.7, getting set. Is it in there somewhere?
Oh rats! I can't believe I did not see that! Thanks!

But now I am back to my original problem. Something (with my full code) is turning interrupts back off again. I was messing with then code to figure that one out and accidentally removed the Global interrupt setting.

Now I need to go back and figure out what is turning off interrupts. I think it is the UART library.
 

nsaspook

Joined Aug 27, 2009
13,265
It's always the small things that get you. One of things I really like about MPLABX is the version control modules that keep track of all code changes.
Making a standard framework of subroutines for processor types that splits the module configuration bits from the interrupt configuration bits helps keep things organized.
 
Top