Hello, I'm new here.
I am wondering about changing the Arduino PWM frequency.
I found some solutions, but what I really would like to do is have two potmeters, one controls the PWM duty cycle. And the other one changes the PWM frequency in real time.
It seems that controlling the PWM duty is easy but I wonder how to make the PWM frequency adjustable on-the-fly...
I'm looking for an adjustable range from about 20hz to 1000hz.
Anyone out there who knows a solution?
Do you really want to do this? Is there a valid reason or is it just to experiment.
Changing the PWM frequency involves changing the value in several registers and has been covered many times before just google it.
However, you then need to map what is coming out from the pot to several register values and it could get messy and defiantly not worth it unless you have a valid reason.
I intent to build an Arduino controlled experimental Fet driver board which can power transformers and stuff.
But to fine tune ranges it would be handy if the freq and pwm was adjustable. I did not imagine that such a thing would be 'that' complicated.
If you want a quick-and-dirty variable frequency, variable duty cycle, just get a triangular wave signal generator and a simple comparator.
No need for pesky software.
I did not imagine that such a thing would be 'that' complicated.
Well you are asking how to do it so you know it is not 'that' straightforward.
However for just powering transformers then I can't see any advantage of having this as a continuously varying parameter. Transformers are inductive loads and so when you switch them they will not have a PWM signal on them any more but a sin wave. Putting a PWM signal into a transformer will do nothing to affect the voltage out of the other side it will just limit the current capacity of the load it can drive.
here is the list of available PWM frequencies, but I think the real question is if you can change the frequency while the code is running?
If so, it would be fairly easy to make a sketch that changes the pwm frequency pre-scaler depending on a potentiometer value, but keep in mind, when you change pwm frequencies, you are changing the system timers... so you might affect other things in the sketch.