I have set the PWM frequency of an Arduino through 13 bit resolution. How can I change the frequency to be between 200Hz and 1kHz, with 2 buttons(+ and -) and with each press the frequency should change by 10Hz
I am using an Arduino Uno
How did you get 13 bit pwm?
Default is 8 bit PWM.
PWM freq can be adjusted through direct register manipulation. Steps are dependent on divider settings. So 18MHz and then divided by 4, 8, 16,
If you are willing to loose some pwm bits, you might be able to get some values in between.
But not in steps of 10...
Why would you want that anyway?
Since your frequency is pretty low, you may achieve what you want with a microSeconds timer and some bit banging....
I manipulated the time registers, setting the ICR1 at 8182, I already have 1.9kHz but I need the frequency to be interchangeable. Also it fluctuates for some reason. I need resolution and frequency for a PWM generator
Also why not steps of 10?
I see: log(8182)/log(2)=12.998
is your 13 bit resolution. And 8182 gets you to 16000000/8182=1956Hz
Fluctuates by how much? And how much fluctuation is acceptable?
As per forum guidelines, please post your full code, a schematic, and which Arduino you are using.
You can make the frequency adjustable by adjusting ICR1. And then set duty cycle as a fraction of ICR1. This is a good reference:
Or there's the excellent Timer1 library
Ok. That is pretty sophisticated.
And using a 16 bit timer you should have some playing room to organize both frequency and bit depth. See post #4.