Sub topic 5
Microstepping: smoother motion and its limits
This chapter assumes you know how a stepper motor turns coil pulses into full steps, how full-step, half-step and wave drive sequences work, and basic Arduino programming (digitalWrite, delayMicroseconds). You should also be comfortable with Ohm's law and with reading a motor datasheet.
What microstepping is
Full-step drive energizes both coils at full current, so the rotor jumps between positions 1.8° apart on a typical 200-step motor. Microstepping replaces that jump with a series of smaller moves. The driver changes the current in the two coils gradually, following approximate sine and cosine curves. The rotor settles at a point between the full-step positions, and that point depends on the ratio of the two coil currents.
A driver that divides each full step into 16 parts is running at 1/16 microstepping. The motor then needs 16 pulses on STEP to advance one full step.
The percentages are sine and cosine values. At the midpoint both coils carry about 71% of peak current, so the combined magnetic pull has the same strength as at the endpoints.
Resolution arithmetic
The number of pulses needed per revolution is:
steps per revolution = motor full steps × microstep factor
| Motor | Microstep setting | Pulses per revolution | Angle per pulse |
|---|---|---|---|
| 200 steps (1.8°) | Full | 200 | 1.8° |
| 200 steps (1.8°) | 1/2 | 400 | 0.9° |
| 200 steps (1.8°) | 1/16 | 3200 | 0.1125° |
| 200 steps (1.8°) | 1/32 | 6400 | 0.05625° |
| 400 steps (0.9°) | 1/16 | 6400 | 0.05625° |
Pulse rate rises by the same factor. A motor at 60 RPM needs 200 pulses per second in full-step mode and 3200 per second at 1/16. This helper from the speed chapter works for any setting if you pass the total steps per revolution:
// Returns the time in microseconds between step pulses
// for a given speed in RPM and steps per revolution
// (motor steps multiplied by the microstepping factor).
unsigned long stepIntervalMicros(float rpm, int stepsPerRev) {
return (unsigned long)(60000000.0f / (rpm * stepsPerRev));
}
void setup() {
Serial.begin(115200);
Serial.println(stepIntervalMicros(60, 200)); // 5000 us at full step
Serial.println(stepIntervalMicros(60, 3200)); // 312 us at 1/16
}
void loop() {}Setting the mode on a driver
Most STEP/DIR driver boards select the microstep factor with pins named MS1, MS2 and MS3. Each pin is tied high or low, either with jumpers or from the Arduino. The A4988 and DRV8825 use different tables, so check your board's datasheet before wiring.
| MS1 | MS2 | MS3 | A4988 | DRV8825 |
|---|---|---|---|---|
| Low | Low | Low | Full | Full |
| High | Low | Low | 1/2 | 1/2 |
| Low | High | Low | 1/4 | 1/4 |
| High | High | Low | 1/8 | 1/8 |
| Low | Low | High | 1/8 | 1/16 |
| High | High | High | 1/16 | 1/32 |
Change the mode only while the motor is stopped. Changing it mid-motion can shift the driver's position inside its sine table, and some drivers only reread the pins at certain points.
What you gain
- Smoother motion. Each pulse changes the rotor position by a small amount, so the torque ripple that causes vibration at low speed is much lower.
- Less noise. Full-step operation at low speed produces a ticking or buzzing sound. Higher microstepping makes the motor much quieter. Many drivers also have interpolation modes that give quiet operation from a coarse step input.
- Reduced resonance. Every stepper has speeds where the rotor oscillates. Smaller steps excite those oscillations less.
- Finer position commands. Your code can ask for smaller position increments.
What you do not gain
Microstepping does not give you accuracy at the resolution you command. Three effects limit it.
- Falling incremental torque. Holding torque at a microstep position is only a fraction of full-step holding torque. The torque that pulls the rotor toward the next position is proportional to the sine of the small angle between the rotor and the target. At 1/16 this restoring torque for one microstep is very small. Friction or load can hold the rotor short of the target, and the position error stays below the level where the driver can correct it.
- Motor and driver imperfections. Real motors have uneven tooth spacing and magnetic differences between phases. Drivers have current measurement error and use approximate sine tables. The microstep positions are therefore not evenly spaced.
- Absolute accuracy. A good motor holds full-step positions to about ±5% of a full step. Microsteps between those positions inherit that error. The microsteps help smoothness more than they help accuracy.
A practical consequence is that going from 1/16 to 1/256 rarely improves real positioning. It does make step rates 16 times higher, which your microcontroller must be able to produce.
What it costs
Higher step rate
At 1/16 microstepping and 300 RPM on a 200-step motor, the pulse rate is 300 × 3200 / 60 = 16,000 pulses per second. That is 62.5 µs per step, and the pulse needs high and low times. A loop that calls digitalWrite and delayMicroseconds can reach this, but it leaves almost no time for other work. An AVR-based Arduino running AccelStepper typically tops out around 4,000 to 10,000 steps per second, depending on what else the sketch does. Beyond that, either reduce the microstep factor or use a faster board.
Each driver also specifies a minimum STEP pulse width. The A4988 needs at least 1 µs high and 1 µs low. The DRV8825 needs at least 1.9 µs each. The delayMicroseconds(2000) pulses in the earlier chapters are far above these limits, but a hand-tuned fast loop can violate them.
Lower torque at speed
Microstepping does not change the motor's torque and speed curve, which depends on the driver voltage and the motor inductance. It also does not fix the missed steps you get when you ask for a speed the motor cannot follow. At high speed the current does not have time to reach its target in each step, so the shape of the sine wave is lost. The motor then behaves much like it does in full-step mode, and the smoothness benefit disappears.
Current limit effects
The current limit you set on the driver is the peak value. At a microstep position, the current in each coil is a fraction of that value, and the combined holding force is lower. Some drivers also use decay modes that behave differently at low currents, which can add noise at certain microstep positions.
Example: checking a configuration
Suppose you want 120 RPM from a 200-step motor at 1/8 microstepping.
- Steps per revolution: 200 × 8 = 1600.
- Pulse rate: 120 × 1600 / 60 = 3200 pulses per second.
- Interval: 1,000,000 / 3200 = 312.5 µs, so about 312 µs.
The sketch below holds that rate with a simple pulse loop. It sets MS1 high and MS2 high with MS3 low, which is 1/8 on both the A4988 and the DRV8825.
const int STEP_PIN = 3;
const int DIR_PIN = 4;
const int MS1_PIN = 5;
const int MS2_PIN = 6;
const int MS3_PIN = 7;
const int STEPS_PER_REV = 200 * 8; // 1/8 microstepping
const float RPM = 120.0;
unsigned long stepIntervalMicros(float rpm, int stepsPerRev) {
return (unsigned long)(60000000.0f / (rpm * stepsPerRev));
}
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(MS1_PIN, OUTPUT);
pinMode(MS2_PIN, OUTPUT);
pinMode(MS3_PIN, OUTPUT);
digitalWrite(MS1_PIN, HIGH);
digitalWrite(MS2_PIN, HIGH);
digitalWrite(MS3_PIN, LOW);
digitalWrite(DIR_PIN, HIGH);
delay(10); // let the driver read the mode pins
}
void loop() {
unsigned long half = stepIntervalMicros(RPM, STEPS_PER_REV) / 2;
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(half);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(half);
}If the motor turns at one half or twice the expected speed, the first thing to check is the microstep factor your driver actually applies.
Choosing a setting
| Situation | Suggested setting |
|---|---|
| Maximum torque at high speed | Full or 1/2 |
| General purpose, balanced | 1/4 to 1/8 |
| Quiet operation, low speed, smooth motion | 1/16 or finer, with a fast enough step source |
| Repeatable absolute position | Any setting, but end moves on full-step positions |
Exercise
A 200-step motor runs at 1/16 microstepping and must turn at 150 RPM. What step rate does the Arduino need to produce, and what is the interval between pulses? Then explain why setting 1/32 would not make a positioning task twice as accurate.
Show answer
Steps per revolution are 200 × 16 = 3200. The step rate is 150 × 3200 / 60 = 8000 pulses per second, so the interval is 1,000,000 / 8000 = 125 µs. At 1/32 the rate would double to 16,000 pulses per second (62.5 µs). Accuracy would not double because microstep positions are limited by the small restoring torque, by friction, and by motor and driver imperfections, which are larger than the extra resolution. The full-step position error of the motor, typically around 5% of a full step, carries through to the microsteps.
Exercise
Your motor's driver is an A4988 with MS1 low, MS2 low and MS3 high. A sketch written for 1/16 microstepping makes the motor turn at twice the intended speed. What is the cause?
Show answer
On the A4988 the setting Low-Low-High selects 1/8 microstepping, not 1/16 (that is the DRV8825 table). The driver needs half as many pulses per revolution as the sketch assumes, so the motor turns at twice the speed. Set all three pins high for 1/16 on the A4988, or change the sketch to use 200 × 8 steps per revolution.