Design Article
Open-Source Robotics and Process Control Circuit Examples - Part 3: Speed-controlled DC motor
Lewin Edwards
9/2/2008 2:46 PM EDT
3.5 Speed-Controlled DC Motor with Tach Feedback and Thermal Cutoff
E-2's main propulsion system consists of two DC motors directly driving contra-rotating propellers. An underwater vehicle with a single propeller is subject to
undesirable torque forces, especially if the vehicle has no significant keel.
It's possible to counteract this by using a stator to straighten the water flow behind the propeller. It's also obviously possible to drive two propellers from a single motor using gears. However, using two independently-controllable motors allows us to tighten the vehicle's turning circle by running the motors in opposite directions, if desired. It also lets the device limp home if one motor fails, or one propeller happens to foul something.
The textbook circuit configuration for controlling a reversible DC motor is the H-bridge, illustrated (representatively with bipolar transistors) in Figure 3-6:

Figure 3-6: Standard H-bridge circuit.
This is very much a "lowest common denominator" circuit, and although you might build one on a breadboard for a very quick and dirty test of something, you would never want to field a device built around such a simple configuration. However, it's a good starting point to illustrate the basic principles.
To run the motor in one direction, turn on the PNP transistor on one side of the bridge (say, at A), and the NPN transistor on the other side (say, at D). To run the motor in the opposite direction, turn on the opposite pair of transistors; B and C in our example. You can control the motor's speed by modulating the on-time of either or both of the active transistors.
There are numerous practical problems with such a simplistic design. Perhaps most importantly, there is no protection for the switching transistors from the inductive "kick-back" from the motor windings. You could mitigate this by putting a protection diode across the collector and emitter of each transistor.
Also consider what would happen if you reverse the motor direction by switching from the configuration (A ON " D ON) to the configuration (B ON " C ON). The switching times of the individual BJTs or FETs you would be using are not exactly identical, so you run the risk that, for an instant, both sides of the bridge could be "on," thus shorting the power rails—and probably either burning out part of the driver circuit, blowing a fuse or just causing a momentary power glitch that could reset some or all of your system to an unknown state. You could work around this problem by ensuring that the firmware never goes directly from the "powered up—forward rotation" to "powered up—backward rotation" states; instead, it should switch both sides of the bridge off for a brief recovery period before changing directions.
Furthermore, there is also no intrinsic hardware protection to prevent a firmware bug from shorting the power rails directly through one side of the bridge (for example, by switching on A and B simultaneously due to a software error writing garbage values to an I/O latch)—you could solve this by providing some external logic providing "direction" and "enable" inputs that only allow the drivers to be turned on in permissible combinations. Finally, as the circuit stands, you have no way to diagnose the health of the switching circuit or gauge the current being drawn by the motor, so you can't detect a stalled rotor or shorted winding.
Rather than reinventing all these wheels and engineering a custom solution, we cut around these messy problems by using the National Semiconductor LMD18200T integrated H-bridge. This chip is not exactly cheap, at around $11.50 (in single-piece quantities). However, the price is well worth the engineering time saved. If nothing else, you would probably spend at least twice this amount on destroying MOSFETs while debugging your own circuit design.
The LMD18200 also offers several useful bonus features, including an internal junction temperature watchdog that will signal to your microcontroller with a simple digital signal if the chip is overheating (and shut the drivers off if the H-bridge overheats), integral shoot-through protection, nonregenerative braking (this shorts the motor windings) and a current monitoring output that, with an appropriate shunt resistor and ADC, can be used to measure how much current is being drawn by the motor. In fact, we won't be using the latter feature, so you might prefer to use the slightly cheaper LMD18201, which is identical to the LMD18200 except that it doesn't have the handy drive-current-monitoring feature.
The reason I specify the LMD18200 is simply because it seems to be stocked by more vendors than its cheaper sibling. The price difference is only a few pennies from the distributors I use, but maybe you'll come across a load of amazingly cheap LMD18201s in the surplus marketplace.
There is one more feature our circuit offers, which isn't always essential but is often useful - tachometer feedback. Without some feedback on the actual physical number of revolutions being executed per second, it is practically impossible to control the speed of a motor under varying load.
The tach input of the board expects to see an active low pulse once per revolution. The sensor method I use on the E-2 is a Hall effect sensor mounted next to the motor shaft, and a tiny neodymium magnet glued to the shaft. You might prefer to use some other method, such as an optical sensor and a reflective (or dark) mark painted on the shaft. Some motors even have tach hardware of some sort built in; this is particularly common in small cooling fans, which frequently have an integral Hall effect sensor. With such motors, all you need to do is connect the wires properly, and you're done16.
However, you should note that the tach on these motors may not be reliable at anything less than 100% PWM duty cycle. These cooling fans are often designed to run continuously at full speed, with the tach providing feedback to the system that the fan hasn't stalled. The tach sensor is probably powered directly off the power input wire, and may not have enough of a decoupling capacitor connected to remain alive during the "off" portion of your PWM signal.
Footnote:
16. Note: Almost all fans output two tach pulses per revolution. Depending on what kind of tach sensor you employ, and how you mount it, your system may output only one pulse per revolution.



