variable pwm freq and dutycycle !!

hi folks :slight_smile:

is anyone can tell me, can i controll pwm frequency and pwm dutycyle with 2 potantiometers ?

im thinking about this project and i searched thousend of times but i didnt find my answer yet.

if answer is yes/no please explain to me....

thanks in advance and have a great day :))

Use analogWrite(dutyCycle) to change duty cycle. With a pot use analogRead(potPin) and divide the result (0-1023) by 4 to get the 0-255 for analogWrite.

dutyCycle = analoRead(potPin) / 4;
analogWrite(dutyCycle);

Why do you want to control the PWM frequency?

Have you searched 'varying pwm frequency' on this site?

groundFungus:
Use analogWrite(dutyCycle) to change duty cycle. With a pot use analogRead(potPin) and divide the result (0-1023) by 4 to get the 0-255 for analogWrite.

dutyCycle = analoRead(potPin) / 4;

analogWrite(dutyCycle);




Why do you want to control the PWM frequency?

Cause i want to make a dc dc converter. thanks for reply. i know how to change dutycyle already [i should say that before :slight_smile: ]. i just need to know how to change freq with potantiometer..

The hardware timers can generate PWM. You adjust the frequency of the PWM by setting 'prescale' and 'TOP'. You set the duty-cycle by adjusting the Output Compare Register between 0 and TOP.