How-to
Tuning a Closed-Loop Stepper With Linear Scale Feedback
Short answer
Commission the axis open loop first, verify both linear scale channels and the counts-per-unit constant with gains at zero, then close the loop at an integral gain near 0.01 with about 100 Hz filtering. Backlash, stiction and compliance end up inside the loop, so it limit-cycles at rest — fix the mechanics and the gains together.
On this page
- How do I commission a closed-loop stepper with linear scale feedback?
- How many microsteps per millimeter does my axis have?
- Why does the axis move only a fraction of the commanded distance?
- How do I verify the linear scale before closing the loop?
- What gains and filter do I start with when closing the loop?
- Why does a closed-loop stepper hunt at rest?
- How do I set the following error and output limits?
- Questions asked
Commission the axis in stages, never all at once: run it open loop with the step scaling proven, verify both scale channels and the counts-per-unit constant with the loop open, then close the loop at an integral gain near 0.01 with about 100 Hz of low-pass filtering. A loop closed around a linear scale puts backlash, stiction and compliance inside it, so a mistuned axis limit-cycles — dithers or hunts — rather than oscillating smoothly. The numbers below come from one documented build: a 200 full-step motor on a drive fixed at 16 microsteps, a 4 mm leadscrew and a glass scale with 200 quadrature counts per millimeter, which gives 800 microsteps per millimeter. Whether an encoder makes a stepper motor closed loop covers what feedback does and does not change; this page covers the commissioning order and the tuning.
How do I commission a closed-loop stepper with linear scale feedback? #
In five stages: prove the open-loop scaling, verify both scale channels and the counts-per-unit constant with gains at zero, baseline the position error open loop, close the loop at an integral gain near 0.01 with about 100 Hz filtering, then set the following-error protection.
Each stage exists so a fault stays attributable: if the axis mis-moves before the loop is closed, it is scaling or wiring; if it mis-moves after, it is gains or mechanics. Work the stages in this order:
- Configure the drive's microstepping and the controller's counts-per-unit constant, jog the axis open loop, and confirm a measured move lands on target.
- With all gains at zero, verify both encoder channels electrically, confirm the counted position follows motion in both directions, and validate the scale factor over a 100 mm move.
- Record open-loop step-response plots of the move profile you will tune with, and save the plot data.
- Switch to closed-loop step mode, set integral gain to roughly 0.01 with a 100 Hz low-pass filter, and check that position error falls below the open-loop baseline.
- Set maximum following error just above the worst error in those plots, set the output limits, and only then chase any residual hunting mechanically.
How many microsteps per millimeter does my axis have? #
For a 200 full-step motor, a drive fixed at 16 microsteps per full step and a 4 mm leadscrew: 3200 microsteps per revolution, 800 microsteps per millimeter, and 20,320 counts per inch — the constant your trajectory planner must be told.
Calculated example for exactly those inputs:
- Microsteps per revolution = 200 steps/rev × 16 microsteps/step = 3200 microsteps/rev
- Microsteps per millimeter = 3200 microsteps/rev ÷ 4 mm/rev = 800 microsteps/mm
- Counts per inch = 800 microsteps/mm × 25.4 mm/in = 20,320 counts/in
One commanded microstep is 1 mm ÷ 800 = 1.25 µm of table travel. Take the microstep count from your drive's documentation — the documented drive is fixed at 16 with no setting to change — and recompute for any different pitch, gear or belt ratio. On a step-and-direction drive the controller only sends pulses: the counts-per-unit field is the entire distance scaling, and selecting metric units in the part program (G21) changes the program's numbers, not that constant.
Why does the axis move only a fraction of the commanded distance? #
Because the scaling constant is wrong by that same fraction: in the documented build, a commanded 80 mm move produced less than one 4 mm screw turn, the signature of scaling that never accounted for microstepping.
Divide the commanded distance by the actual distance and look for a factor you recognize: 16 means the microstep factor is missing, 2 means half-steps were counted as steps, and a large irregular ratio means a default constant is running the axis. The documented axis also returned exactly to its start after the failed move, which confirms pure scaling error rather than lost steps. That last case is what a cycle-based distance setting produces: on the controller in that build, it did not apply to step-and-direction output at all, so the axis ignored it.
The builder's hand calculation of 6.35 rev/in × 50 electrical cycles/rev = 317.5 counts per inch was correct arithmetic for a full-stepped motor but ignored that the drive inserts 16 microsteps inside each of the 4 steps per electrical cycle: 317.5 × 64 = 20,320. Enter the computed constant, command 100 mm, and measure against the scale or a dial indicator before trusting it.
How do I verify the linear scale before closing the loop? #
Confirm three things with the loop open: both channels swing below 0.4 V and above 2.8 V, the counted position follows a slow hand move in both directions, and a 100 mm move reads close to 20,000 counts on a 200 count/mm scale.
An encoder count that ramps one direction while you reverse the axis by hand means one quadrature channel is floating: it couples to the driven channel and produces intermittent counts in one direction only. Move the axis very slowly and measure channels A and B at the controller, relative to controller ground; both must toggle cleanly, low below 0.4 V and high above 2.8 V — the levels documented for that build's controller inputs.
Then run a step-response test with all gains at zero: the counted position must follow the motion and return to its start when the axis returns. Validate the scale factor over a long move: 200 counts/mm × 100 mm = 20,000 counts. A 1 mm move is only 200 counts and cannot separate scale error from backlash; if 100 mm reads 19,980 counts, chase that 0.1 percent before tuning anything.
Finally set the input gain that converts scale counts into command units: 800 microsteps/mm ÷ 200 counts/mm = 4 microsteps per encoder count. Each count the scale reports is worth 4 microsteps of commanded motion, so feedback resolution is 1/200 mm = 5 µm against the 1.25 µm command step. The same matching question with rotary encoders is covered in matching encoder resolution to a stepper's step response.
What gains and filter do I start with when closing the loop? #
All gains at zero first, then an integral gain of about 0.01 with a roughly 100 Hz low-pass filter — the trial settings that stabilized the documented 800 microsteps/mm router axis; they are starting points, not universal constants.
With proportional, integral and derivative gains at zero the loop makes no correction and the output trace stays flat; save that baseline data so position error, velocity and correction can be plotted at full magnification later. Then close the loop: the controller adds or removes step pulses until the scale reads the target, and in that mode the step-response values, following-error limits and correction limits are expressed in microsteps with times in seconds, as documented for that build.
Raise the integral gain gradually and compare position error on the same recorded move profile, open loop versus closed: that comparison separates mechanical error from the controller's correction. Convert as you go — 10 microsteps ÷ 800 microsteps/mm = 0.0125 mm, or 12.5 µm — so gains are judged against micrometers, not raw counts.
Add a small proportional gain only if the axis is slow to reverse after breakaway; too much total gain overshoots the moment stored mechanical windup releases. Profile matters too: independent rapid moves follow the per-axis velocity, acceleration and jerk settings, while coordinated moves follow the trajectory planner's. Jerk-limited ramps cut the shock that triggers limit cycling; the documented build set jerk to 20 times acceleration, which reaches full acceleration in 1/20 s = 50 ms.
Why does a closed-loop stepper hunt at rest? #
Because backlash, stiction and compliance are inside the loop: the stepper winds up while the scale still reads no motion, torque builds until the axis breaks free and overshoots, then the loop winds back — a slow limit cycle, not the fast sinusoidal oscillation of an over-gained servo.
Diagnose by shape before touching gains. A fast, roughly sinusoidal buzz is a gain problem; a slow creep-and-snap square wave is mechanical. Some dither is arithmetic, not mechanical: with an input gain of 4, a commanded 16,002 microsteps lies between the only readings the scale can express, 16,000 and 16,004, so the loop steps between them and averages near zero error. That 4-microstep, 5 µm wander is normal.
The documented machine's closed-loop output plots showed corrections equal to its backlash, measured there at 40 microsteps (50 µm) on X, 100 microsteps (125 µm) on Y and 30 microsteps (38 µm) on Z — reported values from one machine, and exactly the windup that feeds a limit cycle. Attack it in cost order: check scale and read-head mounting, reduce measured backlash and stiction in the nuts and couplings, then add proportional gain so the motor reverses quickly after breakaway.
Those plots also carried an unexplained vibration near 100 Hz that could not be attributed to the feedback filter; change one gain or filter at a time, save every plot, and compare position error rather than blaming the filter frequency. A stepper rarely runs away the way an over-gained servo does — why a servo axis runs away during tuning describes that failure mode — because its torque falls as the rotor leads the commanded microstep, which is self-limiting.
How do I set the following error and output limits? #
Set maximum following error just above the worst error recorded during normal moves — about 200 microsteps, which is 0.25 mm at 800 microsteps per millimeter, on the documented axis — so the trip catches real faults instead of tuning transients.
The arithmetic: 200 microsteps ÷ 800 microsteps/mm = 0.25 mm. Size it from your own plots: too tight and the axis faults on every acceleration, too loose and a crash winds the integrator far off before anything stops. Set the output limit just above the correction the integrator genuinely needs — the documented axis peaked near 100 microsteps on its worst axis — so a large error cannot command a violent correction. A maximum-error clamp can soften the reaction to huge errors, but the following-error trip should disable the axis first.
Leave the deadband at zero unless the axis will not settle: the documented axis held zero encoder-count error while stopped, so no deadband was used and none was missed. When the trip fires, the drive disables — on a vertical axis, verify where the load goes when that happens, and treat commissioning moves on it as stored-energy work under your machine's risk assessment and lockout procedure.
Questions asked
Is a 200 count per millimeter scale too coarse when the command resolution is 800 microsteps per millimeter?
No. Each encoder count equals 4 microsteps, so the feedback resolves 5 µm against a 1.25 µm command. The loop lands on the nearest representable count and at worst dithers one count wide, about 5 µm at the table. That exact pairing ran on the documented axis and corrected backlash of 30 to 100 microsteps without trouble. The accuracy you can claim is set by the scale, not the microstep count.
Do I need a deadband to stop hunting at rest?
Not usually, and not first. The documented axis held zero encoder-count error while stopped with no deadband. Work the cause in order: scale mounting and read-head alignment, measured backlash and stiction in the nuts and couplings, then a small proportional gain so the motor reverses quickly after breakaway. A deadband is the last resort because it trades a small standing position error for stillness.
Should I tune the loop with the machine cutting?
Tune unloaded, then verify under load. As a rule of thumb, cutting forces add a steady following error the integrator must remove, and they can push a marginal loop into its limit cycle. Run the same recorded move profile empty, then with typical tool pressure, and compare position-error plots; if hunting appears only under load, lower the integral gain before touching the mechanics.
Can a closed-loop stepper still lose position?
Yes, in two ways. A stall or crash that drives the error past the maximum following error trips the fault and disables the axis, and the position at the moment of the trip is not corrected. Any error smaller than the scale's resolution, 5 µm on a 200 count per millimeter scale, is also invisible to the loop. The loop corrects what the scale can see, within the limits you set.