Back to blog
Embedded DSP··11 min read

How Resolver Angles Are Decoded: From IQ Demodulation to PLL

A three-stage mathematical walkthrough and worked numerical example for multi-pole resolver software decoding: why magnitude or atan2(Q,I) fails, why a Type-II PLL is required, and why outer corrections never write back into the inner loop.

#Resolver#IQ Demodulation#PLL#Signal Processing#Control Theory
—views

Most engineers approaching software resolver-to-digital decoding hit the same two snags. First, equations overflow with sin⁡\sin and cos⁡\cos terms, making it easy to confuse the fast excitation carrier with the slow rotor angle. Second, once you recover quadrature sine and cosine envelopes, it is tempting to just call atan2 and stop — so why add a Phase-Locked Loop (PLL), harmonic feedforward, and coarse-fine vernier fusion on top?

This article documents the algorithm core behind Resolver — Dual-Core TMS320F28377D + CLA Resolver Decoding. Setting aside chip registers and assembly scheduling, we trace a 16-pole-pair fine resolver (N=16N=16, M=16M=16 samples per 10 kHz10\,\text{kHz} carrier cycle, 160 kHz160\,\text{kHz} ADC rate) from raw ADC samples to an absolute mechanical angle, backed by a reproducible numerical example.

Overview: Three Stages, Strictly One-Way

The pipeline splits cleanly by time scale. Upstream stages hand results downstream and never accept state write-backs from outer corrections:

Rendering diagram…

In short:

  1. Carrier stage (IQ correlation + signed projection) strips the high-frequency carrier and DC offset while preserving the exact sign of sin⁡θe\sin\theta_e and cos⁡θe\cos\theta_e.
  2. Electrical stage (ellipse calibration + Type-II PLL) turns a distorted ellipse back into a unit circle, then tracks electrical angle and velocity in closed loop.
  3. Mechanical stage (unwrap + outer corrections + vernier fusion) resolves the 16-way ambiguity of a 16-pole-pair resolver (22.5∘22.5^\circ mechanical per electrical cycle) into a single absolute mechanical angle.

1. IQ Demodulation: Peeling Rotor Angle Off the Carrier

Signal Model

Neglecting higher spatial harmonics, the two fine secondary-coil channels are:

xs[k]=Assin⁡θe⋅sin⁡(ψk+δs)+ds+ns[k]xc[k]=Accos⁡θe⋅sin⁡(ψk+δc)+dc+nc[k]\begin{aligned} x_s[k] &= A_s \sin\theta_e \cdot \sin(\psi_k + \delta_s) + d_s + n_s[k] \\ x_c[k] &= A_c \cos\theta_e \cdot \sin(\psi_k + \delta_c) + d_c + n_c[k] \end{aligned}

Keep the two angles strictly separate:

  • ψk=2πkM\psi_k = \frac{2\pi k}{M} is the high-frequency excitation carrier phase; δs,δc\delta_s, \delta_c are fixed carrier phase lags from analog filtering and sampling delay.
  • θe=Nθm\theta_e = N\theta_m is the electrical rotor angle, carried solely in the slow signed envelopes sin⁡θe\sin\theta_e and cos⁡θe\cos\theta_e.
  • ds,dcd_s, d_c are DC offsets and ns,ncn_s, n_c are sample noise.

Full-Cycle Quadrature Correlation

Multiply one complete carrier cycle (MM samples) against local quadrature references rI[k]=sin⁡ψkr_I[k] = \sin\psi_k and rQ[k]=cos⁡ψkr_Q[k] = \cos\psi_k, then average:

Is=1M∑k=0M−1xs[k] rI[k],Qs=1M∑k=0M−1xs[k] rQ[k]I_s = \frac{1}{M}\sum_{k=0}^{M-1} x_s[k]\,r_I[k], \qquad Q_s = \frac{1}{M}\sum_{k=0}^{M-1} x_s[k]\,r_Q[k]

By product-to-sum identities:

sin⁡(ψ+δ)sin⁡ψ=12cos⁡δ−12cos⁡(2ψ+δ),sin⁡(ψ+δ)cos⁡ψ=12sin⁡δ+12sin⁡(2ψ+δ)\sin(\psi+\delta)\sin\psi = \frac{1}{2}\cos\delta - \frac{1}{2}\cos(2\psi+\delta), \qquad \sin(\psi+\delta)\cos\psi = \frac{1}{2}\sin\delta + \frac{1}{2}\sin(2\psi+\delta)

Over an exact integer carrier cycle, the 2ψ2\psi double-frequency terms and every nonzero harmonic sum to exactly zero. DC offsets ds,dcd_s, d_c also vanish against zero-mean references, and uncorrelated noise variance drops by 1/M1/M. What remains is a clean 2D vector per channel:

[IsQs]≈As2sin⁡θe[cos⁡δssin⁡δs],[IcQc]≈Ac2cos⁡θe[cos⁡δcsin⁡δc]\begin{bmatrix} I_s \\ Q_s \end{bmatrix} \approx \frac{A_s}{2}\sin\theta_e \begin{bmatrix} \cos\delta_s \\ \sin\delta_s \end{bmatrix}, \qquad \begin{bmatrix} I_c \\ Q_c \end{bmatrix} \approx \frac{A_c}{2}\cos\theta_e \begin{bmatrix} \cos\delta_c \\ \sin\delta_c \end{bmatrix}

Why Magnitude and atan2(Q, I) Both Fail

  • The angle of (Is,Qs)(I_s, Q_s) is the hardware carrier delay δs\delta_s, not the rotor angle θe\theta_e. Calling atan2⁡(Qs,Is)\operatorname{atan2}(Q_s, I_s) only measures analog lag.
  • Taking the magnitude Is2+Qs2\sqrt{I_s^2 + Q_s^2} destroys the sign of sin⁡θe\sin\theta_e, collapsing θe\theta_e and θe+π\theta_e + \pi into the same value.

The right operation is a signed dot-product projection onto the calibrated carrier phase δ^s\hat\delta_s:

S=Iscos⁡δ^s+Qssin⁡δ^s≈As2sin⁡θecos⁡(δs−δ^s)S = I_s\cos\hat\delta_s + Q_s\sin\hat\delta_s \approx \frac{A_s}{2}\sin\theta_e \cos(\delta_s - \hat\delta_s)

and identically C≈Ac2cos⁡θecos⁡(δc−δ^c)C \approx \frac{A_c}{2}\cos\theta_e \cos(\delta_c - \hat\delta_c) for the cosine channel. Because cos⁡(δ−δ^)\cos(\delta - \hat\delta) is flat near zero, a 1∘1^\circ–2∘2^\circ phase calibration error produces only negligible second-order amplitude shrinkage and zero angle error.

Calibrating δ\delta Without Spinning the Motor

Writing I=acos⁡δI = a\cos\delta and Q=asin⁡δQ = a\sin\delta (where aa is the signed rotor envelope), double-angle identities square away both rotor position and sign:

δ^=12atan2⁡(2∑kIkQk, ∑k(Ik2−Qk2))\hat\delta = \frac{1}{2}\operatorname{atan2}\left(2\sum_k I_k Q_k,\ \sum_k (I_k^2 - Q_k^2)\right)

Because a2≥0a^2 \ge 0, δ^\hat\delta can be estimated at standstill. The sole trade-off is that half-angle resolves δ mod π\delta \bmod \pi, so global 180∘180^\circ polarity must be fixed once against a reference direction.


2. Ellipse Calibration Before Normalization

Ideally (C,S)(C, S) traces a centered circle as the shaft rotates. Residual offsets (Os,Oc)(O_s, O_c) and channel gain mismatch (Gs≠GcG_s \neq G_c) skew it into an off-center ellipse, injecting periodic angle error.

Correct the ellipse linearly first, then normalize jointly onto the unit circle:

S=(Smeas−Os)Gs−1⋅g,C=(Cmeas−Oc)Gc−1⋅gS = (S_{\text{meas}} - O_s)G_s^{-1}\cdot g, \qquad C = (C_{\text{meas}} - O_c)G_c^{-1}\cdot g ρ=S2+C2,Vs=Sρ,Vc=Cρ\rho = \sqrt{S^2 + C^2}, \qquad V_s = \frac{S}{\rho}, \qquad V_c = \frac{C}{\rho}

The two steps are not interchangeable: normalization removes common-mode drift (excitation voltage or temperature swings) and keeps PLL loop gain constant, whereas ellipse calibration removes differential gain and offset errors that normalization cannot touch.


3. Tracking PLL: Closed-Loop Angle Estimation via 2D Cross Product

Direct atan2(Vs, Vc) passes every sample of noise straight to the output, and finite-differencing it for velocity amplifies noise dramatically. A tracking PLL maintains an internal angle estimate ϕ\phi and drives the phase error to zero.

Phase Detector = 2D Cross Product

Take the 2D cross product between measured (Vc,Vs)(V_c, V_s) and estimated (cos⁡ϕ,sin⁡ϕ)(\cos\phi, \sin\phi):

c=Vscos⁡ϕ−Vcsin⁡ϕ=sin⁡(θe−ϕ)=sin⁡ec = V_s\cos\phi - V_c\sin\phi = \sin(\theta_e - \phi) = \sin e

When ϕ\phi lags θe\theta_e, c>0c > 0 accelerates the loop; when it leads, c<0c < 0 pulls it back. Once locked (e≪1e \ll 1), c≈ec \approx e linearizes automatically.

Why a Type-II Second-Order Loop

Feed ckc_k through a PI controller to obtain electrical angular velocity ω^\hat\omega, then integrate velocity into angle:

Fk+1=Fk+ckT,ω^k+1=Kpck+KiFk+1,ϕk+1=wrap⁡2π(ϕk+ω^k+1T)F_{k+1} = F_k + c_k T, \qquad \hat\omega_{k+1} = K_p c_k + K_i F_{k+1}, \qquad \phi_{k+1} = \operatorname{wrap}_{2\pi}(\phi_k + \hat\omega_{k+1} T)

In continuous small-signal form:

L(s)=Kps+Kis2,E(s)Θ(s)=s2s2+Kps+KiL(s) = \frac{K_p s + K_i}{s^2}, \qquad \frac{E(s)}{\Theta(s)} = \frac{s^2}{s^2 + K_p s + K_i}

Two integrators in the open loop make it a Type-II loop. A constant-speed shaft produces a ramp input θe(t)=ωt\theta_e(t) = \omega t; only a double zero (s2s^2) in the error transfer function guarantees zero steady-state tracking error at constant velocity. Matching s2+2ζωns+ωn2s^2 + 2\zeta\omega_n s + \omega_n^2 yields ωn=Ki\omega_n = \sqrt{K_i} and ζ=Kp/(2Ki)\zeta = K_p / (2\sqrt{K_i}). Note that the closed-loop numerator Kps+KiK_p s + K_i adds a zero, so step overshoot is higher than textbook all-pole formulas predict.

Low-Speed Integrator Bleed & Unwrapping

At standstill or creep speed, double integration can slowly wind up on tiny residual bias. When both velocity and phase error stay below threshold, applying a gentle leak F←(1−λ)FF \leftarrow (1-\lambda)F (0<λ≪10 < \lambda \ll 1) trades a tiny static offset O(bias/Kp)O(\text{bias}/K_p) for zero standstill drift.

Finally, unwrap the [0,2π)[0, 2\pi) electrical angle incrementally and divide by NN:

Δϕk=wrap⁡[−π,π](ϕk−ϕk−1),θm,k=wrap⁡2π(θm,k−1+ΔϕkN)\Delta\phi_k = \operatorname{wrap}_{[-\pi,\pi]}(\phi_k - \phi_{k-1}), \qquad \theta_{m,k} = \operatorname{wrap}_{2\pi}\left(\theta_{m,k-1} + \frac{\Delta\phi_k}{N}\right)

Increment unwrapping stays unambiguous only while ∣ω^e∣<π/T|\hat\omega_e| < \pi/T, which sets a hard mathematical upper bound for velocity clamping.


4. Outer-Loop Corrections: Fix the Output, Never the PLL State

Three outer corrections sit downstream of the unwrapped angle: harmonic feedforward, Anchor slow bias, and coarse-fine vernier fusion. None of them may write back into the PLL state, preserving inner-loop bandwidth and clean velocity estimates.

Rendering diagram…
  • Harmonic Feedforward: Subtracts residual 4th/8th electrical-angle periodic distortion H(ϕ)/NH(\phi)/N directly from the output.
  • Anchor Slow Bias: Compares raw atan2(S, C)/N against θm,raw mod 2πN\theta_{m,\text{raw}} \bmod \frac{2\pi}{N}, filters valid residuals through a gated low-pass target btargetb_{\text{target}}, and slews banchorb_{\text{anchor}} via a critically damped actuator (acmd=ωa2(btarget−b)−2ωava_{\text{cmd}} = \omega_a^2(b_{\text{target}} - b) - 2\omega_a v) much slower than PLL bandwidth so there are no output steps.
  • Coarse-Fine Vernier Fusion: A 16-pole-pair fine resolver repeats every 360∘/16=22.5∘360^\circ / 16 = 22.5^\circ. A single-pole coarse angle θc\theta_c picks which sector q∈{0,…,15}q \in \{0,\dots,15\} the shaft occupies:
q=round⁡(θc−θf22.5∘) mod 16q = \operatorname{round}\left(\frac{\theta_c - \theta_f}{22.5^\circ}\right) \bmod 16

As long as coarse error stays within half a sector (±11.25∘\pm 11.25^\circ), qq is exact: coarse resolves which sector, fine PLL resolves precision and dynamics inside the sector.


5. Worked Public Numerical Example

Let N=16N=16, M=16M=16, and T=0.1 msT=0.1\,\text{ms}. Set a synthetic ground truth and realistic front-end imperfections:

  • True mechanical angle θm=50.00∘\theta_m = 50.00^\circ (sector q=2q=2, fine offset 5.00∘5.00^\circ), so true electrical angle θe=16×50.00∘ mod 360∘=80.00∘\theta_e = 16 \times 50.00^\circ \bmod 360^\circ = 80.00^\circ.
  • Channel amplitudes and DC offsets (4% gain mismatch): As=1.00, ds=+0.08A_s = 1.00,\ d_s = +0.08; Ac=0.96, dc=−0.05A_c = 0.96,\ d_c = -0.05.
  • True carrier phase shifts δs=18.0∘, δc=20.0∘\delta_s = 18.0^\circ,\ \delta_c = 20.0^\circ, with an intentional 0.5∘0.5^\circ calibration error: δ^s=18.5∘, δ^c=19.5∘\hat\delta_s = 18.5^\circ,\ \hat\delta_c = 19.5^\circ.
  • Coarse single-pole reading θc=52.30∘\theta_c = 52.30^\circ (+2.30∘+2.30^\circ error, safely inside ±11.25∘\pm 11.25^\circ).
StageInput / OperationComputed OutputEngineering Takeaway
0. Carrier samples (M=16M=16)First 4 samples xs[0..3]=[0.3843, 0.7196, 0.9575, 1.0618]x_s[0..3] = [0.3843,\ 0.7196,\ 0.9575,\ 1.0618]
xc[0..3]=[0.0070, 0.0626, 0.1011, 0.1165]x_c[0..3] = [0.0070,\ 0.0626,\ 0.1011,\ 0.1165]
16-point carrier frameMixes carrier, DC offset, and 4% gain mismatch
1. Full-cycle IQ correlationAverage against sin⁡ψk, cos⁡ψk\sin\psi_k,\ \cos\psi_kIs=0.4683, Qs=0.1522I_s=0.4683,\ Q_s=0.1522
Ic=0.0783, Qc=0.0285I_c=0.0783,\ Q_c=0.0285
ds,dcd_s, d_c vanish; atan2⁡(Qs,Is)=18.00∘\operatorname{atan2}(Q_s,I_s)=18.00^\circ and atan2⁡(Qc,Ic)=20.00∘\operatorname{atan2}(Q_c,I_c)=20.00^\circ confirm this is hardware lag, not rotor angle
2. Signed projectionDot product along δ^s=18.5∘, δ^c=19.5∘\hat\delta_s=18.5^\circ,\ \hat\delta_c=19.5^\circSraw=0.4924S_{\text{raw}}=0.4924
Craw=0.0833C_{\text{raw}}=0.0833
Uncalibrated atan2⁡(Sraw,Craw)=80.39∘\operatorname{atan2}(S_{\text{raw}},C_{\text{raw}})=80.39^\circ: 4% gain mismatch adds +0.39∘+0.39^\circ electrical error
3. Ellipse cal + normalizeScale by 0.5As, 0.5Ac0.5A_s,\ 0.5A_c, then normalizeScal=0.9848, Ccal=0.1736S_{\text{cal}}=0.9848,\ C_{\text{cal}}=0.1736
ρ=0.99996\rho=0.99996
Vs=0.9848, Vc=0.1736V_s=0.9848,\ V_c=0.1736
0.5∘0.5^\circ phase calibration error shrinks ρ\rho by only 0.004%0.004\% and leaves angle at exact 80.00∘80.00^\circ
4. One Type-II PLL tickFrom ϕk=76.00∘\phi_k=76.00^\circ (4∘4^\circ lag), Fk=0F_k=0, ωn=2π⋅200 rad/s\omega_n=2\pi\cdot 200\,\text{rad/s}, ζ=0.707\zeta=0.707 (Kp=1776.9, Ki=1.579×106K_p=1776.9,\ K_i=1.579\times 10^6)ck=0.06976c_k = 0.06976 (true e=0.06981 rade=0.06981\,\text{rad})
ω^k+1=134.96 rad/s\hat\omega_{k+1}=134.96\,\text{rad/s}
ϕk+1=76.773∘\phi_{k+1}=76.773^\circ
Cross product tracks small error linearly and pulls ϕ\phi forward by 0.773∘0.773^\circ in a single 100 μs100\,\mu\text{s} tick
5. Coarse-fine fusionSteady state ϕ=80.00∘⇒θf=5.00∘\phi=80.00^\circ \Rightarrow \theta_f=5.00^\circ with θc=52.30∘\theta_c=52.30^\circ(52.30−5.00)/22.5=2.102⇒q=2(52.30-5.00)/22.5 = 2.102 \Rightarrow q=2
θabs=2×22.5∘+5.00∘=50.00∘\theta_{\text{abs}} = 2\times 22.5^\circ + 5.00^\circ = 50.00^\circ
Even with +2.30∘+2.30^\circ coarse bias, sector selection is exact and recovers 50.00∘50.00^\circ

Closing Thought: Separate Time Scales, Keep Flow One-Way

What keeps this pipeline stable on a real DSP is not any exotic trick, but strict time-scale separation and one-way data flow: carrier correlation strips excitation and DC at the fastest layer; ellipse calibration and a Type-II PLL handle dynamics and velocity in the middle; harmonic feedforward, Anchor bias, and vernier fusion resolve geometry and multi-turn ambiguity outside the loop.

For how these stages map onto dual-core TMS320F28377D CPUs, dual CLAs, and FPGA BiSS-C output, see the project page: Resolver — Dual-Core TMS320F28377D + CLA Resolver Decoding.