Hi.
I have been trying to find a way to output a PWM signal from my Arduino Mega, but I need to be able to change the frequency. And I would need to be able to control the duty cycle with an analog input.
I have been using "AnalogInOutSerial" for testing but I am getting a very high pitched loud tone in my application. I looked through all the example sketches and could not find anything. Ideally I would like to keep this as simple as possible since I have limited Arduino IDE experience.
If anyone could help me out or point me in the right direction I would appreciate it. Thanks!
Changing the duty cycle is as simple as changing the value used with analogWrite().
Changing the frequency requires changing the values in the HardwareTimer registers. Avoid messing with Timer0 as that is used to produce micros() and millis().
Why do you want to change the frequency?
What frequencies do you want to use?
In what circumstances will a change be needed?
...R
I used the TimerOne library to generate a 20HZ PWM for a treadmill motor on a Mega. Very easy to use.