Timer half as fast as it should be

Hello,

I´m trying to write a program that turns on a led after one second and after another one it should turn it of again and repeat that. I want to do this on low level (and not using delay()) with Timer2.

With an UNO with fsys=16MHz, prescaler 1024 and 8-bit counter register i should get an INT every ~16ms (1/16MHz * 1024 * 256). To get one second i added a counter variable to the isr which counts to 60 which should result in one second, but it is 2 seconds.

Here´s my source code:

void setup() {
  Serial.begin(9600);
  pinMode(3, OUTPUT);
  
  // Timer 2
  TCCR2A = 0;
  TCCR2B = 0;
  
  TCCR2A |= (1 << WGM20);
  TCCR2B = B00000111; // prescaler 1024
  TIMSK2 |= B00000001; // Enable INT - TOIE1: Overflow
}

void loop() {}

ISR(TIMER2_OVF_vect) {
  static unsigned int counter = 0;
  static unsigned long start_millis = millis();

  if (counter == 60) {
    digitalWrite(3, digitalRead(3) ^ 1);
    
    Serial.write("\ntime (ms): ");
    Serial.print(millis() - start_millis, DEC);
    start_millis = millis();
    
    counter = 0;
  } else {
    counter += 1;
  }
}
TCCR2A |= (1 << WGM20);

That setting gives Mode1 which is PWM to 255, a mode where the counter counts up and down before reset and the overflow interrupt.

Use Mode 3 for Fast PWM which only counts up before reset and overflow interrupt.

TCCR2A |= (1<<WGM21 | 1 << WGM20);

thanks, its working now :)