PROGRAM TO GENERATE 30.303KHZ IN ARDUINO
const byte OUTPUT_PIN = 3; // Timer 2 "B" output: OC2B
const byte n = 65; // for example, 8.89 kHz
void setup()
{
pinMode (OUTPUT_PIN, OUTPUT);
TCCR2A = bit (WGM20) | bit (WGM21) | bit (COM2B1); // fast PWM, clear OC2A on compare
TCCR2B = bit (WGM22) | bit (CS21); // fast PWM, prescaler of 8
OCR2A = n; // from table
OCR2B = ((n + 1) / 2) - 1; // 50% duty cycle
} // end of setup
void loop() { }
const byte OUTPUT_PIN = 3; // Timer 2 "B" output: OC2B
const byte n = 65; // for example, 8.89 kHz
void setup()
{
pinMode (OUTPUT_PIN, OUTPUT);
TCCR2A = bit (WGM20) | bit (WGM21) | bit (COM2B1); // fast PWM, clear OC2A on compare
TCCR2B = bit (WGM22) | bit (CS21); // fast PWM, prescaler of 8
OCR2A = n; // from table
OCR2B = ((n + 1) / 2) - 1; // 50% duty cycle
} // end of setup
void loop() { }
Comments
Post a Comment