Spinning the wheels: interfacing PMDC motors to a microcontroller
Advanced PMDC motors kept Opportunity roving around Mars for 14 years. Credit: NASA
The humble brushed Permanent Magnet DC motor (PMDC) is still the favourite for designers of small mobile robots, automotive systems and toys. It consists of three main components:
- The outer casing with two permanent magnets installed inside forming the Stator.
- The Rotor or Armature consisting of at least two copper wire coils (windings) wound on an iron core which rotates within the stator.
- The Commutator and brushes which allow a power supply to be connected to the rotating coils. The commutator is split into isolated segments so that the electromagnetic field generated by each coil reverses polarity as the shaft rotates.
It is the interaction between the static magnetic field and the rotor field that causes the rotor to rotate. For a working motor, you need a minimum of two coils with the commutator split into two 180° segments. A practical motor requires at least three coils and three 120° segments. A two-coil motor will not self-start and will ‘lock-up’ when the north and south poles of the stator and rotor fields line up. In this condition, the brushes will probably be straddling the segment gaps, shorting out the coils and the power supply. Adding a third coil eliminates this problem and ensures self-starting. High-quality motors have at least five coils, sometimes more to ensure much smoother operation. The beauty of the PMDC is its simplicity and the linearity of its operation (Fig.1). Notice all the straight lines on the graphs!
Large industrial motors use electromagnets to generate the stator field. This allows for powerful and controllable magnetic fields not possible with permanent magnets. However, recent developments in material technology have led to the introduction of extremely powerful ‘rare-earth’ magnets based on neodymium and samarium/cobalt. The main problem with PMDC motors is ageing and a gradual loss of torque. This is usually due to a reduction in the stator field strength caused by overheating of the rotor windings at low speed and heavy load. Another cause of age-related failure is the wearing out of brushes and commutator: a weakness that has led to the development of the Brushless DC motor. The trouble is, BLDC motors are expensive and require complex controllers, so brushed motors are still popular.
Driving a PMDC Motor
The simplest circuit consists of a switch and a dc power supply: if you just want on/off with no directional control. A practical project is likely to need an electronic switch - a MOSFET or Bipolar transistor device, controlled via a microcontroller GPIO pin (Fig.2a). The simple single-transistor circuit shown is suitable for low-voltage ‘hobby’ motors with a stall current less than 1A. Note the diode to protect the transistor from the high reverse voltage that occurs when an inductive load is switched off. The capacitor helps to reduce RFI generated by the motor’s commutator action.
If control over the direction of rotation is required, this can be achieved with an H-Bridge circuit (Fig.2b). It’s a very popular circuit and is widely available packaged in a single chip. The switch element, S on the diagram, can be a single bipolar transistor but is most often a Darlington Pair or a MOSFET. The diodes and capacitor perform the same protection function as before. An examination of the Truth table for this H-bridge circuit will show that only four out of the sixteen possible permutations of input control signals A, B, C and D are used. Most of the remainder must NEVER be applied, particularly those which cause switches A and B or C and D to be turned on at the same time, short-circuiting the power rails with fatal consequences for those devices!
Most applications also need a means of varying the motor speed, especially if some sort of feedback control system is to be used. You can see from the left-hand graph in Fig.1 that PMDC rotation speed is linearly related to the applied voltage. Directly varying the voltage by operating the driver transistors in their linear region using a digital to analogue converter (DAC) would work, but at a cost of massive power wastage in the form of heat. A much more elegant method is to drive the switches with a digital pulse width modulation (PWM) signal (Fig.3).
This is by far the best way because:
- The mark-space ratio of the pulse train is directly proportional to the average voltage.
- The drivers are still switched between on and off, minimising power dissipation.
- Most modern MCUs have on-chip PWM signal generator hardware.
The PWM signal is added to the H-bridge circuit by AND-gating it with the other input signals so that all the switches are turned off while it is low and enabled when it’s high. This means that power is applied to the motor during the high phase and turned off during the low. The motor freewheels or ‘coasts’ during this off period. If all the switches are turned off via the control signals, the motor will slow down and stop – how long it takes will depend upon the load. A PMDC motor has a unique characteristic: if the power is turned off and its terminals are shorted together, the rotor field briefly reverses, opposing the turning force and bringing the motor to a sudden stop. In the H-bridge circuit, this is achieved by turning on switches B and D at the same time.
A question often asked is: ‘What PWM frequency should I use?’. In principle, anything up 20kHz can be used to get it out of human hearing range. I have found that with small hobby motors it’s hard to get a reasonable range of speed control with much more than 250Hz. One explanation may be that the very narrow pulses of a high-frequency signal are just not long enough to ‘kick’ the rotor into action. One thing is certain: it depends on the motor, and a certain amount of experimenting may be needed.
The L293D Quad Half-Bridge
As I suggested earlier, the H-bridge circuit is so useful it’s available in various forms from a number of chip manufacturers. The L293D, for example, has been around for a long time and is very popular with designers needing an interface between a microcontroller and small dc motors. The chip actually contains four ‘half-bridges’: the latter being the pair of transistor switches on each side of the ‘H’. In other words, one chip can be wired up as two independent H- or Full-Bridges to control two motors (Fig.4).
Note that extra internal logic combines the control signals for each pair of switches into a single Mode input and adds an enable input for the PWM signal. On-chip protection diodes are provided, so the only other component worth including is a capacitor soldered across the motor terminals.
The latest PMDC motor designs feature ironless, tubular coil armatures rotating around the permanent magnet stator. Expensive, but they can accelerate/decelerate very quickly and offer much greater efficiency than the standard iron-cored type. It was an ironless motor, slightly modified for use in Space, that provided the motive power for the Mars Exploration Rovers Spirit and Opportunity for many years – way beyond their original mission lifetime.
If you're stuck for something to do, follow my posts on Twitter. I link to interesting articles on new electronics and related technologies, retweeting posts I spot about robots, space exploration and other issues.
CommentsAdd a comment
[Comment was deleted]
Re: "The beauty of the PMDC is its simplicity and the linearity of its operation (Fig.1). Notice all the straight lines on the graphs!"
I agree that voltage control is simple to use, but it may well be worthwhile adding the associated Power/Speed ‘curve’. This will show that caution is required If you need to use laws of motion in your design.
@Martin_C You're right I should include the power/speed curve as part of the practical design exercise involving motor selection. I'll make it the subject of my next post.
Another nice article - thanks.
My first H-Bridge circuit used change-over relays which worked very well!
I was intrigued at the time with the last two options in your truth table "coast/stop" and "brake/stop" which as described allows you to coast and then effectively put the 'hand brake' on! The motor (plus gearbox) can be a surprisingly effective brake in this latter state.