Some time ago I wanted to design a really small DC motor controller for my experiments. I found a very nice device, tiny, but still capable of delivering close to 3A of direct current to a DC motor. It may have looked like the 3A was an instant winner, but what captivated my attention was the ease of use of this device. The result was my AE-DC1 (more information HERE).
The cool thing about this tiny controller is that it will make it very easy for me to explain a series of DC Motor control issues such as speed variation and PWM (for Pulse Width Modulation).
Will not go in detail about the device being housed inside the AE-DC1, as it is all discussed on my web page linked above. All that we have to understand at this moment is the two inputs ENABLE and PHASE.
Enable is basically the ON switch on this device. If ENABLE is asserted, the motor receives current. If ENABLE is not asserted, then the motor stops receiving current and it eventually stops. PHASE then decides the direction of the current flow. One value of PHASE will make the motor move clockwise and the other value will make it rotate counterclockwise.
This posting is not about direction, but about speed. And how do we do that? Is there a speed control input on this device? There is and there isn't.
In order to control DC Motor speed, we need to vary the voltage. If a motor moves at 1000 RPM (revolutions per minute) when we apply 12V, then it is safe to assume the speed will be close to 500 RPM if the applied voltage is 6V (this of course depends on how linear is the motor speed response with regards to voltage).
But if our battery power is pretty much constant, how do we vary the voltage the motor sees (i.e. a lead acid battery is 12V)? As I specified earlier, ENABLE is the ON/OFF switch. What I have not specified is that if I were to toggle this switch on a continuous basis, the motor would see a voltage proportional to how much time the motor is ON with regards to how much the motor is OFF.
In other words, if my motor is turned ON half of the time and OFF the other half, then the average voltage the motor would see is half of the input voltage and it would move at half the maximum speed.
Which brings us to PWM...
The idea is then to apply a signal at the ENABLE input such that the motor is ON and OFF an amount of time that gives us the output voltage we want. The signal in question is a square wave with variable ON and OFF time. We call this signal, a Pulse Width Modulated signal.
The square wave is said to be modulated in pulse width because we will change how much it is ON and how much it is OFF. This is done so that the total time T is always equal to the sum of TON and TOFF, and T is constant. By this I mean that whatever time we give TON, we must subtract to TOFF and viceversa.
The ratio of how much the time is ON to OFF is important as this is directly proportional to the output voltage on our H Bridge. We call this ratio, the Duty Cycle % (DC%). The equations to understand are:
The first equation defines Duty Cycle as the ratio of TON to total T. Since this is a number smaller than 1, it represents which fraction of the total applied voltage will be available at the motor. This is stated at the second equation where VOUT is the voltage at the motor and VBB is the applied voltage at the H Bridge high side.
Putting all of the components together, we can now look an example. If I apply a PWM signal to my AE-DC1 controller ENABLE input, and the Duty Cycle was 33%, I would see a third of my input voltage at the motor. Since VBB is being applied, the motor sees a third of VBB. Going with numbers, if VBB was 12V, the motor would in reality see 4V and would move at the speed as if 4V had been directly applied (of course losses through the H Bridge must be taken into consideration, but we will worry about this later).
Frequency of PWM:
A new question arises: how fast do we switch ON and OFF this motor? In other words, what is the frequency of the PWM? (frequency of the PWM is the inverse of T or 1/T) I will make this a different post as there is a series of issues we should look into. But in the mean time, feel free to use anything larger than 20 KHz and not faster than 200 KHz. I Promise I will explain why...