Initially I had Timer0 working fine during the run mode. The only problem is when the device goes to sleep mode, Timer0 stops counting up until awaken. In the datasheet it says to use Timer1 to be able to monitor time during sleep mode. I modified timer0 existing code to timer1 new configurations, the other code is pretty much the same. However, there is something I might have missed that is different about timer1 than timer0, since the timer1 is not counting up at all. The PIC I'm using is PIC18F87J11 with MPLAB C18.
I will share the code that seems relevant and upon request I will add more as needed.
Timer0 Snippet Code ( From Header File)
#define TMR_IF INTCONbits.TMR0IF
#define TMR_IE INTCONbits.TMR0IE
#define TMR_IP INTCON2bits.TMR0IP
#define TMR_ON T0CONbits.TMR0ON
#define TMR_CON T0CON
#define TMR_L TMR0L
#define TMR_H TMR0H
Timer0 (From C File)
TMR_CON = 0b00000000 | CLOCK_DIVIDER_SETTING;
TMR_IP = 1;
TMR_IF = 0;
TMR_IE = 1;
TMR_ON = 1;
Timer0 (Where I increment the time)
if(TMR_IF)
{
printf("\r\n Passed here");
timer_counter_high++;
}
Output: Passed here
Timer1 Snippet Code ( From Header File)
#define TMR_IF PIR1bits.TMR1IF
#define TMR_IE PIE1bits.TMR1IE
#define TMR_IP IPR1bits.TMR1IP
#define TMR_ON T1CONbits.TMR1ON
#define TMR_CON T1CON
#define TMR_L TMR1L
#define TMR_H TMR1H
Timer1 (From C File)
TMR_CON = 0b11101101 | CLOCK_DIVIDER_SETTING;
TMR_IP = 1;
TMR_IF = 0;
TMR_IE = 1;
TMR_ON = 1;
Timer1 (Where I increment the time)
if(TMR_IF)
{
printf("\r\n Passed here");
timer_counter_high++;
}
else
{
printf("\r\n Did not come through");
}
Output: Did not come through
Edit:Added the CLOCK_DIVIDER_SETTING code as requested. This is being used for timer0 and timer1
#elif(CLOCK_FREQ <= 8000000)
#define CLOCK_DIVIDER 32
#define CLOCK_DIVIDER_SETTING 0x04
#define SYMBOL_TO_TICK_RATE 8000000
I still did not put the device on sleep mode to test timer1 in that condition, first I have to figure out why timer1 is not counting up during the run mode. I will appreciate any help or ideas related to my problem, Thanks!
Edit 2: Some questions that I like to be answered
Q1: Can Timer1 still be used with the internal oscillator just like timer0?
Q2: How do you calculate the correct CLOCK_DIVIDER_SETTING for T1CON ? (Do I need it if T1SYNC is set and the prescaler?)