The Current Loop at 20 kHz

A torque command becomes one number, the current that makes torque, and a small loop runs 20,000 times a second to hold it. Run that loop too slowly and the actuator sings.

Press a loop rate, then drag the torque command, the bandwidth and the temperature. Watch the current vector chase its target, or spiral away. Then we build, piece by piece, everything under it: the frame change, the PWM, the loop, the sensors and the faults.

You need a feel for what a sine wave is and a little C for the code. We build the rest from zero: current, torque, the transforms and the controller.

Built from primary sources: TI application report BPRA073 (field orientated control), Microchip AN1078 (a worked 20 kHz PMSM loop), the TI DRV8353 datasheet, the maxon EC-i 40 catalog page and ST’s STM32G4 timer header. Every number is traced in the Field Guide. The motor and the loop are an honest model that runs in your browser, not real silicon.

Hold the torque

0.30 N·m
1.0 kHz
25 °C

An honest model, not silicon. Motor: maxon EC-i 40, 70 W, 36 V version (R 0.582 Ω and L 0.512 mH phase to phase, so half of each per phase in a star winding; Kt 46.1 mNm/A; 7 pole pairs). Loop: PI gains from the nominal 25 °C model, one sample of compute delay, voltage clipped to the bus limit 36 V / √3 = 20.8 V. Copper heats at 0.39% per kelvin; the magnets weaken by an assumed 0.12% per kelvin. We treat the catalog Kt as torque per amp of iq.

Chapter 0

The Actuator That Sang

See why a current loop that runs too slowly turns a quiet motor into a whistle, and what the firmware must hold steady

Picture a robot joint on your bench. You send it a torque command of 0.30 N·m. It should hold that torque and nothing more. Instead it whines, a clean tone you can hear across the room, and the housing starts to warm. Nothing is broken. The wiring is fine. The code is the code that ran quietly last week.

What changed is small. Someone added work to the interrupt that runs the control loop. The loop used to run 20,000 times a second. Now it runs 5,000 times. This lesson explains why that one change makes a motor sing, and how to design the loop so it cannot.

What the firmware is really asking for

A motor makes torque, a twisting force, from current, the flow of electric charge, measured in amps. Inside a brushless motor, three coils push on the magnets of the rotor. Each coil is a phase. More current in the right coil at the right moment gives more twist. So a torque command is really a current command.

You cannot simply set a voltage and hope. A coil resists any change in its current. That resistance to change is its inductance, written L. A spinning magnet also pushes back with a voltage of its own, the back-EMF. Together they make the current lag and drift. The only way to get the current you want is to measure it and correct it.

That is a control loop: measure, compare with the target, correct, repeat. The current loop is the innermost loop of a motor drive, and it runs inside one interrupt, a short handler that the hardware starts on a timer tick (see interrupts and DMA). At 20 kHz the handler runs every 50 µs, and each time it does four things.

  1. It reads two phase currents from the ADC, and the rotor angle from the encoder.
  2. It turns them into two numbers: iq, the current that makes torque, and id, the current that makes none (Chapter 1).
  3. It compares each with its target and runs a PI controller on each (Chapter 3).
  4. It turns the two voltage answers back into three PWM duty values and writes them to the timer (Chapter 2).

The input is a torque command from an outer loop, often over CAN (see CAN and EtherCAT). The output is three numbers in timer registers. All the other firmware in the actuator exists to keep this one interrupt on time.

Why speed matters: delay costs angle

Every step takes time. The ADC converts. The CPU computes. The new duty values wait for the next PWM period before they act. So the correction you compute now arrives later.

Think of pushing a child on a swing. You push as the swing moves away. If you are late by a quarter swing, your push no longer helps, and if you are late by half a swing, you push against the motion. A loop does the same. A delay of τ seconds turns a wave of frequency f by 360 × f × τ degrees. In radians this is ω × τ, with ω = 2πf. Once the delay is long enough, the loop’s corrections add to the error instead of removing it.

Engineers count this in phase margin: the number of degrees of extra delay the loop can take before it feeds its own oscillation. A well tuned current loop starts with 90 degrees of margin, for a reason that Chapter 3 derives. The delay then eats the margin away. Drag the two sliders and watch it go.

Turn a wave with a delay

Teal is the correction the loop wants to apply. Warm is the same correction after the delay. The bar below shows how much of the 90 degrees of margin is left. Press a loop rate to load its delay.

1,000 Hz
75 µs

The 90 degrees is the margin of an ideal current loop whose controller cancels the motor’s electrical pole (derived in Chapter 3). The delay in the chips is 1.5 loop periods: one period to compute, half a period of PWM hold. Real loops add small extra delays from filters and gate drivers.

Now the numbers for our loop. At 20 kHz one period lasts 50 µs. Two delays add up to about 1.5 periods, or 75 µs (Chapter 3 shows where each comes from). The loop’s bandwidth is about 1 kHz. At 1 kHz a 75 µs delay turns the wave by 360 × 1,000 × 0.000075 = 27 degrees. The margin left is 90 − 27 = 63 degrees. The loop is calm.

At 5 kHz one period lasts 200 µs, and the delay grows to 300 µs. The same wave is now turned by 108 degrees. That uses the 90 degrees and 18 more. The margin is minus 18 degrees, so the loop is unstable. Press 5 kHz in the instrument at the top of the page to see it: the current vector no longer settles on its target, and it scribbles around it.

Symptom, then measurement, then fix

The symptom is a tone. You hear a steady whine at one pitch, the motor runs warm, and the current wiggles at one frequency. In our model the ring at 5 kHz sits near 0.9 kHz, which is well inside the range of human hearing.

The measurement has two parts. First, record one phase current and take its FFT, a method that turns a signal into the list of frequencies it contains. One tall peak means the loop is oscillating. Second, toggle a spare pin at the start and the end of the control interrupt, and read the true period and the true jitter on a scope.

The fix comes from comparing three things: the loop rate you really have, the gains you tuned, and the motor’s resistance R and inductance L. Tune with the rate you measured, not the rate you meant. Chapter 3 gives the rule of thumb: run the loop at least 10 to 30 times faster than its bandwidth.

The road

Each part of the instrument at the top has a chapter. The lesson walks them in the order the signals travel through the interrupt.

  1. Three phases to two axes: the frame change that turns spinning sine waves into two steady numbers.
  2. PWM, gate drivers and the ADC instant: how a number becomes a voltage, and when to read the current.
  3. The PI current loop: the gains, the delay, the limits, and the tuning rule.
  4. Encoders, observers and sensorless: where the rotor angle and speed come from.
  5. System identification: finding each motor’s real R, L and Kt as units and temperatures change.
  6. Faults: overcurrent, stall, a lost phase, and the safe way to switch torque off.
  7. Fleet scale: what to log so a field failure has a root cause.
  8. Field guide: the numbers, a checklist and one full FOC step in C.
A current loop is tuned for 1 kHz bandwidth and is stable at 20 kHz. A change makes it run at 5 kHz with the same gains. What happens, and why?

Chapter 1

Three Phases to Two Axes: Clarke and Park

Turn three spinning sine waves into two steady numbers, and see why only one of them makes torque

Put a current probe on each of the three motor wires and look at a scope. You see three sine waves, each shifted by a third of a cycle, all moving. Now the torque controller wants to say one calm thing: “give me 10 amps of torque current.” How do you compare a calm number with three moving waves?

The answer is a change of viewpoint. If you ride along with the rotor, the moving waves look still. This chapter builds that viewpoint in two steps, and the steps have names: the Clarke transform and the Park transform.

Three coils, one arrow

The three coils sit 120 degrees apart. Their currents are called ia, ib and ic. In a star-connected motor the three currents always add to zero, so two of them tell you the third: ic = −ia − ib. That is why firmware usually reads only two ADC channels.

Spin the motor with balanced currents and each current is a sine wave: ia = I·cos φ, ib = I·cos(φ − 120°), ic = I·cos(φ + 120°). Here φ is the electrical angle of the current. One electrical cycle is one trip of the magnetic pattern past a coil. A motor with p pole pairs (pairs of magnet poles) makes p electrical cycles per mechanical turn. Our maxon EC-i 40 has p = 7, so one turn of the shaft is 7 cycles.

Three waves, but one idea: a single arrow of length I that turns at the electrical speed. The three currents are just that arrow’s shadows on three axes. This arrow is the current space vector. Control becomes much simpler once you work with the arrow instead of the shadows.

Clarke: from three shadows to two

The Clarke transform draws two perpendicular axes, α and β, with α along coil a. It then reads the arrow’s shadow on each. Texas Instruments writes the result in its application report BPRA073, and Microchip writes the same in AN1078.

iα
The arrow’s shadow on the axis along coil a. It equals the coil-a current.
iβ
The shadow on the perpendicular axis. It needs ia and ib, and the √3 comes from the 120 degree geometry.

Here is where the formula comes from. Start with the full form, iα = (2/3)(ia − ib/2 − ic/2). Replace ic by −ia − ib and the bracket collapses to (3/2)·ia, so iα = ia. In the same way, iβ = (1/√3)(ib − ic) becomes (ia + 2·ib)/√3. The factor 2/3 keeps the arrow the same length as the phase peak. Both outputs are still sine waves, and they still move.

Park: ride along with the rotor

The Park transform turns the two axes to follow the rotor. It picks the d axis along the rotor magnet (the “direct” axis) and the q axis 90 degrees ahead of it (the “quadrature” axis). It needs one input from outside: the rotor’s electrical angle θ.

id
The part of the arrow along the rotor magnet. It makes no torque. TI calls it the flux component.
iq
The part of the arrow 90 degrees ahead of the magnet. This part makes the torque. TI calls it the torque component.
θ
The rotor’s electrical angle, from the encoder: p times the mechanical angle, minus a stored offset.

Think of standing on a merry-go-round. A horse that rides at your speed looks frozen. The arrow turns with the rotor, so in the rotor’s frame it stands still. Its two coordinates id and iq are plain DC numbers. A PI controller handles DC numbers well, and that is the whole reason for the transforms. TI states the result as torque ∝ ψR·iq, with ψR the rotor flux: torque is linear in iq, and id adds nothing.

Drive the device below. Press Play and watch the three waves move while id and iq stay flat.

Ride along with the rotor

Left, the three phase currents (faint) and the two numbers the controller sees, id and iq (bold). Right, the current arrow against the rotor’s d and q axes. Add an angle error and watch torque leak away.

10.0 A
0°

Amplitude-invariant Clarke and the Park rotation exactly as printed in TI BPRA073. Torque uses the toy rule torque = 46.1 mNm/A × iq (the catalog Kt of the maxon EC-i 40, 70 W, 36 V). The angle error is the gap between the angle the firmware believes and the true rotor angle, in electrical degrees.

A worked example, every step

Set the peak current to 10 A. The rotor sits at θ = 30 degrees, and the controller wants pure torque, so it places the arrow 90 degrees ahead, at 120 degrees. Then ia = 10·cos 120° = −5 A, ib = 10·cos 0° = 10 A, and ic = 10·cos 240° = −5 A. They add to zero, as they must.

Clarke gives iα = −5 A and iβ = (−5 + 2·10)/√3 = 15/1.732 = 8.660 A. Park at θ = 30 degrees (cos 30° = 0.866, sin 30° = 0.5) gives id = −5·0.866 + 8.660·0.5 = −4.330 + 4.330 = 0 A, and iq = −(−5)·0.5 + 8.660·0.866 = 2.5 + 7.5 = 10 A. All 10 amps are torque current. With Kt = 46.1 mNm/A the torque is 0.461 N·m.

Going the other way, the controller ends with voltages vd and vq. The inverse Park rotates them back, vα = vd·cos θ − vq·sin θ and vβ = vd·sin θ + vq·cos θ (TI BPRA073), and Chapter 2 turns vα and vβ into three duty cycles.

When the angle is wrong

Everything rests on θ. If the firmware’s angle is off by δ, the arrow lands δ degrees away from where the controller meant it. The true currents are then iq = I·cos δ and id = I·sin δ (up to sign). At δ = 20 degrees, iq = 9.40 A and id = 3.42 A: torque falls 6%, and 3.42 A flows for nothing but heat. At 90 degrees the torque is zero. Past 90 degrees it flips sign, and the speed loop above sees the wrong direction and may run away.

The symptom is weak, warm and noisy torque that differs between units. The measurement: command pure iq, spin the motor slowly, and look at the average id. It should be zero. The fix is an alignment procedure at start-up: drive a current along the d axis only, so the rotor snaps to a known electrical angle, then read the encoder and store the offset. Mind the factor p: with 7 pole pairs, a 1 degree error on the encoder shaft is a 7 degree error in θ.

The firmware’s rotor angle is wrong by 60 electrical degrees. You command 10 A of iq. What do you get?

Chapter 2

PWM, Gate Drivers and Where the ADC Samples

Turn a computed voltage into switch timing, and find the quiet instant when the current can be read cleanly

The loop has just decided: “put 12 volts on phase A.” But a microcontroller pin only gives 0 V or 3.3 V, and a few milliamps. The motor needs tens of volts and tens of amps. Something must sit between the two. That something is a bridge of switches, driven by rapid on and off pulses.

Switches and averages

Each phase has two power transistors, called MOSFETs. The high-side switch connects the phase wire to the supply, 36 V in our drive. The low-side switch connects it to ground. Together they form a half-bridge. One is on at a time, never both.

PWM, pulse-width modulation, flips the phase between the two rails very fast. The fraction of each period that the high side is on is the duty, D. The coil’s inductance smooths the current, so the motor feels only the average: D × 36 V. Duty 0.5 gives 18 V, duty 0.9 gives 32.4 V. The firmware sets D by writing a number into a timer register.

A motor feels differences between phases, not absolute levels. So the firmware may shift all three phase voltages up or down by the same amount for free. The usual choice centres them in the supply. A balanced sine of amplitude V then fits, as long as the spread between the highest and lowest phase stays within 36 V. That spread is at most √3 × V, so V can reach 36 / √3 = 20.8 V. This number is the voltage limit in the instrument at the top of the page, and the circle inside the hexagon of Microchip’s space-vector figure.

The timer: a triangle that counts

In centre-aligned PWM the timer counter climbs to a top value and then falls back, drawing a triangle. A pin is high while the counter is below that phase’s compare value. The pulses of all three phases are then centred on the same instants. Microchip’s AN1078 uses this mode because the motor sees pulses at twice the switching rate, which lowers the current ripple.

The period is set by the auto-reload register. One driver guide for STM32 gives the rate as fTIM / (2 × (ARR + 1) × (PSC + 1)), with the prescaler PSC. With the 72 MHz clock in that guide and PSC = 0, a value of ARR = 1199 gives 30 kHz. If the timer is clocked at 170 MHz (the top core speed of the STM32G431; check your own clock tree for the timer), ARR = 4249 gives 20 kHz, and a period of 50 µs.

Dead time: never short the supply

A MOSFET does not switch instantly. If the low side is still turning off while the high side turns on, current rushes from the supply straight to ground through both. This is shoot-through, and it destroys transistors. The cure is dead time: a short gap after one switch turns off and before the other turns on.

A gate driver chip sits between the timer and the MOSFETs. It provides gate current to turn them on fast, and it can add dead time of its own. The TI DRV8353 adds 50, 100, 200 or 400 ns on top of its automatic handshake, which watches each gate voltage. The STM32 timer has its own dead-time generator. The ST header macro uses DTG = dead time / tDTS for short gaps. With a 170 MHz timer clock, tDTS = 5.88 ns, so 200 ns needs DTG = 34.

Dead time has a cost. During the gap the current flows through the transistor body diode, and the phase voltage is wrong by about the bus voltage times the dead time times the PWM rate. For 200 ns at 20 kHz this is 36 × 0.0000002 × 20,000 = 0.144 V, a first-order textbook estimate, and the sign depends on the current direction.

When to read the current

The firmware must also measure the phase current. A small shunt resistor in each low-side leg turns current into a tiny voltage, and an amplifier scales it up for the ADC. The DRV8353 has three such amplifiers with gains of 5, 10, 20 or 40 V/V. With a 5 mΩ shunt and gain 10, each amp makes 50 mV. A bidirectional reading swings about VREF/2 minus 0.25 V, so with a 3.3 V reference the range is about 1.4 V / 0.05 V per amp = 28 A.

Switching is violent. Each time a MOSFET flips, the shunt signal rings. The DRV8353 datasheet lists the time for its amplifier to settle to within 1% after a 0.5 V step. It is 250 ns at gain 5, 500 ns at gain 10, 1 µs at gain 20 and 2 µs at gain 40. A higher gain means a longer wait.

The fix is to choose the instant. The shunts carry the motor current only while the low sides conduct. All three low sides conduct together at one turning point of the triangle, in the zero vector (all three outputs at ground). In a symmetric pattern the current at that instant also equals the average over the whole period, so the sample has no ripple bias. The ADC trigger comes from a timer output, so the hardware picks the instant, not the software. The ADC then finishes its conversion, and the interrupt starts.

The window shrinks as the duty grows. The low side conducts for (1 − D) × T. The reading needs the dead time before and after, and the settling time after the early edge. At 20 kHz and D = 0.9 the low side is on for 5.0 µs, and the quiet window is 5.0 − 2 × 0.2 − 0.5 = 4.1 µs. At D = 0.98 the low side is on for 1.0 µs and only 0.1 µs is quiet. Try this in the device.

Find the quiet instant

Top: the counter triangle and the pulses of phases A, B and C. Bottom: ringing on the current shunt after each edge. The faint warm band is where the shunt carries current, and the green band is the quiet part of it. Slide the pink ADC trigger or raise the duty.

70%
25.0 µs

Illustrative timing at 20 kHz (50 µs). Dead-time choices are the DRV8353 SPI options; the settling time of 500 ns (gain 10, ±1%) is from its datasheet, and the ring is modelled as a decay with that 1% time, a time constant of 109 ns and a toy 8 A start. Phase B sits 0.30 and phase C 0.55 below the busiest duty. Real ringing is messier and depends on the board layout.

The symptom of a bad instant is noisy current and jittery torque: the reading changes from sample to sample when the motor is standing still. The measurement: put one scope channel on a PWM pin and another on the ADC trigger or on a GPIO set at conversion start. The trigger must sit well away from every edge. The fix: move the trigger with the timer compare register that drives it, or lower the gain, or lower the maximum duty so that a quiet window always exists.

At 98% duty the ADC reads a noisy current when it triggers at the counter’s turning point. Which change fixes the cause?

Chapter 3

The PI Current Loop and Its Tuning

Choose two gains from the motor’s own numbers, see what the delay does to them, and stop the integrator from running away

You now have two steady numbers, id and iq, and a way to turn voltage commands into switching. What goes in the middle? You want iq to reach 10 A, fast, with no overshoot, and you want id to stay at zero. The controller that does this job in almost every motor drive is a PI controller: proportional plus integral.

What the motor does with a voltage

Apply a voltage to one axis and the current does not jump. Microchip’s AN1078 writes the model in one line: v = R·i + L·di/dt + e. R is the winding resistance, L its inductance, and e the back-EMF. With the back-EMF set aside, a voltage step makes the current rise like a charging bucket. It takes a time L/R to reach 63% of its final value. For our motor (0.512 mH and 0.582 Ω phase to phase) this electrical time constant is 0.88 ms, and it is the same for one phase, since halving both numbers leaves the ratio alone.

The two gains

A PI controller computes the voltage as v = Kp·e + Ki·∫e dt, where e is the error, the target minus the measured current. The proportional part pushes in proportion to the error right now. The integral part adds up the error over time and removes the last small gap. Together they hold iq exactly at its target, whatever the resistance or the back-EMF.

There is a clean way to pick the two gains. Write the controller as Kp·(s + Ki/Kp)/s and the motor as 1/(L·(s + R/L)). Choose Ki/Kp = R/L. The controller’s zero then cancels the motor’s pole, and the loop collapses to Kp/(L·s): a plain integrator. Its closed loop is a first-order response with bandwidth ωc = Kp/L.

Kp
The proportional gain, in volts per amp. It sets how hard the loop pushes on today’s error.
Ki
The integral gain, in volts per amp per second. It sets how fast the stored error builds.
ωc
The bandwidth you choose, in radians per second: 2π times the frequency in hertz. The current follows commands up to about this speed.

Here is the worked example for our motor and a bandwidth of 1 kHz. Step 1: ωc = 2π × 1,000 = 6,283 rad/s. Step 2: Kp = 0.256 mH × 6,283 = 1.609 V/A. Step 3: Ki = 0.291 Ω × 6,283 = 1,828 V/(A·s). Step 4: in firmware the integral is added once per sample, so the code uses Ki × Ts = 1,828 × 0.00005 = 0.0914 V/A per sample. Check: Ki/Kp = 1,136 rad/s equals R/L = 0.291 / 0.000256 = 1,137. A 10 A step then makes the first output 1.609 × 10 = 16.1 V, under the 20.8 V limit.

The delay eats the margin

With the pole cancelled the loop is an integrator, and an integrator turns waves by 90 degrees: that is the 90 degrees of margin from Chapter 0. Now count the delay. The controller reads the current at one sample, computes for one full period, and the new duty takes effect at the next period. On top of that the PWM holds that duty for a whole period, which looks like another half period of lag. The total is 1.5 periods.

At the crossover that delay costs 360 × fc × 1.5 × Ts degrees. Call r = fs / fc the number of samples per bandwidth cycle. Then the margin is 90 − 540 / r degrees. At r = 20 it is 63 degrees, at r = 10 it is 36, and at r = 6 it is zero. This is why engineers sample 10 to 30 times faster than the bandwidth, the rule from the latency-budget lesson of this series.

The model confirms the formula. At a 1 kHz bandwidth, a 20 kHz loop overshoots a 10 A step by 1.9% and a 40 kHz loop by 0.1%. A 10 kHz loop overshoots by 44%, and a 5 kHz loop never settles. Move the sliders in the device and find the edge yourself.

Tune it, then break it

Left, the phase margin for every pair of loop rate and bandwidth. Right, the response to a current step, and below it the stored integral. Make the step large, then switch anti-windup on and off.

1.0 kHz
20 kHz
10 A

The same model as the instrument at the top: maxon EC-i 40 (R 0.291 Ω, L 0.256 mH per phase), gains from the pole-zero rule, a one-sample compute delay, voltage clipped at 20.8 V. The margin shown is the formula 90 ° − 540 ° / r; the step response is the sampled model itself. Anti-windup here stops the integral while the output is clipped.

Windup: when the voltage runs out

The bus is finite. A 30 A step asks for 1.609 × 30 = 48 V, but the limit is 20.8 V, so the output clips. The current climbs at the fastest rate the supply allows. Meanwhile the error is large, and the integral term keeps adding 0.0914 × 30 = 2.7 V every sample, though the output cannot move. This is integrator windup.

When the current finally reaches 30 A, the integral holds tens of volts of stored push. The current shoots past the target (13% in the model, peaking at 34 A) and the integral needs time to drain. The symptom is overshoot on big steps only, and a loop that behaves on small ones. The measurement: log the integral term and the clip flag. The fix is anti-windup. Microchip’s AN1078 subtracts a share of the excess (Sum = Sum + Ki·Err − Kc·Excess, with Kc often set equal to Ki), and the simpler version used here freezes the integral while the output is clipped.

ctypedef struct { float kp, ki_ts, i; } pi_t;   /* ki_ts = Ki * Ts, folded in once */

/* One PI step for one axis. limit is the voltage this axis may use (volts). */
static inline float pi_step(pi_t *c, float err, float limit)
{
    float u = c->kp * err + c->i;            /* P term plus stored I term */
    float out = u;
    if (out >  limit) out =  limit;
    if (out < -limit) out = -limit;
    if (out == u)                          /* not clipped: keep integrating */
        c->i += c->ki_ts * err;
    return out;                              /* volts for this axis */
}

One more effect shows up once the shaft spins. The d and q axes push on each other: a term ω·L·iq appears in the d equation, and ω·L·id in the q equation, with ω the electrical speed. In our model at 3,000 rpm (ω = 2,199 rad/s) the first is 5.6 V at 10 A, and the back-EMF adds 9.7 V on the q axis. Feeding those terms forward cuts the id disturbance during a step from 2.9 A to 0.8 A. These are the standard dq voltage equations of a permanent-magnet motor; the model above uses them.

Your loop runs at 20 kHz, tuned for 2 kHz bandwidth, and rings badly. What does the margin formula say, and what is the best first move?

Chapter 4

Encoders, Observers and Sensorless

Get the rotor angle and the speed from a sensor that only counts, and learn when you can do without the sensor

A joint turns slowly, 100 rpm, and you ask the speed loop for a smooth ride. The torque you get is a stutter. The cause is not the current loop. The speed reading jumps between zero and nearly 300 rpm, and the speed loop faithfully answers every jump. This chapter explains where the angle and speed come from, and why the speed is the harder number.

An encoder only counts

A quadrature encoder has two output signals, A and B, that go high and low in a pattern as the shaft turns. The order of the pattern tells the direction. Each change is one count. A timer in its encoder mode adds up the counts in hardware, so the firmware reads a plain integer. With N counts per revolution, the shaft angle is counts × 2π / N. The encoder lesson in this series, encoders and the position loop, goes deeper into the signals.

The angle feeds Chapter 1. The Park transform needs the electrical angle: θ = p × (mechanical angle − offset). Take N = 4,096 counts and p = 7 pole pairs. One count is 360° × 7 / 4,096 = 0.615 electrical degrees. That is fine for FOC: the cos 0.6° error is almost nothing.

Why speed is harder

The speed loop and the angle observers want a speed. The obvious way is to subtract: speed = (this count − last count) × 2π / (N × Ts). But a count is a whole number. The smallest nonzero speed reading is one count per sample, which is 2π / (N × Ts). With N = 4,096 and Ts = 50 µs this is 30.7 rad/s, or 293 rpm.

Now run the shaft at 100 rpm, which is 10.5 rad/s. In one 50 µs sample the shaft moves 10.5 × 0.00005 = 0.00052 rad, or 0.34 counts. So most samples show zero counts, and one sample in three shows one count. The estimate reads 0, 0, 293, 0, 0, 293. The average is right and each reading is wildly wrong. This is quantisation noise: the error of rounding a smooth angle to whole counts, made large because the sample time is so short.

Three remedies, and their prices

The first remedy is a longer window. Subtract the count from M samples ago and divide by M × Ts. The step shrinks by M. With M = 20 (1 ms) it is 293 / 20 = 14.7 rpm. The price is delay: the answer describes the speed about M × Ts / 2 = 0.5 ms ago.

The second remedy is to time the gap between counts instead of counting them. This helps at low speed. It needs a capture timer and a rule for a missing edge, and it is outside our model.

The third remedy is an observer: a small model that predicts where the shaft should be, and corrects itself with each measurement. A common form is a tracking loop. Call the measured angle θ and the estimate θ̂. Then θ̂ advances at the estimated speed plus a correction 2ωo(θ − θ̂), and the estimated speed ω̂ grows by ωo²(θ − θ̂) each second. The two gains put both poles of the error at −ωo, the critical damping. A constant speed gives zero error. A constant acceleration a leaves a steady error of a / ωo².

The bandwidth ωo is the knob. With ωo = 2π × 200 Hz = 1,257 rad/s and an acceleration of 100 rad/s², the steady error is 100 / 1,257² = 63 µrad, which is tiny. A higher ωo follows faster changes but lets more quantisation through. A lower one is quieter but lags. You pay for noise with lag, whichever method you choose. Drive the device and find the trade.

Count the noise

Blue is the true speed, which wobbles a little at 30 Hz. Purple is what the estimator reports from encoder counts alone. Lower the speed or the counts per turn to see the noise, then fix it.

100 rpm
20 samples

A 20 kHz loop (Ts = 50 µs) reading an ideal encoder, with the true speed varying by ±20% at 30 Hz. The error is the RMS gap to the true speed over the last 15 ms. Counts per turn are after x4 decoding. A real encoder adds edge jitter and index errors that this model leaves out.

Sensorless: infer the angle from the motor itself

A spinning magnet makes a voltage in the windings, the back-EMF. Its phase tells you where the rotor is. Sensorless FOC reads that voltage with a model instead of a sensor. Microchip’s AN1078 keeps a digital copy of the motor, i(n+1) = F·i(n) + G·(v − e), with F = 1 − Ts·R/L and G = Ts/L. For its example motor the note measures 5.34 Ω and 3.84 mH line to line. It halves both for one phase, 2.67 Ω and 1.92 mH, and at 20 kHz F is 0.9304 and G is 0.026. The copy runs beside the real motor. The gap between its current and the measured current is pushed back through a sliding-mode correction, and the filtered correction is the estimated back-EMF, whose α and β parts give the angle.

Look at the catch. Back-EMF is proportional to speed. At standstill it is zero, so the angle is unknown. AN1078 says this plainly: the estimator needs a minimum speed, so the start-up drives the motor open loop with a ramp until the estimate locks. A robot joint that must hold a position at zero speed cannot use this. A fan, pump or compressor can, and that is the note’s target.

At 50 rpm the raw one-sample speed estimate reads 0 most of the time and sometimes a large value. What is the right diagnosis and fix?

Chapter 5

System Identification Across Units, Temperature and Load

Measure each motor’s real resistance, inductance and torque constant, and keep the gains honest as the motor heats up

You tuned the current loop on one motor, on a cool bench, and it was perfect. Now two hundred actuators ship with the same gains. Most behave. A few, mounted next to a hot gearbox, whine after ten minutes of work. A handful hum from the first power-up. The code is identical in all of them. The motors are not.

What the gains secretly depend on

Chapter 3 set Kp = L·ωc and Ki = R·ωc. Those gains hold the motor’s numbers inside them. A copy of a design is only right if the motor matches the numbers you used. Three things move the numbers.

Unit to unit. No two motors are exactly alike. The winding, the magnet strength and the air gap vary a little, and the inductance L can differ by a large share.

Temperature. Copper resistance rises about 0.39% per kelvin (0.0039 per K at 20 °C). From 25 °C to 125 °C our phase resistance grows from 0.291 Ω to 0.404 Ω, a factor of 1.39. The magnets also weaken. A typical neodymium magnet loses about 0.12% of its strength per kelvin, so over the same 100 K the torque constant Kt falls by about 12%, from 46.1 to 40.6 mNm/A. The catalog limit for the winding of our maxon motor is 155 °C.

Load. At high current the iron can saturate, and then L drops.

See what each does to the loop. Suppose L is 40% lower than the design value. The bandwidth Kp/L rises by 1/0.6, so by 67%. At a design of 1.2 kHz with a 20 kHz loop, r falls from 16.7 to 10. The margin 90 − 540/r falls from 58 to 36 degrees, and the loop rings. If R rises by 39%, the zero no longer cancels the pole exactly, which adds a little overshoot. And if the magnets weaken, the loop still holds iq, but the shaft makes less torque than you asked for.

Measure the plant: a step test

System identification means measuring the motor’s real parameters by exciting it and fitting a model. For R and L the test is simple. Hold the rotor still, so it makes no back-EMF. Apply a fixed voltage V on the d axis and record the current at the loop rate. A coil charges like a bucket: i(t) = (V/R)·(1 − e−t/τ), with τ = L/R.

Two numbers fall out. The final current is V/R, so R = V / i∞. The time the current needs to reach 63% of its final value is τ, so L = R × τ. Worked example with V = 2 V on our motor: i∞ = 2 / 0.291 = 6.87 A. τ = 0.256 mH / 0.291 Ω = 0.88 ms, which is 17.6 samples at 20 kHz. The current reaches 63% of 6.87 A, which is 4.33 A, after about 18 samples. A fit to all samples, rather than one point, averages the noise. A 12-bit ADC over the 56 A span (28 A each way) has a step of 56 A / 4,096 counts = 13.7 mA. A single sample is then good to about 1 part in 500 of a 7 A signal, and many samples help more.

Kt is measured in a different way. Spin the motor with zero current by another machine or a load, read the q-axis voltage, and divide by the electrical speed: that voltage is the flux linkage times the speed. Or apply a known iq and read the torque from a load cell. The values go into a record that the end-of-line station writes to flash, one per unit.

Temperature has a trick. Resistance is a thermometer: T = 25 + (R/R25 − 1)/0.0039. Measure R again during use and you know the winding temperature without a sensor in the winding, as long as you trust the 0.0039 value. Many boards also have a temperature sensor, an NTC, near the power stage, but it reads the board, not the copper.

Drive the device. Choose a unit, set a temperature, and run the step test. Then compare the closed-loop step with the fleet gains and with gains rebuilt from the fitted R and L.

Identify, then retune

Left, the step test on the chosen unit: noisy samples and the purple fit. Right, an iq step with the fleet gains (warm) and with gains rebuilt from the fit (purple). The loop is tuned for 1.2 kHz at 20 kHz.

25 °C

The units are illustrative: A is the catalog motor (R 0.291 Ω, L 0.256 mH per phase); B has 6% more R and 40% less L; C has 4% less R and 30% more L. Real spreads are not published here. The step test applies 2 V, adds 0.05 A of noise and a 13.7 mA ADC step, and fits R from the last quarter of the samples and the time constant from the log of the rise. Copper 0.39% per K and magnets 0.12% per K as in the Field Guide.

Symptom, measurement, fix

The symptom is a fleet that behaves in the lab and misbehaves in the field: units ring when hot, units differ from each other, torque falls short on a warm day. The measurement is to plot the ring frequency, or the step overshoot, against the unit and its temperature. The fix has three layers. Run the step test at start-up and store R and L for each unit. Rebuild Kp and Ki from the stored values. Scale the torque command by Kt(T), so that a torque request becomes the right iq at the present temperature.

A motor runs at 85 °C. The current loop holds iq perfectly. Which statement is right?

Chapter 6

Faults: Overcurrent, Stall, Lost Phase, Safe Torque Off

Catch each failure on its own time scale, switch torque off safely, and measure how long the reaction takes

A robot arm lowers its gripper onto a table that was not supposed to be there. The shaft stops. The controller does what it was told: it raises the current to push through. For ten seconds nothing looks wrong, because the current stays inside its limit. Then the winding insulation starts to smell. The loop did its job. Nobody told it what to do when the job could not be done.

Faults happen on very different clocks. A short circuit takes microseconds to wreck a transistor. A broken wire takes milliseconds to show. A stalled shaft takes seconds to cook a winding. One detector cannot cover all three, so a drive stacks them in layers.

Three layers of defence

LayerCatchesTime scaleWho acts
Gate-driver monitorShort circuit, MOSFET overcurrent1 to 8 µsThe driver chip, with no CPU
Software limit in the current loopOvercurrent, a lost phasetens to hundreds of µsThe control interrupt
Thermal modelStall, overload, a hot windingsecondsA slower task

The first layer is hardware. The TI DRV8353 watches the voltage across each power MOSFET. When a MOSFET carries too much current, its drain-source voltage (VDS) climbs. If VDS stays above a threshold for longer than a short deglitch time (a wait that ignores brief spikes), the chip declares an overcurrent. The threshold is programmable from 0.06 V up to 2 V. The deglitch time is 1, 2, 4 or 8 µs. The chip can latch off, retry after a delay, only report, or ignore the event. It does this without waiting for the CPU.

Take a MOSFET with 2 mΩ on-resistance (an illustrative figure): a trip at 0.1 V is a trip at 50 A.

The second layer is software. In the current-loop interrupt the firmware compares each measured current with a limit. One bad sample must not trip it, because an ADC glitch is not a fault. So the rule asks for N samples in a row. This is a window: the detector must see the condition N times before it acts. The price is time. The reaction takes N samples to detect, plus about one sample to act.

How fast must it be? A short at the motor terminals pushes current through two phases. The supply drives it at most at di/dt = V / L = 36 V / 0.512 mH = 70 A per millisecond. Take a limit of 35 A and a window of 3 samples at 20 kHz, starting from 8 A. The current crosses 35 A after 0.38 ms, the third sample over the limit comes at about 0.52 ms, and the reaction follows one sample later. The current peaks near 48 A. A limit set too low trips in normal work: this motor may run a 20 A peak legitimately.

The slow fault: stall and heat

A stalled shaft at 20 A of iq looks fine to the instant limit. Heat tells another story. In the dq frame the winding loses P = 1.5 × R × (id² + iq²). For iq = 20 A and R = 0.291 Ω, P = 1.5 × 0.291 × 400 = 175 W. The maxon catalog gives a thermal resistance from winding to housing of 2.27 K/W and a winding thermal time constant of 24.9 s, with a 155 °C winding limit. If the housing stays at 25 °C (true for the first minute or so), the winding would climb 175 × 2.27 = 396 K at steady state. It reaches the 130 K rise to 155 °C after t = −24.9 × ln(1 − 130/396) = 9.9 s. The thermal model must trip before that.

Software tracks this by integrating the power, the I²R heating, through a model of the winding. A trip at 140 °C leaves a margin and fires after 8.5 s. Real firmware adds the board’s temperature sensor, but the model reacts to the copper itself. The model here holds R at its 25 °C value; a hot winding has higher R, so the real heating is faster still.

The quiet fault: a lost phase

A cracked solder joint or a loose connector leaves one phase open. The two other phases then carry the current, torque ripples, and the motor runs hot and noisy. One test: phase A reads almost nothing (under 5% of its expected peak) while the torque command is large (|iq| above 2 A). But a healthy phase current crosses zero twice per cycle, and near each crossing it is briefly under 5% of its peak. At 1,000 rpm with 7 pole pairs the electrical frequency is 117 Hz, and each crossing lasts about 0.14 ms. The window must be longer than that, or a healthy motor trips.

Break it on purpose

Choose a fault and press Inject. The pink mark is the instant the firmware reacts. Change the limit and the window and see whether it is early enough, or whether it trips for no reason.

35 A
3 samples

Illustrative: 20 kHz loop; a short grows at 70.3 A/ms from an 8 A working current; the 50 A gate-driver trip assumes a 2 mΩ MOSFET at 0.1 V with a 4 µs deglitch; 100 A is a made-up absolute limit. The stall uses the maxon EC-i 40 thermal numbers (2.27 K/W, 24.9 s, 155 °C) with the housing held at 25 °C and a fixed 20 A. The lost-phase test uses a 5% level on a 10 A, 1,000 rpm wave. The window and the limit are yours to choose.

Reacting: switch torque off safely

Once a fault is confirmed, what should the drive do? The simplest reaction is Safe Torque Off (STO). IEC 61800-5-2 defines it as a function that stops the drive supplying energy that can make torque, and drive makers map it to the uncontrolled stop of IEC 60204-1. The firmware turns off all six switches. The motor coasts. STO does not brake. A vertical arm joint can fall under its own weight, and the drive manuals warn that STO alone does not stop an unwanted restart. So the reaction is a design choice per fault: ramp the current down first when the fault is slow, cut the power stage at once when it is fast, and plan for gravity. The safety lesson, fail-safe and functional safety, builds this out.

Treat faults as features of the firmware, not as patches. Test them by injecting them: pull a phase on the bench, force a current sample over the limit in a unit test, replay a stall in simulation. Then measure the time from the injection to the gate-off on a scope. Write the number down. A reaction that has never been measured is a guess.

A stalled joint holds 20 A, under the software current limit, and the winding is at 25 °C. What protects the winding?

Chapter 7

Fleet Scale: Telemetry and Root Cause

Decide what each actuator must record, so that a failure in the field has a cause you can find

A joint stops working in a warehouse far away. The only thing the log says is “motor error”. You cannot tell a bad magnet from a bad connector, or a bad connector from a bug in last month’s firmware. You have one failed unit and no history. The unit might be a symptom of a batch of a thousand. You cannot know.

Chapters 5 and 6 gave each actuator numbers and fault codes. This chapter asks what to keep, how to keep it cheaply, and how to read it across a whole fleet.

You cannot send everything

Count the raw data first. The current loop runs at 20 kHz. Say it records six values per sample (three phase currents, id, iq and the angle), two bytes each. That is 20,000 × 6 × 2 = 240,000 bytes per second from one actuator. A fleet of 1,000 would make 240 MB per second. No radio link or cloud bill accepts that. So the actuator must summarise on the spot.

Four kinds of record do most of the work.

  1. Identity. The serial number, the firmware build, the hardware revision, and the lots of winding and magnet from the end-of-line record. Without these, nothing can be sliced.
  2. Identified parameters. The values from Chapter 5: R at 25 °C, L, Kt, and the encoder offset. A slow change in R at 25 °C or in Kt over months is a sign of wear.
  3. Histograms. Instead of streaming temperature, keep 16 counters that count how many seconds the winding spent in each temperature band. Do the same for peak current, bus voltage and the control interrupt’s run time. Sixteen two-byte counters, thirty-two bytes, tell a story that would take megabytes as raw samples.
  4. A flight recorder. A ring buffer that always holds the last stretch of fast data. When a fault trips, freeze it and send it. A buffer of 256 samples at 20 kHz is 12.8 ms. With six two-byte channels it takes 256 × 6 × 2 = 3,072 bytes of RAM, small enough for most microcontrollers.

Each fault record also carries a fault code, a time stamp, the winding-temperature estimate, and the detector’s own state: how many samples were over the limit, and the limit in force. A fault with no state is a fault you can only guess at.

Two habits keep these records useful for years. First, version the record format: put a schema number in every record, so that old units and new units can be read by the same tool. Second, stamp each record with the build and a clock value, and store it until a link is available, the idea behind store and forward. A record with no time cannot be lined up with a heat wave, a software release or a shipment.

One unit tells you little, a fleet tells you a lot

A single actuator overshooting a current step by 25% might mean its inductor is weak. It might also mean a bad day. A thousand actuators show something sharper: a distribution, the shape of how often each value occurs. If most units overshoot by about 8% and a small hump sits at 22%, a subpopulation exists, a group of units that share a cause.

The next step is to slice the units by the identity fields. Colour the hump by winding lot, by firmware build, by site. The right slice explains the hump: every unit in it comes from one category. The wrong slices do not: they spread the hump evenly across their categories. This is cause-finding by elimination, and it only works if the identity was logged.

The sample size matters. With 50 units, a 6% subpopulation is three units, and three dots do not make a pattern. With 2,000 units it is about 120, and the pattern is plain. This is why the telemetry must be designed before the first unit ships. A month of data from 1,000 units is worth more than the best lab test of ten.

Find the bump

Each unit ran its own current-step self-test. Left, the overshoot of all reporting units. Right, for the split you pick, the share of each group above 15%. Choose a split, then add units.

300

Synthetic data, seeded so it is the same on every visit. Healthy units overshoot by about 8% (spread 2%). Winding lot 7, 6% of the fleet, overshoots by about 22% (spread 3%) because its inductance is low. Firmware builds A and B and five sites are assigned at random, so they cannot explain anything. The 15% line and every figure here are illustrative, not measurements of real fleets.

Symptom, measurement, fix

The symptom is a field failure with no root cause. The measurement is a fleet table of identity, parameters, histograms and fault records. The fix is a loop: guess a cause, slice for it, ship a change to a few units first, and watch the same histogram. Rolling out a firmware change to a small group (a canary) and comparing it to the rest is a clean test. The lessons on debug, trace and observability and bootloaders and over-the-air updates cover the tools that make this safe.

1,000 units show a hump of high overshoot. Coloured by firmware build, the hump spreads evenly across builds A and B. Coloured by winding lot, it falls entirely in one lot. What follows?

Chapter 8

Field Guide

Keep the numbers, the terms, one full FOC step in C and a checklist you can run on a real board

You can now follow one torque command from end to end. The command becomes an iq target. A timer fires 20,000 times a second. At a quiet instant, the ADC reads two phase currents. The Clarke and Park transforms turn them, with the rotor angle, into the steady numbers id and iq. Two PI controllers, tuned from the motor’s own R and L, turn the errors into voltages. The inverse transforms and the PWM turn those voltages into switch timing. All of this fits in about 50 µs, and the delay it adds to the loop decides how much bandwidth is safe.

The numbers that matter

WhatNumberWhere it comes from
Our motor, maxon EC-i 40, 70 W36 V; R 0.582 Ω, L 0.512 mH (phase to phase); Kt 46.1 mNm/A; 7 pole pairsmaxon catalog page 309, part 496655
Thermal limits of that motorwinding to housing 2.27 K/W; winding time constant 24.9 s; winding limit 155 °Cmaxon catalog page 309
Electrical time constantL / R = 0.88 msComputed from the above
Clarke, Park, inverse Parkiβ = (ia + 2ib)/√3; id = iαcosθ + iβsinθ; iq = −iαsinθ + iβcosθTI BPRA073; Microchip AN1078
Torquetorque ∝ iq; 0.461 N·m at 10 A with the catalog KtTI BPRA073; SimpleFOC; our toy use of Kt
Voltage limitVdc / √3 = 20.8 V at 36 VDerived (centred phases)
PI gains from a bandwidthKp = Lωc = 1.609 V/A and Ki = Rωc = 1,828 V/(A·s) at 1 kHzDerived (pole-zero cancellation)
Phase margin of the loop90° − 540° / r, with r = loop rate / bandwidth; zero near r = 6Derived (delay 1.5 periods)
Model results at 1 kHz bandwidthovershoot of a 10 A step: 0.1% at 40 kHz, 1.9% at 20 kHz, 44% at 10 kHz, unstable at 5 kHzThe lesson’s sampled model
PWM ratef = fTIM / (2 (ARR + 1)(PSC + 1)); 72 MHz and ARR 1199 give 30 kHzSpinner SVPWM guide for STM32
Dead time50, 100, 200, 400 ns (DRV8353 SPI); 200 ns is DTG 34 at 170 MHzDRV8353 datasheet; ST LL timer header
Dead-time voltage error36 V × 200 ns × 20 kHz = 0.144 VTextbook first-order estimate
Current amplifier settling (±1%)250, 500, 1000, 2000 ns at gain 5, 10, 20, 40 V/VDRV8353 datasheet
Gate-driver overcurrentVDS trip 0.06 to 2 V; deglitch 1, 2, 4 or 8 µsDRV8353 datasheet
Worked example in a noteHurst motor at 20 kHz: F = 0.9304, G = 0.026Microchip AN1078
Encoder speed step4,096 counts at 50 µs: 293 rpm per count; 0.615° electrical per count at 7 pole pairsComputed
Temperature driftcopper +0.39% per K; NdFeB Br about −0.12% per K (range −0.09 to −0.12)Textbook copper value; Advanced Magnets
Stall at 20 A175 W; 396 K steady rise; 9.9 s to 155 °CComputed from the maxon numbers
Telemetry budgetraw 240 kB/s per actuator; 256-sample recorder 3,072 bytesComputed

One FOC step, as code

This is the whole interrupt in C for a Cortex-M4F such as the STM32G4. It is a sketch, not a drop-in driver: the helpers enc_rad, adc_a and adc_b stand for your own code, and the timer polarity and the ADC zero offset need setting on your board. It reuses pi_step from Chapter 3.

c/* Runs once per PWM period (20 kHz). The ADC is triggered by the timer in the quiet window (Ch 2). */
extern pi_t pi_d, pi_q;                         /* gains from L and R (Ch 3, Ch 5) */
extern float vdc, id_ref, iq_ref, theta_off;

void foc_step(void)
{
    /* 1. Read two shunt currents. 12-bit counts, 56 A span: 0.01367 A per count. */
    float ia = (adc_a() - ADC_ZERO) * AMPS_PER_COUNT;
    float ib = (adc_b() - ADC_ZERO) * AMPS_PER_COUNT;

    /* 2. Electrical angle from the encoder (Ch 4); p = 7. */
    float th = POLE_PAIRS * enc_rad() - theta_off;
    float s = sinf(th), c = cosf(th);

    /* 3. Clarke then Park (Ch 1). */
    float ial = ia, ibe = (ia + 2.0f * ib) * 0.57735027f;
    float id =  ial * c + ibe * s;
    float iq = -ial * s + ibe * c;

    /* 4. Two PI loops (Ch 3). Circle limit Vdc/sqrt(3); the d axis goes first. */
    float vmax = vdc * 0.57735027f;
    float vd = pi_step(&pi_d, id_ref - id, vmax);
    float vq = pi_step(&pi_q, iq_ref - iq, sqrtf(fmaxf(vmax*vmax - vd*vd, 0.0f)));

    /* 5. Inverse Park, inverse Clarke (Ch 1). */
    float val = vd * c - vq * s, vbe = vd * s + vq * c;
    float va = val, vb = -0.5f * val + 0.8660254f * vbe, vc = -0.5f * val - 0.8660254f * vbe;

    /* 6. Centre the three voltages in the supply, then turn them into duty (Ch 2). */
    float hi = fmaxf(va, fmaxf(vb, vc)), lo = fminf(va, fminf(vb, vc)), off = -0.5f * (hi + lo);
    TIM1->CCR1 = (uint32_t)((0.5f + (va + off) / vdc) * ARR_TOP);
    TIM1->CCR2 = (uint32_t)((0.5f + (vb + off) / vdc) * ARR_TOP);
    TIM1->CCR3 = (uint32_t)((0.5f + (vc + off) / vdc) * ARR_TOP);
}

The bring-up checklist

Where this sits

This is the lowest loop of a robot joint. Above it sit the velocity and position loops (encoders and cascaded loops), the bus that brings it commands (CAN and EtherCAT), and the safety logic that decides when to cut it (fail-safe and functional safety). Below it sit the timer and the interrupt (timers, PWM and sampling, interrupts and DMA).

Keep going

Sources

The takeaway. A torque command is a current command, the current is held by a loop, and the loop’s speed is a budget that delay spends. Know your motor’s R, L and Kt for this unit at this temperature, read the current at the quiet instant, and measure how long every fault takes to switch the torque off.
Which order is right for one FOC step?

Now press Present or Teach and explain one control interrupt out loud, from memory. Say what it reads and why it reads at that instant. Say what the two transforms do and how the gains come from R and L. Say what the delay costs and what you would measure on a scope. Then go back to the instrument and break the loop on purpose with the 5 kHz button.

The Current Loop at 20 kHz: Motor Control Firmware
Back to Gleams