← BlogBlog

Rotor position at zero speed: high-frequency injection

Sensorless FOC so far has relied on a flux observer. It integrates the voltage the drive applies, minus the resistive drop, and the rotor angle comes out of the back-EMF. Back-EMF is proportional to speed, so the observer gets less accurate as the motor slows and has nothing to work with at standstill. On motor 3 (maxon EC-i 40, 7 pole pairs, 18 V) it held the rotor down to about 100 rad/s electrical. Below that it lost the angle, and from 40 rad/s down its stall detector tripped. Starting from rest needed an open-loop current ramp (I-f) up to 350 rad/s before the observer could take over.

High-frequency injection (HFI) gets the angle from a different property: the motor’s inductance depends on rotor position. That works at any speed, including zero, and needs no extra hardware. It uses the same PWM and the same current shunts as normal FOC. This post covers how it works, what had to be fixed on the bench, and what the result looks like on motor 3.

The idea: saliency

If the stator inductance is the same in every direction, a small voltage applied along any axis produces the same current, whatever the rotor angle. Most permanent-magnet motors are not quite like that. Rotor geometry, or the magnet saturating the iron along its own axis, makes the inductance along the magnet (Ld) differ from the inductance across it (Lq). This is called saliency. The size of the effect is

ξ = (Lq − Ld) / (Lq + Ld)

Motor 3 has a surface-mounted magnet and was not designed to be salient, but it has a little: Lq/Ld ≈ 1.12, so ξ ≈ 0.055. That is a 5–6% difference in inductance, and it is enough.

To measure it, the drive holds the rotor still and applies a small high-frequency voltage, the carrier, along 24 test angles in turn. For each angle it records the current response along the test axis and across it. Both vary twice per electrical revolution, because the inductance has the same value along the magnet’s north and south directions:

Motor 3's saliency, measured at standstill

Real capture · motor 3 · rotor held · 1 V carrier
-12% -6% 0 +6% +12% 0° 60° 120° 180° 240° 300° 360° carrier response vs test angle, % of the mean d response along the test axis (d̂) across it (q̂) 2θ fit 2θ amplitude 6.7% → ξ ≈ 0.067

One of 24 standstill sweeps (RunTest HFI_SWEEP). The test-axis response is largest where the test axis lines up with the low-inductance direction, and the cross response passes through zero there. Across all sweeps ξ came out between 0.035 and 0.072, with the cross response matching the test-axis response, which rules out a measurement artefact. The fitted axis agreed with the hall angle within the ±30° resolution of a hall sector.

The cross response is what the tracker uses. If the drive’s estimated d axis is off from the true one by an error e, the current response perpendicular to the estimate is

cross response ∝ −ξ · sin 2e

It is zero when the estimate is right, and its sign shows which way to correct. A tracking loop that drives it to zero follows the rotor.

How the drive does it

The carrier

Every control period (10 kHz on the F302), the drive adds a voltage ±vh along its estimated d axis, on top of whatever the current loop asks for. The carrier is 1 V on motor 3. At this frequency the winding behaves mostly as an inductance, so the current ripples by about vh·T/L along each axis, a few hundred milliamps.

The first version flipped the carrier sign every period (+−+−). It barely worked: the d response was 41 mA where about 300 mA was expected. The cause is timing. The F302 samples the currents once per period, at the counter peak, and a new duty only takes effect half a period later. With a carrier that flips every period, each sampling interval sees half of +vh and half of −vh. The two halves cancel, and what is left in the samples is mostly dead-time distortion.

Holding each sign for two periods (++−−, 2.5 kHz) fixes it. Each sign is then seen whole by one sampling interval, and the d response went from 41 mA to about 310 mA at 1 V.

Why the carrier is ++−− and not +−

Timing sketch · F302: sample at the counter peak, new duty half a period later
carrier +−+− Δi between samples ≈ 0: the response cancels carrier ++−− Δi between samples: +, 0, −, 0 … applied voltage (duty loads ½ period late) phase current ripple current sample vertical lines: control periods (100 µs)

Grey: the voltage actually applied, half a period behind the command. Coloured: the resulting current ripple. White dots: the samples the drive takes. With +−+− the samples land at the same level every time, so there is nothing to demodulate. With ++−− the change between samples follows a +, 0, −, 0 pattern.

Demodulation

The drive takes the change in current between consecutive samples and weights it by (c[n−1] + c[n−2]) / 2, which is +1, 0, −1, 0 for this carrier. That separates the carrier’s response from the slow current the drive is regulating, because the slow current changes very little over one period and the weights sum to zero. The weight is right whether the new duty loads half a period late, as on the F302, or a full period late.

Along the estimated d axis the result is proportional to 1/L. Across it, the result is the −ξ·sin 2e error signal above.

Tracking

mmc_core::hfi::Tracker is a phase-locked loop: a PI controller that turns the cross response into an angle correction and a speed estimate. Its gains are divided by ξ, so the loop bandwidth is the value set (hfi_bw, 150 rad/s on motor 3) whatever the saliency. The output is an angle and a speed, the same as the flux observer’s, so FOC and the speed loop run on it unchanged.

Polarity

Saliency repeats every 180° electrical, so the tracker cannot tell the magnet’s north from its south. If it locks 180° off, positive iq pushes the rotor backwards.

The check uses magnetic saturation. Current along the magnet’s north adds to the magnet’s flux, saturates the iron a little, and lowers the inductance. Current the other way does not. So with the estimate pointing north, a positive d-current bias gives a larger carrier response than a negative one:

The polarity signal: a +d bias answers stronger

Real captures · motor 3 · rotor held at six positions
280 300 320 340 +11% rotor at 0° +17% rotor at 60° +2% rotor at 120° +2% rotor at 180° +8% rotor at 240° +3% rotor at 300° d-axis carrier response (mA), rotor held +0.7 A on d (along the magnet) −0.7 A on d (against it)

Mean carrier response along d, with the d axis on the magnet, under ±0.7 A of d current. The +d bias wins at every position, but by as little as 2% at some. That margin is comparable to the saliency itself, which is why the start sequence repeats the comparison several times.

At start-up the drive alternates short +d and −d current pulses, compares the responses, and turns its estimate by 180° if −d gave the stronger one.

Dead time

With little load current, each phase current crosses zero on every carrier swing. The inverter’s dead-time voltage error flips sign at every zero crossing and swamps the cross response. A steady d-current bias of +0.5 A (id_inject) keeps the phase currents away from zero. The dead-time error then becomes a nearly constant offset, which the differencing in the demodulator removes.

A start from standstill

The full start sequence in sensorless mode with HFI enabled:

  1. Lock (0.3 s). The carrier and the +0.5 A d bias are applied, and the tracker settles onto the saliency axis.
  2. Polarity (96 ms). Eight pairs of ±0.6 A d-current pulses, 6 ms each, then flip the estimate if needed.
  3. Run. The speed loop closes on the tracker’s angle and speed. If the target is above sl_handoff, the drive hands over to the flux observer once it gets there. Below that it stays on HFI.

Standstill to 20 rad/s el without halls

Real capture · motor 3 · halls recorded as truth only
-1 -0.5 0 0.5 1 lock ← polarity pulses run on the HFI tracker current (A) 0 20 40 0 s 0.4 s 0.8 s 1.2 s 1.6 s target 20 rad/s el speed (rad/s el) i_d i_q HFI speed estimate hall speed (truth only)

The id trace carries the injected carrier, sampled by the telemetry. The rotor does not move during the lock or the pulses. Once running, the HFI speed estimate follows the rotor through the stick-slip described below: the halls step when the estimate says the rotor moved.

The polarity pulses that threw the rotor

The first version used three pulse pairs of 25 ms each. About one start in ten tripped the 1.5 A overcurrent limit. Slewing the pulse edges made no difference, so the trip was not an edge overshoot. The captures showed what was happening: during the pulse window the rotor turned 1–3 electrical revolutions (up to 21 hall edges in 0.15 s), and id reached twice the commanded value.

The lock phase had already pulled the magnet’s north onto the tracker’s +d axis, because the +0.5 A bias aligns the rotor. A −d pulse then pushes directly against the magnet. That is an unstable equilibrium: any small offset grows, with a time constant of

τ = 1 / √(1.5 · p² · ψ · i / J) ≈ 4 ms at 0.6 A on motor 3

A 25 ms pulse lasts about six time constants, long enough to turn the rotor half a revolution before the next +d pulse turns it back. Once the rotor moves, the tracker’s frame slips under the current loop and the phase currents peak.

Pulses of a few time constants cannot do that. The pulse length and count became parameters (hfi_pol_s, hfi_pol_n). The polarity is now read from the unfiltered response, because the ~2 ms filter would carry one pulse’s response into the next.

Long pulses against short pulses

Real captures · motor 3 · 15 starts each, from wherever the last one stopped
0 6 12 18 24 0 0.4 0.8 1.2 1.6 1.5 A trip 25 ms × 3 25 ms × 3 6 ms × 8 6 ms × 8 hall edges during the pulses peak |i_d| during the pulses (A)

Hall edges counted during the pulse window, and the peak d current there. With 25 ms × 3 the rotor moved in 14 of 15 starts, and peak id passed 1.19 A in four, reaching 1.43 A once. With 6 ms × 8 it did not move in any, and the peak stayed at the 0.6 A pulse plus the carrier ripple. A 4 ms × 12 run looked the same as 6 ms × 8.

6 ms × 8 is now the default. Counting the pulse-shape batches, 15 further starts to −20 rad/s el and 3 to 600 rad/s el through the handover to the flux observer, 63 of 63 starts were clean, with polarity right in all of them.

The low-speed floor

The comparison: the same target speeds with the flux observer (I-f start, observer, then stepped down to the target) and with HFI (from rest straight to the target). True speed comes from counting hall steps, and angle error is scored against the hall angle.

Angle error against speed: flux observer and HFI

Real captures · motor 3 · forward · cogging feed-forward off
0 ±10° ±20° ±30° ±40° ±50° ±60° ±70° 9 5 200 15 6 150 23 9 100 64 9 75 63 9 50 stall 11 30 stall 9 20 — 7 10 target, rad/s el angle error spread against the halls (1σ, ° el) flux observer HFI

Spread of the drive's angle error against the halls (for HFI, measured at hall edges). At 75 and 50 rad/s el the observer still turns the rotor, but on an angle that is ±60° wrong: speed falls short and iq doubles. At 40 rad/s el and below the stall detector trips it. HFI holds 5–11° everywhere it turns. At 10 rad/s el with the original gains it moved only in bursts.

HFI held the angle at every speed, but below about 75 rad/s el the rotor did not turn smoothly. It stuck, then lurched forward. That turned out to be a property of the speed loop, not of HFI.

Stick-slip and the speed loop’s stiffness

While the rotor is stuck, the speed loop’s integrator winds up iq until the torque breaks the rotor free, at about 0.3 A on motor 3. The rotor then lurches forward and sticks again. A PI speed loop acts as a spring on position error with stiffness ki. The slip distance is therefore about

breakaway current / k_i = 0.3 A / 8.1e-3 A/rad ≈ 37 rad el ≈ 2100° el

The measured stick-slip was about 1900° el peak to peak. Raising the gains should shrink it in proportion to 1/ki, and it did:

Stick-slip against speed-loop gain

Real captures · motor 3 · HFI from rest
0 1000 2000 3000 4000 0 s 1 s 2 s 3 s 4 s rotor position from hall steps (° el), target 20 rad/s el 0 500 1000 1500 2000 1870 ×1 900 ×2 505 ×4 246 ×8* stick-slip p-p (° el) ×1 gains (fw 20) ×8 gains + cross-sat. correction 1/k_i prediction

Left: position counted from hall steps at a 20 rad/s el target, original gains against 8× gains with the cross-saturation correction below. Right: stick-slip peak-to-peak (rotor position about its mean-speed line, ±30° of hall quantisation included), averaged over ±20 and ±50 rad/s el, and over ±5 to ±50 for ×8. The dashed line is 1870°/gain. *×8 includes the correction; without it, ×4 and above lock up.

More current moves the HFI angle

At 4× gain, two of the reverse runs locked up. The rotor stuck, the integrator wound iq to the 1.2 A limit, and the rotor never broke free. Over the stuck interval, the HFI angle walked away from the rotor as the current rose:

A lock-up: q current drags the saliency axis

Real capture · motor 3 · −20 rad/s el, 4× gains, no correction
0 20 40 60 0 A 0.25 A 0.5 A 0.75 A 1 A 1.25 A 25° el per A (the small-current slope) HFI angle drift since the rotor stopped (° el) vs |i_q| ×4 gains, no correction, −20 rad/s el: rotor stuck, integrator winding

The rotor is still (no hall edges) while the speed integrator winds |iq| from 0.3 to 1.2 A. The angle the tracker reads moves 53° el, faster than the 25°/A seen at small currents once past about 0.6 A. The stall detector then trips the drive.

This is cross-saturation. q-axis current saturates the iron too, which shifts the low-inductance direction the tracker locks onto. On motor 3 the shift is about −25° el per amp of iq at small currents (r = −0.88 over 49,000 samples from every stuck interval in the test set), and it grows faster past about 0.6 A. The result is a runaway. The angle error means less torque from the same current, the speed loop asks for more current, and the extra current increases the error.

The fix is a correction term. The drive’s angle is the tracker’s angle plus hfi_xsat·iq, with hfi_xsat = 0.44 rad/A (the measured 25°/A). With it, the 4× runs no longer lock up, and RMS q current drops from 0.22 to 0.17 A because the torque is aligned. 8× gains then work in both directions.

Where the floor is now

With the correction and 8× gains (on their own parameters, hfi_kp/hfi_ki, so the observer and hall modes keep theirs):

target, rad/s el +5 −5 +10 −10 +20 −20 +50 −50
true speed 5.0 −5.0 9.6 −10.0 20.0 −20.1 50.0 −50.1
stick-slip p-p, ° el 287 216 388 215 287 220 184 167

The floor is now 5 rad/s el (0.7 rad/s mechanical, about 7 rpm), and the lowest speed that works has not been found yet. Before HFI, the sensorless floor on this motor was 100 rad/s el. Reversing through zero also works: 20 → −20 and 50 → −50 cross cleanly. The flux observer stall-trips as the speed passes zero.

Two things that did not help:

  • Friction feed-forward (sl_fric, a fixed iq added in the direction of motion): no change at 4× with the correction, because the stiff integrator already supplies breakaway current within milliseconds. On the flux observer it made things worse, so it is HFI-only and off by default.
  • A higher tracker bandwidth (300 rad/s) at 4×: overcurrent at start in three of four runs.

What it costs

  • Interrupt time: an HFI start takes 6173–6265 of the 7200 cycles available per period on the F302.
  • Flash: 2.97 KB left on the F302.
  • Noise: the 2.5 kHz carrier is in the audible range. It only runs in the HFI modes.
  • Hardware: none. HFI uses only the current shunts. The terminal-voltage dividers (back-EMF sensing) are not involved, and neither is FOC’s flux observer, which integrates the commanded voltage. The dividers are still needed for sensorless six-step, for measuring flux from a coast, and for catching a coasting rotor from Off without halls.

Takeaways

  • A small saliency is enough. 5–6% inductance difference on a motor not designed for it gave ±5–11° angle error at every speed down to 5 rad/s el.
  • Check sample timing before signal processing. The first carrier cancelled itself because of a half-period duty latency. Nothing in the demodulation could have recovered it.
  • Watch what the start sequence does to the rotor. The polarity pulses pushed against a magnet the lock phase had just aligned. Shortening them below a few mechanical time constants stopped the rotor moving and removed the trips.
  • The low-speed limit was the speed loop. HFI held the angle at 10 rad/s el; the stick-slip came from the speed loop’s stiffness against stiction, and it followed 1/ki as predicted.
  • The estimator depends on the load. Cross-saturation shifts the saliency axis with q current, enough to cause a lock-up that adding current makes worse. A single linear term fixed it on this motor up to the currents it needs.
  • The polarity check has not been fully tested yet. The lock bias aligns the rotor before the pulses run, so on motor 3 the pulses mostly confirm what the bias set up. A motor with less friction or a load that holds it will need the polarity read to do real work.

Next

  • The correction is linear only to about 0.6 A. Loaded operation will need a table or a quadratic term.
  • A stronger polarity signal for motors with less saturation: read the first current rise instead of the averaged ripple, or use a short q-current nudge read on the tracker.
  • The F302’s ADC interrupt discards every second current sample. Keeping the sample where the new duty loads would read the carrier where it is largest.
  • Feed the cogging torque forward under HFI as well. Today the interrupt budget only allows that in the hall modes.
  • Wire motor 3’s encoder (4096 counts per turn). At standstill the halls only resolve ±30°, and the tracker is better than that.