Steppers with Encoders: When Open-loop Control Isn’t Enough

With the increasing popularity of DIY projects such as quadcopters, CNC tables and 3D printers, many people are faced with the decision of which type of motor to use in their project. For applications that require precise control of the position of the motor, the common choices are DC motors with encoders, servo motors, and stepper motors.

A DC motor is the standard electric motor; it will spin as fast as it can with the DC power you provide it with. On its own, a DC motor has no position control. Most DC motor controllers allow you to change the duty cycle, a value from 0 to 100% that describes how much of your power supply is being made available to the motor. However, controlling the duty cycle does not give you control over the position or even the velocity of the motor. This is where encoders come in:  an encoder typically attaches to the rear shaft of your motor, and it measures the actual position of the motor and sends this information to your system. Now you can have real position control, because your system can easily calculate how far it needs to turn the motor in order to make the current position equal to the desired position.

The insides of a typical servo motor. On the bottom, a 2-wire DC motor. On top, a circuit board that runs the control system and interprets servo commands.

The insides of a typical servo motor. On the bottom, a DC motor. On top, a circuit board that runs the control system and interprets servo commands.

A servo motor is just a DC motor with some upgrades: they typically have a gearbox to increase output torque, and they have a control system built right inside the motor’s casing. Since all of the control is built in, you can simply tell a servo to rotate to a specific angle, and it’ll try its best to move to that position. The downside to an integrated control system is that you usually can’t customize it in any way.

A stepper motor uses alternating current through two separate coils to turn the rotor. I won’t go into the details, but the end result is that the motor moves in distinct “steps”, and the angle of these steps can be calculated from the step angle listed on the motor’s datasheet and the gearbox reduction ratio, if it has a gearbox. Since the motor turns a known amount each time a step is made, the position and velocity can be calculated.

Now, in some situations, customers have used stepper motors with attached encoders. You may wonder, why on earth would you add position control to a motor that already has position control? As the title of this blog implies, this is the question I’ll answer today.


Open-loop Position Control with a Stepper Motor

First, let’s take a look at what the control system looks like on a stepper motor without an encoder. Suppose you want the stepper to make one complete rotation. Your program knows your motor’s step angle is (for example) 1.8°, so it tells your controller to move 200 steps clockwise. The controller tells this to the driver chip, and the driver chip outputs the power signals that turn the motor. Next, suppose you want the motor to turn half a rotation counter-clockwise from it’s original starting location. Your program remembers the motor is 200 steps away from the starting position, so it tells the controller to move 300 steps counter-clockwise, and so on.


This is known as open-loop control. You have precise control over the position of the motor, but only under the assumption that the motor has physically done exactly what it’s been told to do. If the motor takes an extra step due to excessive inertia, if the motor stalls, or if you’re using a gearbox that has significant backlash, your program’s assumption of the motor’s current state will be wrong.


Closed-loop Position Control with a DC Motor and Encoder

Now we’ll look at the control system that results from using a DC motor and encoder. Suppose you want the motor to make one complete rotation. Your program tells the controller to move at 100% duty cycle. The motor starts moving, and as it does, the encoder updates your program with the motor’s current position. The program then re-evaluates the situation and tells the controller a new duty cycle.


If your program is clever, it can adjust the duty cycle to gradually decrease as you get closer to your target position (this sort of control could be achieved with a PID control loop). If an external force were to stop the motor, your encoder would indicate to your program that the motor has stopped moving, and it could increase the duty cycle or activate another system designed to take care of the problem. This type of control is called a closed-loop controller, because the actual output of the system constantly loops back into the calculation that determines the future output. By installing an encoder onto your stepper motor, you can create a similar closed-loop system with all of the same benefits of a stepper motor. If the motor stalls and desynchronizes with the controller, you can restart it. If you miss steps or take too many, they can be accounted for instead of accumulating over time. If your gearbox backlash introduces a few degrees of error after a number of rotations, that error can be eliminated with an encoder.


Why Use a Stepper Then?

Now that we’ve determined that both DC motors and stepper motors have closed-loop control when used with an encoder, why would we want to use a stepper at all? While they both have the same level of control once you install an encoder, they are still very different in terms of operation. Stepper motors are better for applications where the motor needs to hold position while still providing full torque; a DC motor could do this, but it would be very bad for the motor’s lifespan. Even with an encoder, pulling off that kind of precision with a DC motor would be extremely difficult, because a DC motor can’t lock itself into position like a stepper can. Stepper motors are also preferred in applications that require precision, like CNC tables. For some applications, open-loop control with steppers is enough, but if error recovery is important, switching to closed-loop control is worth consideration. On the other hand, applications that require velocity feedback control at high speeds, such as a remote controlled vehicle, would favour DC motors.

Motor selection also depends on many other factors specific to your project. If you need any advice on what sort of motor and what degree of control you need for your project, feel free to contact us or make a post on our forums.

Tagged with: , , , , ,
Posted in Products
12 comments on “Steppers with Encoders: When Open-loop Control Isn’t Enough
  1. Bonn Um says:

    I’m building a simple robotic arm with shoulder, elbow and wrist joints. Which motors do you suggest I use? Am considering using stepper for the base swivel, shoulder and elbow. Then servos for the wrist. My concern now is increasing the steps to move by one degree.

    • phidgets says:

      Steppers and servo motors are similar in operation, so you could probably use either. Both will allow you to have position control, and both come in a variety of sizes. Generally servos are much lighter than steppers, because they don’t need to have heavy magnets in them. For this reason, you may want to use servos as you go further out on the arm. Compact servos are also usually more effective than compact steppers, so if you want to have multiple degrees of freedom on a joint (like a finger), a servo would be the better choice. This is why hexapod robots always use servo motors.

  2. enrikds says:

    Reblogged this on Enrique del Sol – Robotics Researcher and commented:
    It is good to know how to use a stepper..

  3. mrclint says:

    So, I am building a rig that out of necessity must disconnect whatever driver I use (currently a servo), and then reattach it and find the current location stored in the Arduino. Now if I want to switch the servo to a 360-capable driver, how do you propose I do that?

    As I understand a stepper motor doesn’t have a specific “home” or zero, as a servo has, so if I reattach it it won’t know where it is, right?

    • phidgets says:

      That’s right, both 360-degree servos and stepper or DC motors have no way of knowing where they are without extra hardware.

      There are two common solutions to this problem. The first is to install an encoder that has an index channel on the rear shaft of the motor. An index channel will pulse every time the motor has made a complete rotation, so when the program reattaches, you can seek until you find the index. Having an encoder also gives you precise information on what position the motor is in once it has been zeroed, and can also give you very accurate velocity and acceleration data. The second solution is installing some form of physical limit switch that can act as a zero for the motor. For example, you could put a wheel on one of the motor shafts that has a piece of reflective material on the edge, and an IR reflective sensor mounted nearby. This way, when your program reattaches, you can have it seek until it finds the zero. I’ve heard of people using magnets and magnetic sensors for this in some cases.

      • mrclint says:

        Thanks for the answer!
        I read about encoders, and I think the most likely driver is a dc motor with an encoder, mounted on a worm gear. That way I don’t have to know where it is (except in the start), only how far it has to go which the encoder will provide the answer for, and it doesn’t have to be powered all the time.

        Or the more high-tech way of modifying a servo so that I get the readings from it’s potentiometer. =)

        Interesting reading anyway.

  4. Andreas Gabrielsen says:

    Hey, I am building a conveyor belt for a nozzle-testing machine and require a waterproof high precision motor. Both the belt and the machine will be controlled by a PLC. From what knowledge I now pocess (with the help of this page, thanks), I have decided upon a stepper motor. Do you think a step angle of 1,8 is sufficiently precise? To ensure that no errors occur, I think a closed loop control with an encoder is needed aswell. In regard of Bi/unipolar I have no idea, but the ones I have looked into tend to have Bipolar… High speed and strength is not needed.

    • phidgets says:

      Hi Andreas,

      You’ll have to do some math to determine if 1.8° is sufficiently precise, based on how precise the alignment has to be on the belt. The math will be based on the diameter of the belt. If you need more precision, we sell a 0.9° step angle bipolar stepper. You can also use a stepper motor with a gearbox, but I wouldn’t recommend it since most gearboxes can be off by 1-2° due to gear backlash. You’ll definitely want a bipolar motor, since unipolar motors don’t typically come in a size that would be capable of driving a belt. Unipolar motors are often used for very light loads, like the needle on a fuel gauge.

  5. sungho says:

    Are there any ways to get feedback(Actual counts which have moved) from the open-looped stepper motor using ADC function of MCU?

    • phidgets says:

      If you put an encoder on the stepper motor, you can hook up the A and B channels of the quadrature encoder to digital inputs on the MCU. But you’d need some code to calculate the timing and count the pulses to convert the quadrature signal into counts. Alternatively, you might be able to find an IC that will take a quadrature signal and convert it into something more easily read by your MCU.

  6. Abishek says:

    How do I spec an encoder for a stepper motor? Or what is the relationship between stepper motor resolution and encoder resolution? I am guessing the encoder has to be atleast as good as the minimum step size preferably some fraction of that. But what use is an encoder that is say 1/100th the resolution of a stepper motor?

    • phidgets says:

      Most stepper motors without gearboxes have a step angle of 1.8°, and many encoders have a resolution of 360 CPR (or 1° resolution). You can also get stepper motors that have gearboxes attached, which reduce the step angle down to a very small fraction of a degree. However, unless you buy a very expensive gearbox, there will be some backlash (air gap between the gears) which can result in anywhere from 1° to 3° of variance for a given position. For this reason, I would only recommend a gearbox on a stepper motor for the purpose of increasing the torque, not for increasing the precision. For maximum precision, gearless steppers with a step angle of 0.9° are commonly available.

      Even if the encoder has a lower resolution than the stepper, it can still be useful for detecting stalls and at keeping it on track for long runtimes when many missed steps could otherwise add up to a large margin of error.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: