You need to learn how to program the Atmega 328 registers (assuming you are using an Uno) if you want to change the PWM frequency. Have a look at the Atmel datasheet.
I can understand why you might find the default PWM frequency unsatisfactory, but I have no idea why it might be advantageous to change the frequency dynamically.
The code in this Thread uses PWM to play a WAV file. Hopefully it is a simple illustration of the use of registers. You should be able to figure how the PWM frequency is set, in conjunction with the Atmel datasheet.
well, i use the potentiometer to change the duty cycle, i want to change the frequency with another potentiometer. If i try to use this to let's say to control the speed of a big motor, that 490Hz "screaming" is a bit anoying.
bogdan666:
well, i use the potentiometer to change the duty cycle, i want to change the frequency with another potentiometer. If i try to use this to let's say to control the speed of a big motor, that 490Hz "screaming" is a bit anoying.
I would try changing to a different PWM frequency to see if the noise is more acceptable. But I would not bother with varying the frequency in response to a potentiometer.
In any case once you know how to change the frequency it will be straightforward to arrange to change the values based on the analogRead() value.
bogdan666:
Oooh it will not be straightforward belive me, i have a bit more to go to call myself a beginer..
Did you study the code in the link I gave you earlier. That has the advantage tha I am familiar with it.
If you have another program that will cause the PWM to operate at some frequency other than 490Hz please post it so that we have a basis for further discussion and learning. If not, let's use my code.