Initializing timer registers on 16bit counter?

Hi madworm,

I see what you are trying to do but that test does not duplicate real world use of the timer. Have you checked the datasheet to see if reading TCNT1 is valid when the timer is not running?

Perhaps try a test with the timer running and set to the slowest count possible and poll TCNT1 as follows :

void setup()
{
    TCCR1A = 0;             // normal counting mode 
    TCCR1B = _BV(CS10) |  _BV(CS12);      // set prescale to 1024
    TCNT1 = 0;              // clear the timer count 
    Serial.begin(9600);
}

void loop()
{
  sreg = SREG;                  // store IRQ flags
  cli ();                  // all IRQs off
  timer1 = TCNT1;            // read it back
  SREG = sreg;                  // restore IRQ flags
  Serial.print(millis());
  Serial.print(","); 
  Serial.println(timer1); 
}

You should see timer1 increase by however many ticks of 64us it takes to do the loop. You should see the timer value and the millis value correspond (multiply the timer value by .064 to get milliseconds)