Controlling stepper motors

Last modified: 23rd January, 2003

I'll be filling this page out with additional details as I get further into the design and construction of the control system. Check back every now and then!


Table of contents

On the stepper motor controllers
Using a simple commercial stepper motor controller
Designing my own microstepping controller


On the stepper motor controllers

My approach to stepper motor control changed after I decided to build a Cookbook CCD camera......

For telescope applications, by far the most common and cheapest stepper motors provide 200 steps per revolution (400 half steps per revolution). Of these motors, it seemed that the most common shaft diameter is 1/4 inch (6.35 mm). When you roll the motor shaft against the telescope bearing, the motor needs to turn many times in order for the bearing to turn once and in this way, the arrangement behaves a little bit like a small ratio gear. Because my two side bearings have a diameter of 16 inches (400 mm), the ALT stepper needs to make 63 revolutions to move the telescope through 360 degrees. Saying this another way, my design results in approximately 25000 half steps per revolution with each half step moving the telescope about 50 seconds in the ALT axis.

For visual observing, this coarseness is OK. Although the step size is coarse, the inertia of the telescope tends to smooth the movement and your eye doesn't notice. However, coarse steps are not appropriate when using a CCD camera (for long exposure photographs) because the CCD pixel size is considerably smaller than the step size and coarse steps blur the photograph horribly.

Ultimately, I faced up to the reality that my 25000 half step per revolution design was not sufficient for CCD imaging and I have started work on a hopefully more accurate microstepping design. Never the less, most amateur astronomers do not care about CCD imaging and the simplicity and reliability of coarse stepping will be fine.

Using a simple commercial stepper motor controller

When I went shopping for components, I obtained my stepper motors and stepper motor controllers from All Electronics in California. I purchased a few of their reasonably priced 200 count per revolution or 1.8 degree per step motors (which provide 400 half counts per revolution or 0.9 degree per half step) and two EDE-1204 stepper motor controller chips.

Whatever stepper motors you end up purchasing, make sure that they are sufficiently powerful (large enough) to directly drive your telescope. Anything rated at around 3 to 5 Watt per winding should be OK for a moderate Dob (providing that it is well balanced). Smaller stepper motors will only provide satisfactory performance when used with a geared arrangement.

The circuit I implemented using the EDE-1204s closely followed the example shown on page 5 of the data sheet. The EDE-1204 has two modes of operation: a "run" mode in which the chip itself generates steps or half steps and a "step" mode in which you generate steps under software control.

The "run mode" of the EDE-1204 is good when you want to generate high step rates, (up to thousands per second such as when slewing the telescope) because it is important that the steps are evenly spaced at all times and the EDE-1204 does a good job of this. Trying to ensure evenly spaced steps places an onerous burden on a processor when the step rate is high because there are often many other tasks which need to be performed at the same time.

The "step mode" of the EDE-1204 is good when you're tracking an object across the sky because the world doesn't turn very quickly and the software can better generate the accurate step frequency you need for this task. To track the sky using one-arcminute sized steps, the telescope needs only step every few seconds or so depending upon where it is pointed.

Alas, I now need more accuracy so that I can use my CCD camera.

Designing my own microstepping controller

When I first started to look at options for telescope control, I found many Internet references to microstepping. I'd found a lot of information about microstepping on Mel Bartels' stepper motor page but at first glance, microstepping appeared complicated. Mel's system is designed to use a PC to control the microsteps but I planned to use a very low end microcontroller and I did not think that a microcontroller would be up to the task.

Never the less, necessity is the mother of invention. Now I have the problem and have to solve it.

Short of modifying the mechanics of my telescope to add gear boxes to the ALT and AZ drivers, I know of no other option than to micro step. Knowing that my microcontroller will not be equal to the task of controlling microsteps in software, I wondered about how difficult it would be to implement microstepping in hardware. The basic objective of hardware microstepping is to provide a minimum number of controls from the microcontroller and to have the hardware generate the microstepping waveforms of its own accord.

So what are the controls? I imagine three control lines for the ALT and another instance of the same three for the AZ. This is simpler than for the EDE-1204!

At 64 microsteps per step, my Alt bearings would be operating at more than 800k steps per revolution or 1.6 arcseconds per step. Due to inaccuracies in the stepper motor itself, the absolute accuracy of the approach would not allow me to achieve precisely 1.6 arcseconds per step however I think it reasonable to expect significant CCD performance when compared with the original half stepping approach.

The microstepping circuit

After putting in a little thought, I realised that a hardware microstepper might not be as complicated as I had first imagined. Eight chips will do it as shown below.

Circuit diagram to be added soon.

Two such circuits are required: one for the Alt axis and the other for the Az.

The circuit warrants a little explanation. But firstly, I need to say some things about stepper motors themselves.

The stepper motors I used are called bi-polar and have two electromagnets arranged in an overlapping way around the circumference of the motor so that there are many electromagnetic poles. By energising the two electromagnets in sequence and by carefully choosing which direction the current will flow in each coil, the shaft of the motor can be turned one way or the other in small but very well defined increments. The greater the number of magnetic poles around the circumference, the smaller the steps. This is the normal way to use stepper motors, (with DC voltages that are either on or off) however stepper motors can also be energised with AC or PWM-DC voltages. Microstepping uses PWM-DC voltages.

Before looking at microstepping though, let's look at the simplest case: full stepping. When full-stepping, we either power each electromagnet one way, or the other way, or not apply power at all. When full stepping, only one of the motor's two electromagnets receives power at a time.

Here's a sequence showing four full steps....

Electromagnet   stage   stage   stage   stage
   number         1       2       3       4

     1            +      off      -      off
     2           off      +      off      -

+ means current flowing in one direction
- means current flowing in the opposite direction

To turn the motor in one direction, you energise the electromagnets using the sequence 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, ... and so on. To turn the motor in the reverse direction, you follow the same sequence but in reverse (4, 3, 2, 1, 4, 3, ...).

full stepping sequence

This funny circular diagram represents the "electrical angle" rather than the shaft angle. What it shows is that in order to make four full steps, the electrical angle (the virtual angle formed by the currents in the electromagnets) travels through 360 degrees.

Four steps of the shaft using a 200 step per revolution motor corresponds with only 7.2 degrees of shaft motion. You can't see this in the diagram and it's not supposed to show it!

Half stepping is a simple variation of full stepping. When full stepping, we ensured that only one of the two electromagnets received power at a time. To half step, we need to add some additional stages in which power is applied to both electromagnets simultaneously.

If we needed four full steps to rotate 7.2 degrees, we will need eight half steps to rotate the same angle. However, remember that 360 electrical degrees is still the same as four full steps (eight half steps)....

                 half    half    half    half    half    half    half    half
Electromagnet   stage   stage   stage   stage   stage   stage   stage   stage
   number         1       2       3       4       5       6       7       8

     1            +       +      off      -       -       -      off      +
     2           off      +       +       +      off      -       -       -

+ means current flowing in one direction
- means current flowing in the opposite direction

When two electromagnets are on at the same time, the shaft will try to position itself between the two electromagnets rather than fully align itself with one or the other.

half stepping sequence

There are twice as many points on this diagram of electrical angles so the steps are half the size.

Using DC voltages (either on or off), our 360 electrical degress can only provide us with eight half steps. In order to microstep a stepper motor, we need to progress towards AC voltages.

What would happen if we used a sine shaped voltage on one coil and a cosine shaped voltage for the other? (The cosine voltage shape happens to be 90 degrees ahead of a sine voltage). It turns out that the motor would cease to step and instead would smoothly rotate, just like any other conventional motor. Pure sinusoidal voltages therefore make a stepper motor behave as if it's following an infinite series of microsteps. The speed at which the stepper motor rotates is precisely locked to the frequency of the two sinusoidal voltages. In fact, not only is the speed locked, but the position of the shaft of a stepper motor is locked also. These properties are what make stepper motors interesting for computer control applications.

Think about what happens when we arbitrarily make the frequency of these sinusoidal voltages lower and lower. The shaft of the stepper motor will turn slower and slower but will still remain precisely locked to the phase angle of the sinusoids. When the frequency drops so low that we can effectively think of it as being stopped, the shaft of the motor will stop too, locked in place.

When we use steppers in our telescopes, we need to perform fast slews and also achieve precise tracking. In order to do a fast slew across the sky, we'd quickly increase the frequency of the sinusoids to many kHz and the motors would then turn quickly. To slow down, we'd reduce frequency and to track the sky at normal rates, we'd use very low frequency sinusoids.

Generating and controlling smooth sinusoidal waveforms of arbitrary frequency using a computer is not exactly straightforward. However, it is relatively simple to generate PWM (Pulse Width Modulated) waveforms. The design shown in the circuit above uses a switching (or sampling) frequency of around 1 MHz and a PWM cycle of 256 samples. This means that PWM frequency ends up at around 4 kHz. Compared with the control waveforms generated in the Bartels controller (which are not a sinusoidal / cosinusoidal pair), the ones from my circuit should result in more accurate motor control, but will this result in better telescope performance?

Yes and no. Maybe.

The accuracy of any electro-mechanical telescope control system will depend upon both the accuracy of the electronics and software and the precision of the electro-mechanical system. It is feasible to build very precise electro-mechanical systems and control them the Bartels way and I think that most Bartels based designs are like this. Clearly, many builders seem to be happy with the overall performance of the Bartels system and I do not want to dispute this.

Overall, I think that my less accurate mechanical performance coupled with more accurate electrical performance may perform in a similar ball park as a typical Bartels implementation. The real question however will be whether it is enough for doing CCD work!

Apart from greater stepper motor accuracy, I think that another significant advantage of using a hardware microstepping approach is that the demands on the software and the microcontroller can be substantially reduced. In other words, a hardware microstepping approach does not require a fast microprocessor with highly accurate software timing loops in order to precisely control the stepper motor. Never the less, this is purely design talk at present and I have yet to build and test it.

Back to the circuit diagram

I introduced the circuit diagram above but have not yet described its operation. You will notice that the entire circuit consists mainly of counter chips, latches and an EPROM. Almost all of the transistors and other passive components form the H-bridge driver which applies power to the electromagnets of the stepper motor.

There are two eight bit counters in this design, (one set of eight bits being separately latched) and the combined total of 16 bits are used as address lines for the EPROM. With 16 address lines, the EPROM is a 64k device. The latched counter bits represent the phase angles of the microstep: 256 evenly spaced angles covering 360 electrical degrees (or 4 full steps) implies a resolution of 64 microsteps per step. The remaining eight counter bits represent 256 different PWM output samples for each of the microsteps (i.e. different timings to use for the H-bridge control lines). Thus the EPROM is divided into 256 microsteps and each microstep is built from 256 samples.

The latched eight bit counter (which holds the microstep phase) is an up/down counter. When counting "up", it follows the sequence ...., 253, 254, 255, 0, 1, 2, 3, .... and when counting down, it follows the sequence ...., 3, 2, 1, 0, 255, 254, 253, .... The telescope's microcontroller is responsible for setting the up/down control line and then pulsing the step line in order to rotate the stepper motor one way or the other.

The second eight bit counter is a free running counter clocking at around 1 MHz and is used to sweep the PWM cycles. This second counter only counts in the up direction, ...., 253, 254, 255, 0, 1, 2, 3 ..... Because it clocks at 1 MHz and there are 256 counts, the rate at which the PWM cycle repeats will be 1 MHz / 256 or around 4 kHz.

There are two PWM waveforms generated from the EPROM, one for each of the two electromagnets in the stepper motor. The purpose of using PWM is to obtain an average voltage so for each of the microsteps we want to simulate, these 256 intervals being clocked out from the EPROM will generate two different average voltages with which to power our stepper motor.

Let's imagine that the telescope microcontroller has stopped stepping for the time being. This means that the value of the up/down counter representing the microstep phase will be static. Independently, the value of the up counter will be quickly cycling through its 255 values generating PWM waveforms at 4000 cycles every second. The average voltage (and thus current) through the two stepper motor electromagnets will be static and so the stepper motor will be stationary. However because we're generating PWM, those average voltages / currents can be any fraction between full current in one diection, zero current and full current in the opposite direction.

If we send a single step pulse to the circuit, the microstepping up/down counter will either increment or decrement and a different set of 256 PWM intervals will start to be sampled out of the EPROM. [The EPROM must have 256 different sets of 256 values, or 256x256. If you multiply this, that's 65536 values which happens to be "64k" in computer speak.] So by incrementing or decrementing the value of the microstepping counter, the average voltage / currents to the two electromagnets can be set at new values because we are now reading a different set of 256 values from the EPROM.

By modifying these average voltages / currents through the electromagnets a little, the shaft of the stepper motor will turn fractionally one way or the other; it will microstep. Now for as long as we keep the microstepping up/down counter static again, the stepper motor shaft will also be stationary, but now at a slightly different position than it was before.

Recall that in order to rotate the stepper motor in a smooth circular motion, we need to apply a pure cosine waveform to one electromagnet and a pure sine waveform to the other. In this circuit, we get the motor to rotate by sending a continuous set of evenly spaced pulses on the "step" control line. As the microstepping up/down counter cycles through its 256 possible values, the PWM counter is independently cycling through its own 256 values but at a very much faster rate.

Whooooa. That was a little fast! Did I lose you?

As a postscript, I found a datasheet for a commercial microstepping controller which provides quite a deal of useful information. You can check out the IXMS-150 data sheet by clicking on the link.


Contact me
Return to my design notes page.
Return to my telescope page.