Help requested for PWM using multiple pins with different duty cycles #2080
-
Can anyone help (especially Earle, who does amazing work - thank you!) - I need to control 4 motors using PWM. For some reason the motor manufacturer requires a 200 Hz signal. I tried using the now-defunct RP2040_PWM library but it refuses to go below ~250 Hz, so I'm trying AnalogWrite, first setting up the frequency and resolution using AnalogWriteFreq and analogWriteRange. This works nicely for one PWM output, but there's no apparent way to generate multiple PWMs at different pins with different duty cycles. Is this a hard limitation, or is there a way to code around this? An example code snippet would be greatly appreciated - I'm pretty sure I'm not the only one with this dilemma. John |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Some code samples would be helpful. |
Beta Was this translation helpful? Give feedback.
-
Thank you, Earle. I do believe I overthought this and didn't think it possible to instantiate different writeAnalog pins with different duty cycles. I did try try it but a balky duPont lead gave me a misleading result. With that fixed, this test code executes perfectly. It's great, by the way, that you made it so easy to change PWM frequency and resolution. It's no problem (in my case) to have all analogWrites share those properties. Thanks again! John
|
Beta Was this translation helpful? Give feedback.
Some code samples would be helpful.
analogWrite
can set a different PWM duty cycle (that's whatanalogWrite
does) to 16 different GPIOs at the same time (with the usual RP2040 PWM generator limitations about not all pins being individually controllable...see the datasheet because it's well explained there).