Leonardo (32u4): Timer0 problems with CTC mode I want to use timer 0 to generate a rectangular signal on OC0A (D11) without the use of Arduino specific functions (that use timers for themselves). When I toggle D11 manually using a loop, I hear a sound in the connected piezo, but with my sample code, I don't hear something:

#define ALARM_PIN 11

void setup() {
  digitalWrite(ALARM_PIN, LOW);
  pinMode(ALARM_PIN, OUTPUT);
  noInterrupts();

  OCR0A = 60;
  // Toggle OC0A on compare match
  TCCR0A = (0 &lt;&lt; COM0A1)
         | (1 &lt;&lt; COM0A0)
  // CTC mode
         | (1 &lt;&lt; WGM01)
         | (0 &lt;&lt; WGM00);
  // prescaler = 256
  TCCR0B = (0 &lt;&lt; WGM02)
         | (1 &lt;&lt; CS02);
}

void loop() {
}


Any idea, what could be wrong?

Update

I've played with it a little bit more:

#define LED_PIN 9

void setup() {
  pinMode(LED_PIN, OUTPUT);
  TCCR0B = (1 &lt;&lt; CS02);
}

void loop() {
  digitalWrite(LED_PIN, TCNT0 &gt; 250);
}


This causes my LED to light very dim, so the timer is running up to 255. But as soon as I set TCCR0A, nothing is lighting up:

#define LED_PIN 9

void setup() {
  pinMode(LED_PIN, OUTPUT);
  OCR0A = 60;
  TCCR0A = (1 &lt;&lt; WGM01);
  TCCR0B = (1 &lt;&lt; CS02);
}

void loop() {
  digitalWrite(LED_PIN, TCNT0 &gt; 0);
}
You should re-enable interrupts after you finish setting up. Use either

interrupts(); 


or

sei();


If you want to don't want to use the arduino specific commands. Even if the code does not need interrupts, background code does use them.

Timer 0 is used in arduino for some basic "house keeping" function like keeping time. I'm not sure if that could be part of your problem. you could try using a different timer.