const uint8_t OUTPUT_PIN = 3; // = OC2B
const uint8_t PERIOD = 9; // 9 CPU cycles ~ 1.778 MHz
void setup()
{
pinMode(OUTPUT_PIN, OUTPUT);
TCCR2B = 0; // stop timer
TCNT2 = 0; // reset timer
TCCR2A = _BV(COM2B1) // non-inverting PWM on OC2B
| _BV(WGM20) // fast PWM mode, TOP = OCR2A
| _BV(WGM21); // ...ditto
TCCR2B = _BV(WGM22); // ...ditto
OCR2A = PERIOD - 1;
OCR2B = PERIOD/2 - 1;
}
void soundBuzzer() {
TCCR2B |= _BV(CS20); // F_CPU / 1
}
void silenceBuzzer() {
TCCR2B &= ~_BV(CS20);
TCNT2 = 0;
}
I got it from here, look down to the answers
This program supposed to generate a square-wave of frequency around 1.7MHz but it is not working for me. I have tried the simulation on Proteus 8 and there is no output. Only one error shows during the compilation which is the 'loop' function is missing, I have added one and still there is no output. Please somebody help me.