user37456: I am working on a project which requires use of 16bit timer . I am using Arduino Uno (Atmega 328p) board and Timer_1 (16 bit timer ) in Overflow mode. i want to use 1024 prescaler settings. 
According to the datasheet of the controller i have to set [b]CS10 and CS12[/b] bits to use 1024 prescaler but the problem is OverFlow interrupt routine is never fired when 1024 or 256 prescaler is selected .
The Following code works just fine with Prescaler set to 8 or 64.
#include <inttypes.h> 

volatile uint8_t sCount = 0;

void setup()
{
      Timer_one_16_init(); // configure the timer 

      pinMode(13,OUTPUT);

}

void loop()
{
    // do nothing 
}

void Timer_one_16_init(){

    TCCR1A = 0;

    // set the pre-scaler to 1024 (slowest)

    TCCR1B |= (1<<CS12)|(1<<CS10);

    // set the bottom / starting value

    TCNT1 = 0x00;


    // set Overflow interrupt

    TIMSK1 |= (1<<TOIE1);


    // enable global interrupt 
    sei();


}


ISR(TIMER1_OVF_vect){

    sCount++;

    if (sCount == 60)
    {
        digitalWrite(13,!digitalRead(13));
        sCount = 0;

    }

}

i have no idea why this is happening. i have done everything which is given in the datasheet . 
Am i doing something wrong ?
Thanks in advance 

user7508: You must write the clock-select bits to the correct value. The simplest
way to do it is to write the proper configuration into the TCCR1B
register:
TCCR1B = (1<<CS12)|(1<<CS10);

In your program, you used |= instead of =. This doesn't write the
bits appropriately: it only sets (writes to 1) the bits CS12 and
CS10 but doesn't clear CS11. Since the Arduino core library sets the
prescaler to 64 (CS11 and CS10 set), you end up with all the
clock-select bits sets, in which case the timer is clocked by an
external signal on the T1 pin. Not what you want.

Edit: Judging from the comments, it appears that at least dannyf did
not understand my answer, I am therefore adding a clarification. There
are two scenarios when you may want to tweak the control registers of a
peripheral:

The peripheral is normally controlled by the Arduino core library,
and you want to use it through that library. Typical case: you want
to use a timer to analogWrite(), or the ADC to analogRead(), but
you want to clock the peripheral at a frequency which is not the
core's default.
You want to use a peripheral directly rather than through the Arduino
core. Either you are going to “take it over” from the core, or it's a
peripheral the core doesn't use in the first place.

In the first case, you should only touch those bits of the control
registers that you must change. The other bits should be left alone, at
whatever values the core has set them to. This is the approach of
dannyf's answer.
In the second case, it is wiser to not rely on the core's default
setting, and instead write every single bit of the control registers
to the values appropriate for your application. This is the scenario of
the original question, and the solution proposed in my answer.
For the particular case of this question, the TCCR1B register would
be set to: ICNC1 = 0†, ICES1 = 0, reserved bit = 0, WGM13
= 0, WGM12 = 0, CS12 = 1, CS11 = 0 and CS10 = 1. Combining those bits
together gives the setting TCCR1B = 0x05;. However, for readability
reasons, I prefer to write that value (1<<CS12)|(1<<CS10), as in the
question and in my original answer. Some people may prefer to explicitly
write every bit, like
TCCR1B = (0<<ICNC1) | (0<<ICES1) | (0<<5)    | (0<<WGM13)
       | (0<<WGM12) | (1<<CS12)  | (0<<CS11) | (1<<CS10);

Whichever version you prefer is up to you. I personally don't find this
latter version any easier to read.
†: The values of ICNC1 and ICES1 are actually
irrelevant in this case.

37456: <p>I am working on a project which requires use of 16bit timer . I am using Arduino Uno (Atmega 328p) board and Timer_1 (16 bit timer ) in Overflow mode. i want to use 1024 prescaler settings. </p>

<p>According to the datasheet of the controller i have to set [b]CS10 and CS12[/b] bits to use 1024 prescaler but the problem is OverFlow interrupt routine is never fired when 1024 or 256 prescaler is selected .</p>

<p>The Following code works just fine with Prescaler set to 8 or 64.</p>

<pre><code>#include &lt;inttypes.h&gt; 

volatile uint8_t sCount = 0;

void setup()
{
      Timer_one_16_init(); // configure the timer 

      pinMode(13,OUTPUT);

}

void loop()
{
    // do nothing 
}

void Timer_one_16_init(){

    TCCR1A = 0;

    // set the pre-scaler to 1024 (slowest)

    TCCR1B |= (1&lt;&lt;CS12)|(1&lt;&lt;CS10);

    // set the bottom / starting value

    TCNT1 = 0x00;


    // set Overflow interrupt

    TIMSK1 |= (1&lt;&lt;TOIE1);


    // enable global interrupt 
    sei();


}


ISR(TIMER1_OVF_vect){

    sCount++;

    if (sCount == 60)
    {
        digitalWrite(13,!digitalRead(13));
        sCount = 0;

    }

}
</code></pre>

<p>i have no idea why this is happening. i have done everything which is given in the datasheet . </p>

<p>Am i doing something wrong ?</p>

<p>Thanks in advance </p>
 7508: <p>You must write the clock-select bits to the correct value. The simplest
way to do it is to write the proper configuration into the <code>TCCR1B</code>
register:</p>

<pre><code>TCCR1B = (1&lt;&lt;CS12)|(1&lt;&lt;CS10);
</code></pre>

<p>In your program, you used <code>|=</code> instead of <code>=</code>. This doesn't write the
bits appropriately: it only sets (writes to 1) the bits <code>CS12</code> and
<code>CS10</code> but doesn't clear <code>CS11</code>. Since the Arduino core library sets the
prescaler to 64 (<code>CS11</code> and <code>CS10</code> set), you end up with all the
clock-select bits sets, in which case the timer is clocked by an
external signal on the T1 pin. Not what you want.</p>

<hr>

<p><strong>Edit</strong>: Judging from the comments, it appears that at least dannyf did
not understand my answer, I am therefore adding a clarification. There
are two scenarios when you may want to tweak the control registers of a
peripheral:</p>

<ol>
<li><p>The peripheral is normally controlled by the Arduino core library,
and you want to use it through that library. Typical case: you want
to use a timer to <code>analogWrite()</code>, or the ADC to <code>analogRead()</code>, but
you want to clock the peripheral at a frequency which is not the
core's default.</p></li>
<li><p>You want to use a peripheral directly rather than through the Arduino
core. Either you are going to “take it over” from the core, or it's a
peripheral the core doesn't use in the first place.</p></li>
</ol>

<p>In the first case, you should only touch those bits of the control
registers that you must change. The other bits should be left alone, at
whatever values the core has set them to. This is the approach of
dannyf's answer.</p>

<p>In the second case, it is wiser to <em>not</em> rely on the core's default
setting, and instead write <em>every single bit</em> of the control registers
to the values appropriate for your application. This is the scenario of
the original question, and the solution proposed in my answer.</p>

<p>For the particular case of this question, the <code>TCCR1B</code> register would
be set to: ICNC1 = 0<sup>†</sup>, ICES1 = 0, reserved bit = 0, WGM13
= 0, WGM12 = 0, CS12 = 1, CS11 = 0 and CS10 = 1. Combining those bits
together gives the setting <code>TCCR1B = 0x05;</code>. However, for readability
reasons, I prefer to write that value <code>(1&lt;&lt;CS12)|(1&lt;&lt;CS10)</code>, as in the
question and in my original answer. Some people may prefer to explicitly
write every bit, like</p>

<pre><code>TCCR1B = (0&lt;&lt;ICNC1) | (0&lt;&lt;ICES1) | (0&lt;&lt;5)    | (0&lt;&lt;WGM13)
       | (0&lt;&lt;WGM12) | (1&lt;&lt;CS12)  | (0&lt;&lt;CS11) | (1&lt;&lt;CS10);
</code></pre>

<p>Whichever version you prefer is up to you. I personally don't find this
latter version any easier to read.</p>

<p><sup>†</sup>: The values of <code>ICNC1</code> and <code>ICES1</code> are actually
irrelevant in this case.</p>
