5. How to Control Motor Speed with a PWM Circuit

(article continued from previous page)

Pulse-width modulation is an effective method for adjusting the amount of power delivered to an electrical load. A simple circuit containing an inverter chip, diodes, trimpot, and capacitor creates the variable duty-cycle PWM. A resistor and transistor switch heavier loads than the 74AC14 chip can drive by itself.

Let’s say you have a nice DC gearmotor for your robot. The problem is, this gearmotor is marginally too fast for debugging the robot, or perhaps even too fast for final usage. For debugging, you’d like the motor to run as slowly as 1/3 or 1/4 of the full speed. But, replacing the gearmotor would be expensive and you’ve already installed it with home-made mounting brackets.

You measure the no-load motor current at 5V to be 88 mA. You figure that’s an apparent resistance of 56 ohms (5V / 0.088 A). Can the speed of the motor be lowered to 1/3 if you insert a 112 ohm resistor to take up 2/3 of the power?

To experiment with different resistances, you insert 200 ohm potentiometer (a variable resistor) between the motor and GND.

Schematic of motor speed controlled by a potentiometer.

You begin by powering up with the variable resistor set to 0 ohms. Then you dial it to about where 112 ohms would be. The motor is a little sluggish, but it seems to work and it is definitely slower. Then, you turn the circuit off.

When you next turn the circuit back on (still set to 112 ohms), the motor doesn’t turn at all!

The problem is that a motor is a varying electrical load.

A motor needs a lot more power at startup that it does when running. The 112 ohm resistance is far too large for the motor to start turning at power up. Motors also draw a lot more power when a robot goes uphill or pushes something.

There is another reason why a resistor is not a good choice for controlling the power delivered to a large load. As the power requirements increase, it will quickly exceed the power rating on a resistor or potentiometer. The electronic component will get very hot and then will likely fail permanently.

Furthermore, a resistor wastes excess power as heat. In a battery powered robot, we’d prefer to not waste energy.

Pulse-width modulation to the rescue!

Schematic of a pulse-width modulator (PWM) controlling the speed of a motor.

Schematic of a pulse-width modulator (PWM) controlling the speed of a motor.

By replacing the potentiometer with a transistor, the speed of the motor can be controlled by the duty cycle of the square wave.

There are two differences between the driver portion of this circuit and the LED circuit:

(For more information on driving motors, see Bipolar H-Bridge. And, yes, you can feed the pulses into R3 and R1 of the H-bridge to control speed.)

In the above schematic, notice that the motor can receive 12V even though the 74AC14 logic chip is only powered by 5V. This is possible because the logic chip output feeds into the resistor of the transistor, not directly to the motor. The resistor, transistor, and diode all help isolate the logic voltages from the motor voltages.

In the printed circuit board, I have added a voltage regulator (VR10). This provides you with the ability to attach a 6 to 12 volt power source that will run the entire circuit. The voltage regulator steps the voltage down to 5 V for the chip and the LED, but still provides full voltage to the motor.

Practical Limitations of PWM Motor Control

Using this PWM circuit, I was able to change the speed of Solarbotics’s GM6 gearmotor from 145 RPM at 5V to as little as 0.18 RPM at 5V. As you can imagine, power usage dropped as well, since the motor was off for much of the time.

However, I doubt the motor would be capable of carrying a load (moving a robot) with such a vast alteration of the motor’s speed. If you really need to change the speed of a motor drastically, use gears or select a different motor.

Pulse-width modulation is difficult below 25% for motors because they don’t gain the same rotational inertia in comparison to the static resistances of the grease, gearing, and gaps between commutators.

In fact, to get the GM6 to run so slowly, I had to reduce the PWM frequency to only 100 Hz by substituting a 1 µF capacitor for C2. This gave each “on” pulse enough time to power up the motor for a slight movement before pausing for the “off” time. Sneaky, huh?

Another interesting trick for PWM motor control is to apply twice the standard voltage to the motor. Normally, you’d run the PWM at 50% duty cycle so that the overall motor speed is unchanged (twice the voltage but half the “on” time). But, with the added voltage, the robot builder can now adjust the motor speed above (or below) the normal speed.

A weird aspect of PWM on motors is that it can create audible whining. Basically, if you select a PWM frequency in a human-audible range, the mechanical device will likely oscillate audibly.

Increasing the frequency above 20 kHz may silence the motor whining for all but youths and dogs (no comparison implied). But, some motors, transistors, or motor driver chips are unable to switch on and off that quickly.

You'll need to experiment to select the correct frequency for your particular motor, mounting system, semiconductors, and load. I selected 1 kHz because it is likely to work for most readers’ motors, even if it isn’t quiet or electrically optimal.

Benefits of Pulse-Width Modulation

I hope this article has shown you how easy it can be to control speed, brightness, and power to an electrical device with just a handful of off-the-shelf electronic components. This circuitry is superior to using a fixed or variable resistor for heavy or varying electrical loads, such as motors and LED displays.

A microcontroller-based PWM solution uses fewer components and has the flexibility of varying the duty cycle and frequency on-the-fly through software. This can be an advantage in a mini sumo battle, where searching might be performed at a slower motor speed, but the duty cycle needs to be increased to 100% “on” for pushing an opponent.

However, you can add chips to this circuit if you want to be able to select from various speeds. For example, using a demultiplexer or other path-selection chip, you could wire up the path between the 74AC14 output and the potentiometer to pass into different potentiometers dialed to different settings for various occasions.

Enjoy!