Field-Oriented Control transformed brushless DC motors from fast but torque-rippled machines into the smooth, precise actuators found in modern EV drivetrains and robotics. If you have ever wondered how a Tesla Model 3 motor achieves linear torque from zero to 18,000 RPM, the answer is FOC running at 20 kHz on a DSP core.
Why FOC?
Conventional trapezoidal (6-step) commutation produces significant torque ripple at commutation points. FOC replaces this with continuous sinusoidal currents that track rotor position precisely. The trade-off is computational complexity — which modern Cortex-M4/M7 MCUs handle comfortably at 20 kHz control loops.
Clarke and Park Transforms
Clarke Transform
Converts three-phase [Ia, Ib, Ic] into two-axis stationary frame [I-alpha, I-beta]:
Park Transform
Rotates [I-alpha, I-beta] by electrical rotor angle theta_e to produce DC quantities [Id, Iq]:
The Complete FOC Control Loop
- Sample Ia and Ib via shunt resistors at PWM valley for minimum switching noise
- Clarke transform: [Ia, Ib] to [I-alpha, I-beta]
- Read rotor angle from encoder, resolver, or sensorless observer
- Park transform: [I-alpha, I-beta] to [Id, Iq] using theta_e
- Two independent PI loops regulate Id to 0 and Iq to Iq_ref
- Inverse Park: [Vd, Vq] to [V-alpha, V-beta]
- Space Vector PWM: generates gate signals — 15% more DC bus utilization vs sinusoidal PWM
Implementing on STM32G4 with CORDIC
The STM32G4’s CORDIC hardware accelerator computes sin/cos pairs in just 4 clock cycles — vs 30-60 cycles for software calls. Critical when the FOC loop must execute in under 5 us at 20 kHz PWM:
Sensorless: Sliding Mode Observer
When no shaft encoder is available, the SMO estimates back-EMF from measured voltages and currents, then extracts position via arctangent:
- Applicable above 5-10% of rated speed
- Typical estimation error: +/-3-5 electrical degrees at rated speed
- No additional hardware required beyond current sensors
- Combine with I/f open-loop startup below minimum SMO speed
Conclusion
FOC on STM32 requires CORDIC for transforms, center-aligned PWM with synchronized ADC triggers, and carefully tuned PI loops. At Firmness Technologies, we implement production FOC firmware for EV traction drives, servo actuators, and industrial compressors — always with HIL validation before hardware deployment.
