AN-026: Programmable Adaptive Microstep Table
Microstepping
While stepper motors conventionally have been operated in audible and tangible (half- and full-) steps, they have been loud and prone to resonance failure. Thus, the first aim of microstepping is the reduction of resonance and operation noise. Aside from this, microstepping drastically improves the position resolution. A sine wave is a good solution for reaching an excellent microstepping in many respects: sine wave and cosine wave cause constant power dissipation in the motor. So, the motor can be operated at its maximum thermally limited power, independently of the position within the waves.
Finding the best waveform for a given motor
Normally, there is no specific data available for the stepper motor series. A motor can be optimized for best microstepping or for highest torque, or for a certain form factor or tooling. The specific waveform can be best optimized when using a high-resolution encoder or a laser pointer attached to your motor and moving the motor at very low velocity.
Aims of the optimization
- even distribution of microsteps
- constant velocity at slow speeds
- constant torque independent of position
Motor Dependence
As a first step, you should understand which parameters have a direct or indirect influence on the microstep performance.
Parameter | Description | Optimization |
Motor type | Each motor type has unique characteristics of its microstep behavior. The form of the pole shoes has a major influence on the back-EMF of the motor and hence on the required microstep wave. | Choose a motor fitting your requirements based on the motor torque curve, cost, current, etc. The motor should be strong when compared to mechanical friction or ripple torque (which could be caused for example by a gearing or by a belt drive) in the application, as friction will cause position offset and ripple torque will cause position failure. |
Production tolerance | The manufacturer’s tolerance when assembling the motor, especially the exact angle of the rotor magnets has an influence on the microstep quality. | You should test with several motors to get an idea of production stray. |
Motor coil current | Normally, stepper motors work best at their nominal current, as they provide the highest torque and lowest relative torque ripple. However, factors which might lead to operation at reduced current levels are:
|
As a guideline operate a stepper at 50% to 100% of nominal current. Optimize the microstep curve for the motor current, where precision or smooth operation is most critical. |
Waveform | For most stepper motors, a sinusoidal waveform is a good approach. | As a first test, the motor should be operated with sinusoidal microstepping. When the motor shows a pumping effect (e.g., getting slower and faster within each fullstep), an adaptation of the microstep wave will bring improvements. |
Simple Approach for Microstep Wave Optimization
We will optimize the microstep wave table for equidistant microstepping using a simple interactive approach. Therefore, expensive measuring equipment is not required and in-depth data of motor physics is not needed. Torque variation of the motor is also not considered. This approach just compresses and drags the sine wave to yield an evenly distribution of microsteps. With the next step, the amplitude can be optimized in order to give a constant torque independently of the position.
Tuning the motor position
Take your motor into operation at nominal conditions. In case your appliance does not directly allow assessment of the microstepping equidistance, you can attach a needle to the axis. A very good means is a tiny laser pointer, because of the optical amplification to a near wall. If available, a high-resolution encoder can be used even for automatic tuning of the microstep wave.
- Be sure to first tune the chopper parameters and motor current setting. Bring the motor into very slow rotation, e.g., a few microsteps per second. Check the quality of the microstepping using the needle or the laser pointer. You will probably see deviations from the optimum, equidistant stepping. Start with a sine wave.
- If you use a laser pointer pointing to a distant wall, attach a scale to the wall. You can design the scale in a way that it divides the distance of two fullsteps into a number of equidistant steps. Position the first fullstep corresponding to the 0° position at table position 0, and the next fullstep to the 90° position at table position 256. You do not need to use each microstep position in between for checking, in case you work with high resolutions like 256 microsteps. A good result will already be achieved when you optimize the positions for 8 or 16 evenly distributed microstep positions and later on evenly distribute the remaining microsteps in between. The first and last positions are fixed to the original values at 0° and 90°, as they mark the original fullstep borders. You can do the same using a high-resolution encoder.
- Now, position the motor as exactly as possible to each of the equidistant steps (P1, P2 …) using the highest available microstep resolution (256 microsteps). Take into account that motor friction might influence the exact positioning. Multiple trials will help reduce errors caused by friction. Take note of the microstep pointer (MSCNT) for best position match for each position (shift each position as required).
- Now you have a lookup-table (shifted positions for blue trace in Figure 1b) which allows exact positioning to the determined values. The sine values at the noted MSCNT positions, which are required to exactly reach the desired microstep positions, are the optimized entries for these microstep positions. You can do an interpolation between each two entries to extend the microstep curve to the original table resolution, (e.g. to 256 microsteps). For this task, a spreadsheet may be helpful.
Note: the angle between the laser pointer and the scale on the wall can be neglected because of slightness, except for very low-resolution stepper motors.
Optimization of the torque
Now the optimization of the torque can be done. This will help the motor to keep equidistant positions when it is loaded with a certain torque. This optimization step requires more measuring equipment and can best be realized in an automatic setup. An encoder coupled to the motor can be used for torque measurement by superimposing a step (e.g., 90° electrical angle) on the motor and measuring the instant acceleration of the motor.
The positions have been compressed and dragged in the previous step (horizontal arrows in Figure 1b). Now the amplitudes become scaled in the same way (vertical arrows in Figure 1d). While scaling the wave, keep in mind that the drivers optimally work when sustaining the peak amplitude at the maximum permissible level (248). A second iteration of both steps might still give improvements, as there is a small dependence of the position from the absolute current level, due to the motors’ residual torque.
Programming the Incremental Microstep Table
For understanding the background of the incremental coding of the microstep table, it is good to have an idea of the characteristics of the microstep wave.
A microstep table for a two-phase motor has certain characteristics:
- It is in principle a reverse characteristic of the motor pole behavior.
- It is a smoothened wave to provide a smooth motor behavior. There are no jumps within the wave.
- The phase shift between both phases is exactly 90°, because this is the optimum angle of the poles within the motor.
- The zero transition is at 0°. The curve is symmetrical within each quadrant (like a sine wave).
- But it must not be strictly monotonic as the example in the previous chapter shows.
Due to these characteristics, the wave can be described by a one quarter period and there is only a certain change possible between two adjacent positions. Following point 4, the slope of the wave is normally positive, but due to torque variations it can also be (slightly) negative.
Considering these facts, it becomes clear that the wave table can be compressed. The incremental coding used in the ADI TRINAMIC ICs uses a format which reduces the required information per entry of the 8 bit by 256 entry wave table to slightly more than a single bit.
Incremental Encoding
The principle of incremental encoding just stores the difference between the actual and the next table entry. To have an absolute start value, the first entry is directly stored (START_SIN). For ease of use, the first entry of the shifted table for the second motor phase is also stored (START_SIN_90_120). The TMC drivers provide four inclination segments (0, 1, 2, and 3) with the base inclinations (W0, W1, W2, and W3) and the segment borders (0, X1, X2, X3, and 255).
Inclination segments | Base inclinations | Segments |
0 | W0 | 0… X1 |
1 | W1 | X1… X2 |
2 | W2 | X2… X3 |
3 | W3 | X3… 255 |
Explanatory notes and examples:
Using a single bit per table entry would allow any inclination between 0 and 1. For example, a 0-bit could mean do not add anything and a 1-bit could mean add one. This allows describing a digital slope of 0° (all bits zero) to 45° (all bits one).
It becomes clear that higher inclinations are necessary. However, the inclination will not drastically change from point to point. Therefore, the wave can be divided into up to four segments with different base inclinations.
Using a base inclination of one, a 0-bit would mean add one and a 1-bit would mean add two. This way, a slope between 45° (all bits zero) and 77.5° is yielded (all bits one).
The base inclinations can be set between -1 (falling slope) and +2. This way, slopes between -45° and 78.75° can be described. The default sine wave table in ADI TRINAMIC drivers uses one segment with a base inclination of 1 and one segment with a base inclination of 0.
Example (compare spread-sheet TMC562_TMC50XX_Calculations.xlsx)
Consider the given conditions:
The microstep table for the standard sine wave begins with the eight entries (0 to 7) {0, 1, 3, 4,
6, 7, 9, 10 …} etc.
The maximum inclination in this area is 2 (1+2=3).
The minimum inclination in these eight entries is 1.
The start value is 0.
Advancing in the table, the first time the inclination becomes lower than +1 is from position 153
to position 154. Both entries are identical.
The calculated value for position 256 (start of cosine wave) is 247.
Therefore, the following settings need to be made:
- Set a starting value START_SIN=0 matching sine wave entry 0.
- Set a base inclination range of W0: +1 / +2 (W0=%10), valid from 0 to X1.
- Calculate the differences between each two entries: {+1, +2, +1, +2, +1, +2, +1,…}
- Set the microstep table entries ofsxx to 0 for the lower value (+1), 1 for the higher value (+2). Thus, the first seven microstep table entries ofs00 to ofs06 are: {0, 1, 0, 1, 0, 1, 0 …}
- Latest at position 153, the inclination must be lowered. Use the next inclination range 1 with W1: +0 / +1 (W1=%01). Therefore, X1 becomes set to 153 in order to switch to the next inclination range. Thus, starting from position 153, an offset ofsxx of 0 means add nothing, 1 means add +1.
- START_SIN90_120 becomes equal to the value at position 256, i.e. 247.
- As the wave does not more have segments with different inclinations, the remaining inclination ranges W2 and W3 shall be set to the same value as W1, and X2 and X3 can be set to 255. This way, only two inclination segments are effective.
Overview Of Example | ||||||||||||
Microstep number | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ... | 153 | 154 | ... |
Desired table entry | 0 | 1 | 3 | 4 | 6 | 7 | 9 | 10 | ... | 200 | 200 | ... |
Difference to next entry | 1 | 2 | 1 | 2 | 1 | 2 | 1 | ... | ... | 0 | ... | ... |
Required segment inclination | +1 | +1 | +1 | +1 | +1 | +1 | +1 | ... | ... | +0 | ... | ... |
Offs bit entry | 0 | 1 | 0 | 1 | 0 | 1 | 0 | ... | ... | 0 | ... | ... |