Troubling understand what other interrupt firing high_isr besides TMR2 on PIC18F

Status
Not open for further replies.

sghosh

New Member
I having troubling understand what other interrupt firing high_isr besides TMR2 on PIC18f4550.

Way I detect it I set pin MY_DBG_PIN toggling everytime high_isr is activated, and from what I try to do, only TMR2 I have activated and nothing else.

My code looking like:

Code:
    #include <p18f4550.h>
    
    #define USE_OR_MASKS
    
    #include <pwm.h>
    #include <timers.h>
    
    #pragma config PLLDIV = 10
    #pragma config FOSC = ECPLLIO_EC
    
    #pragma config PWRT = OFF
    #pragma config BOR = OFF
    #pragma config MCLRE = ON
    #pragma config PBADEN = OFF
    #pragma config ICPRT = OFF
    #pragma config LVP = OFF
    #pragma config WDT = OFF,DEBUG=OFF
    
    /* Sets the PWM value on CCP1 to 50% duty cycle*/
    
    #define MY_DBG_PIN        LATBbits.LATB1 
    #define MY_DBG_PIN_TRIS   TRISBbits.TRISB1
    
    #pragma interrupt high_isr
    void high_isr (void)
    {
    	//* Comment to notice toggling of MY_DBG_PIN at 0.7Mhz
    	if(PIR1bits.TMR2IF)			// Timer 2 interrupt
    	{
    		MY_DBG_PIN = 0;
    
    		PIR1bits.TMR2IF = 0;
    	}
    	//*/
    	
    	// Are some other interrupts also firing? Why?
    	//MY_DBG_PIN = 0; // If uncomment, toggling at 0.7Mhz
    }
    
    #pragma code high_vector=0x08
    void interrupt_at_high_vector(void)
    {
    	MY_DBG_PIN = 1;
    	_asm GOTO high_isr _endasm
    }
    #pragma code /* return to the default code section */
    
    void main (void)
    {
    	TRISC=0;
    	OpenTimer2(TIMER_INT_ON | T2_PS_1_4 | T2_POST_1_16 );
    	OpenPWM1( 149 );
    	SetDCPWM1( 300 );
    
    	MY_DBG_PIN_TRIS = 0;    // make it an output 
    
     	PIE1bits.TMR2IE=1;           //enable Timer2 interrupt
        INTCONbits.PEIE=1;          //enable peripheral interrupts
        INTCONbits.GIE=1;           //enable glogal interrupts
    	INTCONbits.GIEH = 1; /* Enable global Interupt */
    
    	while(1)
    	{
    	}
    }
As can see, only TMR2 possibly fire ISR, but then do you notice high freq. update of debugging pin if you uncomment the line?

If I specify TMR2 interrupt flag in ISR and then toggle debugging pin, then expected update freq, as current active code is like.

What other thing can be triggering ISR and how I check that without checking flags of all interrupts?
 
You're not setting up your interrupt enable bits correctly.

Code:
   #include <p18f4550.h>
 
    #define USE_OR_MASKS
 
    #include <pwm.h>
    #include <timers.h>
 
    #pragma config PLLDIV = 10
    #pragma config FOSC = ECPLLIO_EC
 
    #pragma config PWRT = OFF
    #pragma config BOR = OFF
    #pragma config MCLRE = ON
    #pragma config PBADEN = OFF
    #pragma config ICPRT = OFF
    #pragma config LVP = OFF
    #pragma config WDT = OFF,DEBUG=OFF
 
    /* Sets the PWM value on CCP1 to 50% duty cycle*/
 
    #define MY_DBG_PIN        LATBbits.LATB1 
    #define MY_DBG_PIN_TRIS   TRISBbits.TRISB1
 
    #pragma interrupt high_isr
    void high_isr (void)
    {
    	//* Comment to notice toggling of MY_DBG_PIN at 0.7Mhz
    	if(PIR1bits.TMR2IF)			// Timer 2 interrupt
    	{
    		MY_DBG_PIN = 0;
 
    		PIR1bits.TMR2IF = 0;
    	}
    	//*/
 
    	// Are some other interrupts also firing? Why?
    	//MY_DBG_PIN = 0; // If uncomment, toggling at 0.7Mhz
    }
 
    #pragma code high_vector=0x08
    void interrupt_at_high_vector(void)
    {
    	MY_DBG_PIN = 1;
    	_asm GOTO high_isr _endasm
    }
    #pragma code /* return to the default code section */
 
    void main (void)
    {
    	TRISC=0;
    	OpenTimer2(TIMER_INT_ON | T2_PS_1_4 | T2_POST_1_16 );
    	OpenPWM1( 149 );
    	SetDCPWM1( 300 );
 
    	MY_DBG_PIN_TRIS = 0;    // make it an output 

        RCONbits.IPEN = 1;            //enable prioritized interrupts
        IPR1bits.TMR2IP = 1;         //assign high priority to TMR2 interrupt 
     	PIE1bits.TMR2IE=1;           //enable Timer2 interrupt
        INTCONbits.GIEL=0;           //disable low priority interrupts
        INTCONbits.GIEH = 1;         //enable high priority interrupts
 
    	while(1)
    	{
    	}
    }

Try this code and see what you end up with.

Now...you don't really need prioritized interrupts when dealing with a single interrupt. Prioritized interrupts are for when you have an interrupt that needs to be able to override another interrupt. You would set those interrupts as the high priority interrupts while making all other interrupts the low priority interrupt. This way those interrupts will be able to interrupt the low priority interrupt.
 
Last edited:

Hi Jon, thanking for your detailed answer!

I not trying to use prioritized interrupt, and I setup code to use PIC16F type compatible interrupt which I think uses high priority interrupt by default?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…