Sunday, January 11, 2009

Getting deeper into DC Motor Speed Control

DC Motor Speed is directly proportional to applied voltage.

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...

Sunday, January 4, 2009

Overall Motion Control

You have a motor, such as a permanent magnet DC motor found on toys, and you know that if you connect said actuator to a battery or some power source, the motor shaft spins. This mechanical spin is used to move your RC car wheels, spin the DVD player media disc, spin the metal disc on Hard Disk Drives, spin your clothes on the washer and drier, spin the auger that in turns deliver ice at your refrigerator with an ice maker, moves arms and legs on toy or industrial based robots, allows for your e-bike to run without pedaling and your scooter to move forward without kicking and pushing, opens your garage gate, etc.

Motors are everywhere! Are very useful and not so hard to use. But how does a system using motors work? What do we need to understand in order to get me some motors working properly on my next cool application?

Most motor applications use a very simple implementation I like to call Power-Amplifier-Motor (Lets call it PAM). With PAM systems, there is a power source (either a battery or wall outlet derived power supply), which delivers power to the motor. How much power and how fast is this power delivered to the motor is controlled with the amplifier. The amplifier is often an H Bridge power stage often called the Power Driver which is then controlled by some form of logic (FPGA or Microcontroller).





The amplifier receives weak signals from some sort of controller, let say the remote control receiver on your RC car, and then transform this input command into a much more powerful signal the motor can use to move accordingly. As a result, the weak signals from the remote control will translate to speed and direction on your RC car. The same applies to practically every other application using this simple method of interfacing.

There are some other applications, however, which require a degree of control totally different than the RC car example. In the RC car, you apply the control. If you want the car to move faster, you move the lever further. If you want the car to move slower, you retract the lever. How much you move the controlling lever translates into how fast the car moves. But what happens when a human can not be employed at all times to control the speed of the motor?

Per example, on your washer and drier, the idea is for no humans to be involved. If we had to control the speed of the motors, we might as well wash our clothes by hand! We want this machine to do all the job and for us to return later when the task at hand is complete. In this case, we need a controller that can close the loop. These systems are often called Closed Loop Motor Controllers (CLMC) and their level of complexity can range from very simple to considerably much more complicated than the PAM case.




CLMC's can be as complicated as to require the use of an entire computer to derive said control. Per example, industrial robot applications utilize very powerful computers to make sure every single detail of the motion control is performed to perfection, improving both accuracy and precision.

On this blog, I will eventually detail aspects that can be used to work on highly complex CLMC's, but we will get busy with the simple PAM's first. Later we will add some simple Closed Loop mechanism as said approach is more than enough to tackle a great deal of the motor control applications out there.

H Bridge Basics

To control a DC motor, you will most likely use an H Bridge power stage. It is called an H Bridge because the four switches and the motor, when wired as shown on the picture, look like an H.



Why do we need four switches? In reality, we only need one switch to turn the DC Motor On and OFF. Applications where this is all that is needed, will happily use a single switch and move on. However, the great deal of applications out there not only require the control of On and Off, but also of direction. For this purpose, a single switch is no longer enough.

At first it may be apparent that two switches should suffice. However, a carefull look will show this is not the case. Since we must apply both a GND connection as well as a positive voltage (VBB) connection to either of the two DC Motor terminals, four switches are the bare minimum. This configuration guarantees that each terminal on the DC Motor has access to both GND and VBB.

In order for the DC Motor to move in one direction, voltage of one polarity is applied. If the opposing polarity is applied, then the motor spins in the opposing direction. Hence, the importance of being able to apply two voltage polarities to the same motor.



The picture above shows how this is attained. If we turn switches Q1 and Q4, current flows from the left terminal on the motor, to the right terminal on the motor (left side of the picture). This results in the motor turning clockwise. If on the other hand we enable switches Q2 and Q3, then current flows from the right motor terminal to the left motor terminal, resulting on a counterclockwise motor shaft rotation.



Care must be taken so that VBB is never connected to GND as this is a hard short and it will most certainly destroy the power source along with the switches. An event in which switches are connecting VBB to GND is called Shoot-Through. Either enabling switches Q1 and Q3 or switches Q2 and Q4 at the same time, would result in Shoot Through. Shoot Through HAS to be avoided at all cost. Proper H Bridge design will take this important aspect into consideration and will later play a role with how fast the switches can be closed and opened.