 # How to get 7.8 kHz PWM on pins 3 and 11

I’ve went through the timer2 manipulation examples and with the help of those I can get 7.8 kHz PWM on pins 3 and 11 with Fast PWM. There is a problem though. When OCR2A = 0 and OCR2B = 0 the output on pins 3 and 11 is not 0 but 1 on scale 0-255 (see the image capture from the oscilloscope screen).

When using the Phase-Correct PWM Example (commented out), the output is 0 when OCR2A = 0 and OCR2B = 0, but I do not know how get the 7.8 kHz frequency with that method.

Could anyone please help me to get 7.8 kHz PWM on pins 3 and 11 that is 0 when OCR2A = 0 and OCR2B = 0.

Resolution can be lower than 0-255.
I am using Arduino Pro Mini 16MHz.

Thank you,
Fred

``````int pwmPin1 = 3; //PWM 1. pin
int pwmPin2 = 11; //PWM 2. pin
int pwmPotPin = A0; //PWM duty cycle potentiometer pin

void setup() {

pinMode(pwmPin1, OUTPUT); //Set Output to Pin 3
pinMode(pwmPin2, OUTPUT); //Set Output to Pin 11

//the Fast PWM
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS21);
//CS20, output frequency = 62,5 kHz
//CS21, output frequency = 7,8 kHz
//CS22, output frequency =  976 Hz

/*
//the Phase-Correct PWM
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS21);
//CS20, output frequency = 31 kHz
//CS21, output frequency = 3,9 kHz
//CS22, output frequency = 490 Hz
*/
OCR2A = 0; // set initial PWM duty cycle on pin 11
OCR2B = 0; // set initial PWM duty cycle on pin 3
}

void loop() {

int	pwmValue = analogRead(pwmPotPin); //value between 0-1023
OCR2A = pwmValue / 4; // set PWM duty cycle on pin 11, 0-255
OCR2B = pwmValue / 4; // set PWM duty cycle on pin 3, 0-255
}
`````` After you changed the frequency, just use analogWrite() and let the Arduino HAL do the rest Well, well, well… do not know should I laugh or cry :-)) So it was that simple and obvious. Thank you so much septillion for ultra quick help!