I'm simply trying to use timer 2 for tone generation and what I get is a very faint and strange tone (almost like its modulated somehow as there is a "pulsing" to it). Here's my simple code:
#include <Arduino.h>
#define SPEAKER_PORT PORTC
#define SPEAKER_BIT 2
void setup()
{
pinMode(A2, OUTPUT);
TCCR2A = _BV(WGM21); // CTC mode
TCCR2B = _BV(CS20); // clk/1
OCR2A = 200; // 8-bit timer, so keep less than 256
bitSet(TIMSK2, OCIE2A); // enable OCR2A interrupt
}
void loop()
{
// NOP
}
ISR(TIMER2_COMPA_vect)
{
SPEAKER_PORT ^= _BV(SPEAKER_BIT);
}
Any obvious mistakes? Thanks for your help!