Overview
Closed-loop servo tuning on a machine-tool axis usually fails in one of two ways: the gains are left so low that following error blooms during rapid moves, or the gains are pushed until the step response "looks tight" on a step-response plot while the loop sits a few degrees away from oscillation. A step response alone cannot distinguish those two cases. A Bode plot of the closed loop can, because it reports the two numbers that actually define servo robustness: open-loop bandwidth (gain crossover frequency) and phase margin at that crossover.
This note documents a working tuning procedure for a brushed/brushless DC axis driven by a SnapAmp-class amplifier under a motion controller that can inject an excitation signal and plot the resulting frequency response. The worked example is a ballscrew axis with a 0.125 in lead screw and a 1250 CPR encoder, tuned from an unstable-but-fast starting point to a stable 120 Hz / 49° result.
Axis Resolution and Accuracy Budget
Establish the resolution floor before you argue about gains. There is no point chasing a 0.0001 in specification if a single encoder count is larger than that.
| Parameter | Value | Note |
|---|---|---|
| Ballscrew lead | 0.125 in/rev | Direct-coupled to motor in this example |
| Encoder | 1250 CPR | Cycles (lines) per revolution |
| Counts per rev (x4 quadrature) | 5000 | Assumes controller decodes 4x; verify in your controller |
| Linear resolution | 0.000025 in (25 µin) | 0.125 / 5000 |
| Target accuracy | 0.0001 in | = 4 encoder counts |
| Acceptable accuracy | 0.0005 in | = 20 encoder counts |
With 25 µin per count, a tuned loop that holds following error to roughly one count under no load is already an order of magnitude below the 0.0005 in fallback target. Two caveats apply to that number and both matter for acceptance testing:
- The error is measured at the encoder, not at the tool. Screw pitch error, nut preload wind-up, coupling compliance, and thermal growth are outside the loop and invisible to the servo.
- The measurement is under no load. Cutting forces raise steady-state and dynamic error; re-check the plots with a representative load if you can.
Step-by-Step Tuning Procedure
Work in this order. Each stage isolates one behavior so you are not chasing coupled symptoms.
- Verify encoder direction and count integrity first. Command a small open-loop or low-gain move and confirm counts increment in the commanded direction. A reversed encoder produces immediate runaway, not a tuning problem.
- Set P high enough to see the natural response, D and I at zero. You will get an underdamped, ringing step with visible overshoot. This is the baseline; it tells you where the mechanical resonance and the stability edge live.
- Drop P to a low value (e.g. P = 1) and introduce D. Increase derivative gain until the ringing on the step response smooths out. D adds phase lead near crossover, which is exactly what buys phase margin.
- Raise P again until instability just begins to appear (audible buzz, visible ringing, or oscillation on the position error trace), then increase D to re-damp it. Iterate P-up / D-up in small increments.
- Add I only after P and D are settled. The integrator drives steady-state position error to zero and is what lets any servo eventually settle on a commanded count after a small step. Excess I lowers phase margin and can inject audible noise — if tightening position error with more I makes the axis noisy, back the I off.
- Run a Bode plot and read bandwidth and phase margin. Do not accept the tuning on step response alone.
- If phase margin is low but you want the bandwidth, add a lead/lag compensator rather than simply reducing gain (see next section).
- Re-plot, then run real motion profiles at production feed, acceleration, and jerk to confirm following error stays inside budget.
Reading the Bode Plot: Bandwidth vs. Phase Margin
The controller injects an excitation across a frequency band and plots gain (dB) and phase (degrees) versus frequency. Bandwidth is the frequency where open-loop gain crosses 0 dB; phase margin is how far the phase is from −180° at that same frequency. The tuning progression on the example axis:
| Stage | Bandwidth | Phase Margin | Assessment |
|---|---|---|---|
| Aggressive P/D, gains at the stability edge | 87 Hz | A few degrees | Fast but marginally stable. Reduce gains. |
| Revised gains, still aggressive | 67 Hz | Low | Lower bandwidth and still not robust — the wrong trade. |
| Gains plus lead/lag compensator | 120 Hz | 49° | Higher bandwidth and robust. Accept. |
The 67 Hz row is instructive: dropping raw gain reduced bandwidth without buying meaningful margin. Phase margin is recovered by shaping phase near crossover, not by uniformly shrinking gain. That is what the compensator does, and it is why the final tuning achieves both a higher 120 Hz bandwidth and a healthy 49° margin.
Lead/Lag Compensator Setup
There is no closed-form design equation to hand you here — setting the filter is estimation plus iteration against the plot. The method:
- Estimate your target bandwidth (the crossover frequency you want, e.g. ~120 Hz).
- Place the compensator so its maximum phase lead lands at that frequency. Maximum phase lead at crossover = maximum phase margin.
- Set the pole and zero frequencies on either side of that target by some ratio factor.
- Widen or narrow the pole/zero spread and re-plot. A wider spread produces more phase lead, but it also lifts the gain curve on the high-frequency (right) side.
- Watch the high-frequency gain against the 0 dB line. If the boosted gains rise toward 0 dB again, you create a second crossover and the system can go unstable. That is the practical limit on how wide you can open the pole/zero pair.
Iterate steps 3–5 until you have the phase margin you want with the high-frequency gain comfortably below 0 dB.
What Does Not Fix Following Error
Two changes are commonly attempted and neither addresses loop performance:
| Change | Effect on servo response | What it actually does |
|---|---|---|
| Increasing acceleration or jerk limits | Makes following error worse, not better | Defines the commanded path being tested. Higher speed and harder acceleration are inherently harder to track accurately. These settings are not servo parameters. |
| Swapping single-ended encoders for differential | None | Improves noise immunity only. Differential signaling prevents lost or gained counts in electrically noisy installations; it does not change loop gain, bandwidth, or phase margin. |
If single-ended encoders with roughly 4 ft of shielded cable, shielded motor cable, and a single-point shield ground are already producing repeatable counts, differential conversion buys nothing for tuning. Convert only if you can demonstrate count loss.
Verification
- Count-integrity test. Run the axis through representative motion for an extended period, then command a return to the original encoder count. Measure physical tool position with an indicator. If it does not repeat within mechanical tolerance, counts were lost or gained — that is a wiring/noise problem, not a tuning problem, and it is the case where differential encoders help.
- Small-step settling. Command a one- to four-count step. With any integrator active, error must converge to zero. Failure to settle indicates insufficient I or stiction exceeding available torque.
- Rapid-move following error. Capture position error during a full-acceleration move to rapid feed. Confirm peak error against your budget (here, <0.0005 in = 20 counts; ideally near 0.0001 in = 4 counts). Read the vertical scale carefully.
- Final Bode plot. Always capture a Bode plot of the accepted tuning and archive it with the machine file. It is the only record that proves the axis had margin when it was commissioned, and it is the reference for diagnosing drift later.
- Audible check. A well-tuned axis is smooth and quiet at rest and during moves. Buzzing or hunting at standstill usually means excess I or D amplifying encoder quantization noise.
FAQ
What phase margin should I target when tuning a servo axis?
Aim for a comfortable margin at the gain crossover frequency; the accepted tuning in this example reached 49° at 120 Hz bandwidth. A loop showing high bandwidth with only a few degrees of phase margin is marginally stable and should be re-tuned, not accepted.
Why did my bandwidth drop when I reduced gain but phase margin barely improved?
Uniformly reducing gain lowers crossover frequency without reshaping phase near crossover — that is how a tuning goes from 87 Hz to 67 Hz and stays fragile. Recover margin with a lead/lag compensator placed for maximum phase lead at your target bandwidth instead.
Will increasing acceleration or jerk reduce my following error?
No, it makes error worse. Acceleration and jerk define the commanded path being tested, not the servo response; accurate tracking is harder at higher speed and harder acceleration.
Do differential encoders improve servo tuning performance?
No. Differential signaling only improves noise immunity against lost or gained counts. It has no effect on loop bandwidth, phase margin, or following error — verify count integrity by returning to a known count and checking physical repeatability before spending money on conversion.
How do I calculate linear resolution for a ballscrew axis with a 1250 CPR encoder?
Divide screw lead by counts per revolution. With a 0.125 in lead and 1250 CPR decoded 4x quadrature (5000 counts/rev), resolution is 0.125 / 5000 = 0.000025 in per count, so a 0.0001 in target equals four encoder counts.
In what order should I set P, I, and D gains?
Set P first with D and I at zero to expose the natural response, drop P low and add D to damp the ringing, then iterate P up and D up until just short of instability. Add I last to drive steady-state error to zero, backing it off if the axis becomes noisy.