Pulse Width Motor Control

My last project had me digging through old robotics parts to find an H-Bridge Motor Controller.  I found one that had several TTL chips on the circuit as well and it reminded me of a trick some of you may find useful.

First, lets define pulse width modulation (PWM.)  It refers to the duty cycle (how long the line is high vs how long it is low) of a pulse stream.

Pulse Width Motor Control

What use is this for controlling motors?  If you have ever tried controlling a motor by simply turning it on and off, you quickly realize how little control you have.  Your robot goes from stopped to zooming at full speed with nothing in between.  If, however, you use PWM to power your motor, then it will be on at full power very briefly and then off, repeatedly.  With PWM you can provide much finer motor control and have your robot move at whatever speed you like.  The higher the duty cycle of the pulse stream, the more power your motor will output.
Pulse Width Motor Control SchematicThere are several ways to produce PWM signals from the Raspberry Pi.  The simplest is to turn a GPIO pin on and off in a loop with delays controlling the pulse width.  This is very CPU intensive and not always consistent.  You can use libraries or device drivers to produce PWM from the GPIO that will be consistent and will use virtually no CPU.  Or, you can use external hardware to produce PWM.

Here is how I have done it in the past. (I haven't built a robot using a Pi yet, but did it with simpler microcontrollers years ago.)  Use six GPIO pins:

For more detail: Pulse Width Motor Control

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top