EMF #
Brief #
emf measures the back EMF of a coasting motor on the F3 (HV board): with the bridge off it demodulates every PWM period’s unfiltered phase voltage sample against the rotor angle and sums the flux linkage psi, its 5th and 7th harmonic back EMF, and psi per magnet pole, to tell a demagnetised magnet from a weak rotor. It is loaded by stm32f303/src/main.c as emf0 (rt_prio 7, the last in the chain). It is controlled from the F4 through config words and read back one result at a time through a state word: idpmsm’s psi test drives it (conf/template/id_pmsm.txt links hv0.emf_run/emf_sel/emf_pp to idpmsm0 and idpmsm0.emf_val = hv0.emf_val). It runs on the F3 because the F4 only sees each phase voltage every ~2 ms and through io0’s filter.
Component Explanation #
- Wiring on the F3 (fixed in main.c):
emf0.u/v/w = io0.ur/vr/wr,emf0.pos = ls0.pos,emf0.si/co = dq0.si/co,emf0.en = ls0.en.emf0.run/sel/pp = ls0.emf_run/emf_sel/emf_pp(F4 config words),ls0.emf_val = emf0.val(F4 state word).
- Speed and turns (rt, always):
velis the electrical speed from the change ofposper tick (the angle steps once per F4 packet, everyPWM_TICKS_PER_PACKETticks, 3 at the default 15 kHz PWM).- A wrap of
posfrom +pi to -pi counts one electrical cycle forward, the other way one back.
- When it sums (rt):
- Only with the bridge off:
enmust have been 0 for 30 ms (the winding current has to die out first), and|vel|must be above 20 rad/s electrical. run< 0 clears the sums every tick while it stays negative. rt_start clears them too.- The live
psipin is updated whenever the conditions above hold, also whilerunis 0.
- Demodulation (rt):
- The phase voltages are Clarke transformed (amplitude invariant, so the common mode drops out) into
e = a + j b. With the rotor fluxpsi(th) = sum psi_k exp(j k th)over the harmonics k = 1, -5, 7, the back EMF ise = d/dt psi, so
e * exp(-j k th) / w averages to j k psi_k // w = electrical speed
- This holds whatever the direction of rotation, so
psicomes out in Vs (peak, per electrical rad) at any speed. - Every sample adds
e exp(-j th) / w,e exp(+j 5 th) / wande exp(-j 7 th) / wto three sums, andncounts them. - Per pole bins: the fundamental is also summed per half electrical cycle,
bins = 2 * ppbins over a mechanical turn (pprounded, 1..8, so up to 16 bins), which is one bin per magnet pole. Bin 0 is wherever the count started, not a fixed rotor position, so compare the bins with each other: a weak pole reads low in its bin on every run.
- DC offset removal:
- A DC offset between the phase voltage channels (divider or ADC offsets that differ per phase) averages out over a whole electrical cycle but not over half of one, so it would make the bins alternate high and low.
- The offset
dis estimated as the mean Clarke vector over whole electrical cycles only (the back EMF integrates to 0 over each one): summing starts at the first wrap ofposafter the first sample, and a snapshot is taken at every later wrap. Each bin also keeps the sum ofexp(-j th) / w, so its share ofdis subtracted when the bin is read. Until one whole cycle has been seen,dreads 0.
- Results (rt, one per tick):
selpicks whatvalreturns:- 0 (or below): the live
psi(low pass filtered |psi_1| with a 20 ms time constant). - 1: number of samples summed.
- 2, 3: psi_1 real and imaginary part, averaged over the whole coast.
- 4, 5: 5th harmonic back EMF (-5 psi_-5), real and imaginary, on the same scale as psi_1.
- 6, 7: 7th harmonic back EMF (7 psi_7), real and imaginary.
- 8: number of bins in use (2 * pp).
- 9 + 3b, 10 + 3b, 11 + 3b: bin b (0..15), psi real, psi imaginary (DC offset removed, averaged over the bin’s samples), sample count.
- 57, 58: the DC offset
d, alpha and beta (V). - Anything above returns 0.
- On the F4 the value arrives through the rotating state words of the link, so after changing
selthe reader must wait a few ms beforeemf_valholds the new result (idpmsmdoes).
velcomes from differencingpos, which on the F3 is the F4’s angle extrapolated between packets, so the F4 must keep sending the rotor angle while the bridge is off.- Bins past
2 * ppstay 0, and changingppbetween clears mixes bin indices.- The bin count is limited to 16 (8 pole pairs) by the F3’s HAL memory (HAL_MAX_CTX); a motor with more pole pairs gets bins that each span several poles.
Pins #
| Name | Description |
|---|---|
| u | input, U phase voltage to ground (V), unfiltered, from io0.ur |
| v | input, V phase voltage to ground (V), unfiltered, from io0.vr |
| w | input, W phase voltage to ground (V), unfiltered, from io0.wr |
| pos | input, Electrical rotor angle (rad), from ls0.pos |
| si | input, Sine of pos, from dq0.si |
| co | input, Cosine of pos, from dq0.co |
| en | input, Bridge enable from ls0.en, summing only runs 30 ms after it went to 0 |
| run | input, 1 = sum, 0 = hold, -1 = clear, from ls0.emf_run |
| sel | input, Result number returned in val, from ls0.emf_sel |
| pp | input, Pole pairs for the per pole bins (1..8), from ls0.emf_pp |
| vel | output, Electrical speed from pos (rad/s), 4 ms low pass |
| psi | output, Live flux linkage amplitude (Vs), 20 ms low pass |
| n | output, Number of samples summed |
| val | output, Result number sel, to ls0.emf_val |
References #
Source: .c File