title: Why is Timer1 not counting up on PIC18?
body: <p>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 <a href="http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en027149" rel="nofollow">PIC18F87J11</a> with MPLAB C18.  </p>
  
  <p>I will share the code that seems relevant and upon request I will add more as needed. </p>
  
  <p><strong>Timer0</strong> Snippet Code ( From Header File)</p>
  
  <pre><code>#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 
  </code></pre>
  
  <p>Timer0 (From C File)</p>
  
  <pre><code>TMR_CON = 0b00000000 | CLOCK_DIVIDER_SETTING;
  TMR_IP = 1;
  TMR_IF = 0;
  TMR_IE = 1;
  TMR_ON = 1;
  </code></pre>
  
  <p>Timer0 (Where I increment the time)</p>
  
  <pre><code>if(TMR_IF)
          {
          printf("\r\n Passed here");
          timer_counter_high++; 
          }
  </code></pre>
  
  <p>Output: <strong>Passed here</strong></p>
  
  <hr>
  
  <p><strong>Timer1</strong> Snippet Code ( From Header File)</p>
  
  <pre><code>#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
  </code></pre>
  
  <p>Timer1 (From C File)</p>
  
  <pre><code>TMR_CON = 0b11101101 | CLOCK_DIVIDER_SETTING;
  TMR_IP = 1;
  TMR_IF = 0;
  TMR_IE = 1;
  TMR_ON = 1;
  </code></pre>
  
  <p>Timer1 (Where I increment the time)</p>
  
  <pre><code>   if(TMR_IF)
          {
          printf("\r\n Passed here");
          timer_counter_high++; 
          }
          else
          {
          printf("\r\n Did not come through");
          }
  </code></pre>
  
  <p>Output: <strong>Did not come through</strong></p>
  
  <p><strong>Edit:Added the CLOCK_DIVIDER_SETTING code as requested. This is being used for timer0 and timer1</strong></p>
  
  <pre><code>#elif(CLOCK_FREQ &lt;= 8000000)
          #define CLOCK_DIVIDER 32
          #define CLOCK_DIVIDER_SETTING 0x04
          #define SYMBOL_TO_TICK_RATE 8000000
  </code></pre>
  
  <p>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! </p>
  
  <p><strong>Edit 2:</strong> Some questions that I like to be answered</p>
  
  <p><strong>Q1</strong>: Can Timer1 still be used with the internal oscillator just like timer0? </p>
  
  <p><strong>Q2</strong>: How do you calculate the correct CLOCK_DIVIDER_SETTING for T1CON ? (Do I need it if T1SYNC is set and the prescaler?)</p>