Periodic disturbance when manually creating a PWM signal.

I am trying to create a PWM signal to step a stepper motor using my BBB. I am currently doing this by toggling the pin on and off, but when I look at the signal on an oscilloscope, the pwm is working, but about every 3.9ms there is a periodic disturbance that keeps the signal high or low longer than intended. I am guessing this is an issue with something going on in the background. Would it be possible to fix this?

You will never get a nice accurate square wave if you are doing this in code by toggling a GPIO pin.

You have 2 options.

  1. Use a real PWM output.
  2. Write some code to run on a PRU .

You may want to check the example qep, which uses the A and B output of a PWM module in the PWMSS-1 subsystem to simulate a quadrature encoder. The same signal can drive a (bi-polar) stepper motor.


No, however you can minimize what is going on. Nothing wrong with the behavior if it is acceptable for the design.

You might be able to kill processes that you do not need for you application.


The shorter the tree the lower the chances of ad hoc behavior. Keep in mind if you are using a desktop environment you will more than likely break the system if you shut down stuff.

Not sure how critical your timing needs are, so in other words, if the timing is within the design criteria just be aware of it and move forward with it. If not then look at some other options.

1 Like

Thank you for the responses. I ended up going with the PRU approach. Was a bit of a learning curve as I am very new to Linux, but managed to get it working. The response is much better now. it is also able to step MUCH faster now which is a bonus. Thanks a lot everyone!

1 Like