A simple algorithm for microstepping a bipolar stepper motor

Jose Quinones, Texas Instruments

July 11, 2011

Jose Quinones, Texas Instruments


In actuality, to control any bipolar stepper we need two signals as there are two phases: PHASE A and PHASE B. Luckily, if PHASE A is a sine wave, PHASE B is the same sine wave, but with 90 degrees worth of phasing. In other words, if PHASE A is a sine, PHASE B is the cosine. It may seem like we need two tables, but the very same table can be reused.

As the 16-step deep table is used to generate the PHASE A sine wave, we can offset the lookup table index by eight and fetch the values that generate the cosine wave shape. For example, it looks like this in pseudocode:

#define TABLE_DEPTH	16
VREF_PHASEA = LOOKUPTABLE[INDEX]
VREF_PHASEB = LOOKUPTABLE[(INDEX + TABLE_DEPTH / 2) & (TABLE_DEPTH-1)]
Increase INDEX


Notice that for the PHASE B index we must normalize it to the table size. If the table value being fetched for PHASE A is the element #15, we do not want to fetch element #23 for PHASE B, as this would be outside of the table space. We want to fetch element #7. Anding the lookup table index by the table size minus one results in the correct normalized value. I often refer to this anding element as the INDEX_MASK.

We have discussed how to fetch the current magnitude information from the lookup table, but what about the phase information? Should we store this in the table as well? If so, then the table space needs to be four times as large as the number of current settings we want per step, right? Actually, this is not necessary as the PHASE information can be derived from the INDEX variable itself.

The INDEX value goes from 0 to the TABLE_DEPTH – 1 value. But, if we let the INDEX go from 0 to twice the TABLE_DEPTH, we can then use the resulting number’s most significant bit information as the PHASE polarity. Take for example our eight degrees of microstepping scenario. In this case, TABLE_DEPTH is equal to 16, but we will let index run from zero to 31. This changes the index masking strategy as we need a mask for the phase information (PHASE_MASK) and another mask for the lookup table fetching procedure (INDEX_MASK). The pseudo code now looks like this:

#define 	PHASE_MASK 		0x10
PHASEA = INDEX & PHASE_MASK
PHASEB = (INDEX + TABLE_DEPTH / 2) & PHASE_MASK

Notice that we don’t care about wrap up on the INDEX value when deriving PHASE information as the meaningful most significant bit (MSB) will always be toggling. In other words, bits above the MSB are completely ignored, whereas bits below the MSB are used as lookup table index to extract current magnitude information.

#define		TABLE_DEPTH	16
#define		INDEX_MASK	TABLE_DEPTH - 1
VREF_PHASEA = LOOKUPTABLE[INDEX & INDEX_MASK]
VREF_PHASEB = LOOKUPTABLE[(INDEX + TABLE_DEPTH / 2) & (INDEX_MASK)]
INDEX = INDEX + IndexIncrement

We changed the way in which the index is incremented. The truth is there are times when we will not want to increment the index, but actually want to decrement it. The reason for this is that by walking through the lookup table we can also derive direction of rotation information. In other words, if we walk forward through the table, then the motor moves clockwise, but if we walk backwards through the table, the motor then moves counterclockwise.

Here we describe the logistics behind the code we will implement to use the lookup table. A hardware ISR is used to acknowledge the step command. It can be a timer input capture or a general purpose input output (GPIO) configured to interrupt. You must choose whether you want the step command to be recognized on a rising edge, falling edge, or both. Every time such a transition is registered, the code specified above will be executed.

A second ISR takes care of the rotation direction request. Again, it can be any form of hardware input which grants an interrupt on a transition, except in this case it must react to both rising and falling edges. If a rising edge is registered, the index increment is set to +1. If the falling edge is registered, then the index increment is set to –1.

As you can see, the level of simplicity to turn your stepper driver into a microstepping commutator is considerably simple, with the amount of code executed per microstep being fairly small.

Simple fix
Using a microcontroller or a DSP to embed microstepping information on the conventional full-step commutation algorithm is a simple mechanism to fix the resonance problem. Because microstepping is achieved with software rather than hardware, the levels of flexibility are appealing to this kind of implementation. You can use any wave shape the design requires. Degrees of microstepping can grow from small resolution to very high resolution, with up to thousands degrees of microstepping being used on applications requiring a very soft motion profile.

Jose Quinones is a motor control applications engineer at Texas Instruments where he is involved in aiding developers in implementing design based on power devices for implementing microstepping such as the DRV8812/8813 and DRV8824/25. He received a B.S. in electrical engineering from the University of Puerto Rico and spent five years developing motion control embedded systems for Xerox Corporation (for which he has two patents) before joining TI. Jose can be reached at ti_josequinones@list.ti.com.
< Previous
Page 3 of 3
Next >

Loading comments...

Most Commented

  • Currently no items

Parts Search Datasheets.com

KNOWLEDGE CENTER