Hello,
I need help with writing a PWM function that is accurate and reliable. I need it to be in the following format.
PWMout(int output pin, int frequency, int duty cycle);
I know that the analogWrite() function gives me PWM. I need different frequency. The frequency input should be a range of all the frequencies that the arduino can handle. The function should take the Ducy cycle input as a percentage.
Thanks
The frequency of PWM does not matter in virtually all cases. Why is it important to you?
By the way it can't be done like you want, you will have to make compromises.
Hello Mike,
I am working on an application that requires me to change the PWM duty cycle and possibly the frequency during a 1 second period. So 1 Hz.
Thanks
You can only get full 8 bit resolution of the duty cycle at certain spot frequencies. If you want any frequency then the range of duty cycle is limited.
Also you are best using pin 3 or 11 controlled by timer 2.
Without real numbers there is not much more I can add. Do a search for changing the PWM frequency, this involves poking values into some registers. The analogue write will control the width but it will only work up to a value determined by the main register.