Motor Control II
From Opendildonics.org
Intermediate Motor Control
(Or how I learned to stop worrying and love the PWM)
There has got to be more than on and off to motor control. For one thing, there's speed control. While you may want your vibrator going full tilt boogie, you probably don't want it doing that all the time. A typical commercial (off the shelf) vibrator uses basically the following circuit for speed control:
In this circuit, the motor is driven by the output from a voltage divider/on-off switch. The good news is that this circuit is shown in the motor control chapter of every book on motor control. The bad news is that it's shown as an example of what not to do for motor control. The problem is efficiency: the variable resistor controls the voltage drop across the motor just fine, but the resistor also generates heat. Because of the second law of thermodynamics, that energy had to come from somewhere - and that somewhere is the power source of the circuit. This has a number of disadvantages:
- It wastes electricity as heat
- It eats batteries
- It reduces the life of your electronics
- It decreases reliability
- You have to get rid of the heat - which means heat sinks - increasing complexity and cost.
- You need variable resistors that can handle the heat before you get rid of it
This circuit is OK for vibrator manufacturers who:
- Don't pay for the batteries, and thus don't care about battery life
- Who don't care about reliability because they don't have much competition and can get you to buy a new one when this one fails
- Mostly use really cheap variable resistors because of #1 and #2.
Using a transistor amplifier to drive the motor helps, but doesn't help much. It takes the current flow and moves it from the variable resistor to the amplifier transistor. This allows you to use a cheap variable resistor (because there's very little current flowing through it) but means you need to heat-sink the transistor instead, and doesn't do anything about the efficiency.
The Right Way - Pulse Width Modulation
Okay, you're thinking, I just want to get my vibe working. There has got to be a way around this, or you'd just be telling me where to go buy a monster heat-sink. You're right, there is a way. Motor controls only run efficiently in two states - all the way on, and all the way off. Everywhere in the middle, there's a resistive loss across whatever you're using for voltage control. It turns out that motors aren't too fussy about instantaneous power, however. As long as the average power over (for example) 10 milliseconds is 2 volts, the motor will behave as is it were being run on 2 volts. This means that is you have a 5v power supply and turn the motor on 2/5 (40%) of the time, you're golden. This is the essence of how Pulse Width Modulation works. The rest is merely the details.
For explanatory purposes, I'll divide a cycle into 10 pieces. (Start to 1, 1 to 2, etc.) At the far left, all the channels are turned off. At start, all the channels are turned on, and a countdown starts. When it hits 1, the first channel turns off. When it hits two, the second turns off, and when it hits 5, the last channel goes off as well. The first channel is on 1/10 or 10% of the time - which is called a 10% duty cycle. The second is 2/10 or a 20% duty cycle and the third a 5/10 or 50% duty cycle. This is called Pulse Width Modulation because you control the speed of the motor by modulating (changing) the width (duty cycle) of the pulses (the time the channels are on).
Normally, when you're working with DC motors you make the period short enough that you have several thousand periods per second. This is usually shortened to Khz (Kilohertz) despite the fact that this is technically incorrect. Since PWM signals are usually generated by digital circuits, which work in powers of two, you will often see things like 8-bit PWM or 10-bit PWM. All this means is that the PWM periods are broken up into 256 or 1024 slices (respectively). 10 bit PWM simply divides the same period into smaller slices, giving you finer control over the speed of the motor.
Typically, you will use a PWM period of 8khz - 20khz for running vibrators. I like to use 20khz, since the switching noise from the motor is vastly smaller and far quieter, and it's not such a high switching rate that you start to run into other problems. I normally drive them at that rate using either 8 or 10 bit PWM using a microcontroller, rather than a PC. This means that I use a cheap embedded computer to do the "turn it on, start the count, wait, turn it off, wait, jump back to start" part of the job. If you are using a PC parallel port to control you toy, you can do the same thing in software - but be aware that PCs are not really optimized for that kind of work.
The circuit
After all this, you would probably expect some kind of new and interesting circuit. Unfortunately, you're bound to be disappointed in this case. This stuff is all done in software or in the dedicated hardware on microcontrollers, and you can just use the circuit in Motor Control I, and have a great deal of success.


