Priority Interrupt settings PIC18F4550, running three timers - Page 1
Forum section: electronics / beginners

author: Vindhyachal.takniki
author_rank: Frequent Contributor
timestamp: April 29, 2016, 04:16:50 pm
content: I am using PIC18F4550 with MPBALX IDE V2.26, Xc8 V1.32.I have to run three timers. I am using three timers. I have kept osc freq = 4Mhz, so that all timers have clock of 1Mhz.Timer0: Used for delay loops, one shot. Delay produced: 500us,1000us,10ms,50msTimer1: General purpose timer. Run continuously, generate 10ms interrupts.Timer3: Generate configurable interrupt. Timer value varies from 50us-62500us.Timer3 is highest priority interrupt. It runs only when it is required otherwise off. If any other timer interrupt is being serviced, then they should be interrupted by this higher priority interrupt.So Timer3 should me made higher priority & other timers should be at lower priorityIn PIC18F4550 how to configure two interrupts with higher & lower priority.I have tried this but it didn't work.(http://www.xargs.com/pic/c-faq.html#c18isr)Then I have tried this:http://microchip.wikidot.com/faq:31Configured timer0 interrupt to lower priority & if isr have keyword "low_priority", then control never goes in it. However if I remove this keyword then control goes into isr.Now how to configure code for higher priority for timer3.Code:void interrupt isr(void){/* wait timer isr */if(INTCONbits.TMR0IF){/* stop timer */T0CONbits.TMR0ON = 0U;INTCONbits.TMR0IF = 0U;g_wait_timer_flag = 1U;}/* general timer isr */if(PIR1bits.TMR1IF){/* stop, reload & restart timer */T1CONbits.TMR1ON = 0U;PIR1bits.TMR1IF = 0U;TMR1H = GEN_TIM_TH0;TMR1L = GEN_TIM_TL0;T1CONbits.TMR1ON = 1U;LATBbits.LATB1 = !LATBbits.LATB1;}} /* isr ends here */void initialize_wait_timer(void){/* T0CON */T0CONbits.TMR0ON = 0U; /* stop timer */T0CONbits.T08BIT = 0U; /* 16 bit */T0CONbits.T0CS = 0U; /* internal clock */T0CONbits.T0SE = 0U;T0CONbits.PSA = 1U; /* PSA bypass */T0CONbits.T0PS = 0U; /* /2 *//* clear timer counts */TMR0H = 0U; /* clear timer register */TMR0L = 0U;/* int settins */INTCONbits.TMR0IF = 0U; /* clear overflow flag */INTCONbits.TMR0IE = 1U; /* enable int */INTCON2bits.TMR0IP = 0U; /* low priority */INTCONbits.GIE_GIEH = 1U; /* enable global bit */INTCONbits.PEIE_GIEL = 1U;/* write TL & TH value */TMR0H = 0xFE;TMR0L = 0x0c;T0CONbits.TMR0ON = 1U;while( 0U == g_wait_timer_flag );} /* function ends here */void initialize_general_timer(void){/* T1CON */T1CONbits.TMR1ON = 0U; /* stop timer */T1CONbits.RD16 = 1U; /* one sixteen but write */T1CONbits.T1RUN = 0U;T1CONbits.T1CKPS = 0U;T1CONbits.T1OSCEN = 0U;T1CONbits.nT1SYNC = 1U;T1CONbits.TMR1CS = 0U;/* write tiemr counts */TMR1H = GEN_TIM_TH0;TMR1L = GEN_TIM_TL0;/* int settins */PIR1bits.TMR1IF = 0U;PIE1bits.TMR1IE = 1U;IPR1bits.TMR1IP = 0U;INTCONbits.GIE_GIEH = 1U; /* enable global bit */INTCONbits.PEIE_GIEL = 1U;/* start timer */T1CONbits.TMR1ON = 1U;} /* function ends here */

author: rstofer
author_rank: Super Contributor
timestamp: April 29, 2016, 06:20:24 pm
content: I don't see any of the #pragma statements. I would start with the approach used in your first linked document and make up a test case. I would use the template exactly as given.You can't have much more than the GOTO statement at interrupt vector 0x0008 before the code runs into the other vector at 0x0018. The template has just the GOTO statement at each vector with the actual handler being placed elsewhere.Note that statements about additional overhead for the low priority interrupts. This may matter.Look at the hex file and see if the vectors are filled out correctly. Look at the desination of the GOTO statement and see if it is pointing to the proper handler.

author: Vindhyachal.takniki
author_rank: Frequent Contributor
timestamp: April 30, 2016, 02:27:36 am
content: Thanks get it working