Main Site Documentation

PWM and OutputCompare


Is there a reason why PWM or OutputCompare does not include an overload for taking an array and a RepeatCount. So you can repeat a given array N number of times. That way you don’t have to pass a huge array and repeat your pattern inside it. Or am I missing something?

For example, say I want to PWM control Step pin on two stepper controllers and send something like 20 rotations. At 200 steps per rotation, the arrays would be way too large and just a waste or space anyway. If I could set a repeat count, I could pass a two element array and the internals would just repeat it any number of times.


Not sure I understand what you are getting at here, are you talking about rapidly (re)setting the PWM pins’ waveform?

If you are, I think this is a specialized application and you may consider writing your own lib to do it.


Just turning it low and high N number of times (1 microsecond low, 1 microsecond high) via pwm. Right now I am doing it in a loop. But to do that with two motors would require seperate worker threads and was hoping for something cleaner and less cpu intensive.

What I was looking for is something like:

pwm.SetPulse(2000, 1000, 400); // repeat low/high 400 times.


Any comments on this? Maybe I am missing something.


There is no way to do this. We can take a look into it for future. But now, you either have to repeat the buffer in the output compare or stop the PWM channel after the time needed for x pulses is passed.


Ok. Thanks Mike. That wraps it up for me. If your making a wish list. It would seem the Repeat counter and some kind of optional notification event/callback after complete would seem useful in many situations (IR, motor control, etc). Another thing would be some kind of atomic latching or group. So you could setup multiple pwm ports with commands and then let them go at ~same time or stop them at same time.

Basically a Future/Task for PWM.