user27427: I'm trying to use the timer registers to do some timing on my Arduino Mega 2560.
The output of the following code confuses me:
void setup ()
{
    // Set up serial connection
    Serial.begin(9600);
    while (!Serial) {}

    // Print control registers of timer 1
    Serial.println(TCCR1A); // Outputs 1
    Serial.println(TCCR1B); // Outputs 3
}

void loop () {}

Why is TCCR1A equal to 1 and TCCR1B equal to 3? The documentation of the chip says the initial values of the registers are zero. I could of course set them to zero, but I want to understand why it works like this. The values are the same for the other 16-bit timers (3, 4 and 5).

user4143: The Arduino core does things at startup. One of those things is to configure the timers ready for PWM operation.
Here's the relevant bits from init() in wiring.c:
    // set timer 1 prescale factor to 64
    sbi(TCCR1B, CS11);
#if F_CPU >= 8000000L
    sbi(TCCR1B, CS10);
#endif

#if defined(TCCR1A) && defined(WGM10)
    sbi(TCCR1A, WGM10);
#endif


27427: <p>I'm trying to use the timer registers to do some timing on my Arduino Mega 2560.</p>

<p>The output of the following code confuses me:</p>

<pre><code>void setup ()
{
    // Set up serial connection
    Serial.begin(9600);
    while (!Serial) {}

    // Print control registers of timer 1
    Serial.println(TCCR1A); // Outputs 1
    Serial.println(TCCR1B); // Outputs 3
}

void loop () {}
</code></pre>

<p>Why is <code>TCCR1A</code> equal to <code>1</code> and <code>TCCR1B</code> equal to <code>3</code>? The documentation of the chip says the initial values of the registers are zero. I could of course set them to zero, but I want to understand why it works like this. The values are the same for the other 16-bit timers (3, 4 and 5).</p>
 4143: <p>The Arduino core does things at startup. One of those things is to configure the timers ready for PWM operation.</p>

<p>Here's the relevant bits from <code>init()</code> in <code>wiring.c</code>:</p>

<pre><code>    // set timer 1 prescale factor to 64
    sbi(TCCR1B, CS11);
#if F_CPU &gt;= 8000000L
    sbi(TCCR1B, CS10);
#endif

#if defined(TCCR1A) &amp;&amp; defined(WGM10)
    sbi(TCCR1A, WGM10);
#endif
</code></pre>
