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,50ms
Timer1: 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 priority
In 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:31
Configured 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. Haven't added timer3 in yet
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,50ms
Timer1: 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 priority
In 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:31
Configured 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. Haven't added timer3 in yet
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 */