>
PC Generated Pulse Width Modulation (PWM) For DC Motor Speed ControlFigure 1 is a photo of a DC motor controller you can construct in a weekend or two. Motor speed is controlled using pulse-width-modulation (PWM). The key feature of this tutorial is that your PC is used to generate the PWM signal. Thus you can program your PC to contol motor speed in software.
PWM for motor speed control works in a very similar way. Instead of peddling, your motor is given a fixed voltage value (say +5 V) and starts spinning. The voltage is then removed and the motor "coasts". By continuing this voltage on-off duty cycle, motor speed is controlled.
The concept of PWM inherently requires timing. The classic 555 timer chip and some potentiometers can be used to generate PWM. The pots are manually adjusted for the desired duty cycle. However, if you use a PC, you can automatically change the duty cycle and have your PC control your motor's speed.
One potential application of automatic motor speed is regulating room temperature. Your PC can sense the current temperature (using an analog-to-digital converter) and then automatically increase/decrease the fan's speed accordingly. By using your PC you are no longer burdened to manually adjust the fan's speed as the room heats or cools.
There are many commercial PC motor speed controllers however they tend to be very expensive (hundreds of dollars). This tutorial shows you how to breadboard your own for a fraction of the price. The parts are widely available and inexpensive. The key component is the 8254 timer/counter chip (apx. $4) breadboarded on a ISA protoboard card (apx $15). This card plugs into your PC just like a modem or sound card. A complete tutorial on the 8254 Timer/Counter Card exists on the Boondog website. You need to construct this 8254 card prior to building and programming your DC motor control circuit.
This rest of this PWM tutorial is broken down as follows:
PART DESCRIPTION | VENDOR | PART | PRICE (1999) | QTY |
74LS74 D FLIP-FLOP | JAMECO | 48004 | 0.29 | 1 |
UDN2993 H-BRIDGE | ALLEGRO | UDN2993 | 5.00 | 1 |
You can also download the 7474 PDF datasheets.
Allegro Microsystems UDN2993 is a 16-pin DIP packaged dual H-bridge chip that can handle 30 V continous at 0.5 A. An H-bridge is a common way of controlling motor direction. This chip has two H-bridges and the schematic only uses one of them. The UDN2993's enable input pin accepts PWM signals. Although motor direction is not discussed in this tutorial, the UDN2993's phase input can be used to control motor direction.
The UDN2998 is a bigger cousin of the UDN2993 handling 50 V at 3 A continously. It is also available from Allegro. and functions identically. It comes in a 12-pin single in-line (looks similar to a 7805 regulator but fatter) power-tab package.
H-bridge chips are quite common and other alternatives to the UDN2993/2998 exist. STMicroelectronics (also known as SGS-Thomson) makes the L298 dual H-bridge driver which handles 4A at 46V. Alltronics sells the L298 for $9.95. National Semiconductor makes the LMD18200, which is a 3A, 55V H-bridge chip. Digikey, sells it as part number LMD18200T-ND for $23.55
Here are the other H-bridge PDF datasheets:
Check your circuit before you physically connect your motor up to the third board. If you have an oscilloscope, you can see the PWM signal by executing the code in the Programming section. Figure 2 is a GIF screen shot from an oscillosope. The scope was connected to the output of the 7474 flip-flop (pin 5). The 80% duty cycle can be clearly seen. During one period, the signal is high (+5V) 80% of the time and low (0 V) for the other 20%.
Figure 1 (right) is a photo of the motor and UDN2993 board. The motor has a black disk mounted on its shaft. I milled/drilled a nice motor stand from plastic to hold the motor. The black disk has one small pencil-sized diameter hole, and works as a simple optical encoder disk. The infrared (IR) encoder/decoder tutorial shows how you can construct your own encoder. The 8254 Timer/counter card can be used to count motor revolutions. This will be explained in a future tutorial.
Next, the user is prompted to enter the 8254 Card's base address and a desired duty cycle. The baseAddress is used to configure both counters 0 and 1 as rate generators (8254 Mode 2). A rate generator brings an output high (+5V) at a fixed rate. Here, both counter 0 and 1 count down from 10240 (decimal) to 0. Each decrement occurs at the 8254's crystal oscillator frequency of 1.0 MHz or, every 1 microsec. Upon reaching 0, OUT1 will go high momentarily.
After the user enters the base address and desired duty cycle, the user is prompted to either quit, start or enter a new duty cycle. The choice is branched by a switch statement.
If the user doesn't quit, counter 1 faithfully decrements. It's value counterValue is checked against the desired duty cycle (its equivalent in counts), dutyCycleCount . Once they are the same, counter 0 starts counting from 10200 to 0, using the statements:
outportb(counter0, t0_valueLSB); outportb(counter0, t0_valueMSB);If the user decides to quite, the timer's gates are released outportb(gateAddress, 0); and counting stops.
In essence what happens is that counter 1 decrements from 10200 to 0. Everytime it reaches dutyCycleCount, counter 0 starts counting from 10200 to 0. By doing this, the 7474 flip-flop's clear (CLR1) and preset (PRE1) value alternate. The output (Q1) then outputs a pulse-width-modulated signal.
This tutorial shows you how you can easily breadboard your own for a fraction of the price. It is affordable because of the power and flexiblity of the Intel 8254 timer/counter chip. A complete tutorial on this chip exists on this website.
Click here to go Paul's Main Page
Click here to go to Columbia University's Robotics Lab
Click here to email me