user3237: 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 << COM0A1)
         | (1 << COM0A0)
  // CTC mode
         | (1 << WGM01)
         | (0 << WGM00);
  // prescaler = 256
  TCCR0B = (0 << WGM02)
         | (1 << 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 << CS02);
}

void loop() {
  digitalWrite(LED_PIN, TCNT0 > 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 << WGM01);
  TCCR0B = (1 << CS02);
}

void loop() {
  digitalWrite(LED_PIN, TCNT0 > 0);
}


user1585: 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. 

3237: <p>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:</p>

<pre><code>#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() {
}
</code></pre>

<p>Any idea, what could be wrong?</p>

<p><strong>Update</strong></p>

<p>I've played with it a little bit more:</p>

<pre><code>#define LED_PIN 9

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

void loop() {
  digitalWrite(LED_PIN, TCNT0 &gt; 250);
}
</code></pre>

<p>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:</p>

<pre><code>#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);
}
</code></pre>
 1585: <p>You should re-enable interrupts after you finish setting up. Use either</p>

<pre><code>interrupts(); 
</code></pre>

<p>or</p>

<pre><code>sei();
</code></pre>

<p>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.</p>

<p>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. </p>
