USE CASE

A motor switches at 20 kHz. Control has to make that smooth.

Power electronics is brutal at the bottom and elegant at the top. At the bottom, a converter chops DC on and off thousands of times a second and a motor is a tangle of cross-coupled three-phase currents. At the top, field-oriented control turns that into two clean knobs — torque and flux — you can command independently. This program walks the whole stack: the switching converter, the averaged model you design on, the dq machine, the FOC that decouples it, the PWM that realizes it, and the cascade speed loop that drives a load.

A field-oriented torque command tracked crisply while the flux current stays pinned at zero — decoupled torque control
0.034%
buck output-voltage regulation error
0.0 A
flux current under FOC torque step
96.0%
rated drive efficiency
0.285%
speed residual after a load step
10
design notebooks
5 / 5
requirements PASS
THE SWITCHING LAYER

Everything starts as a square wave.

A buck converter regulates voltage by switching — full-on, full-off, thousands of times a second — and letting an inductor and capacitor average the result. The switched simulation shows the real thing: a triangular inductor-current ripple riding on the DC, and an output that settles to its setpoint within 0.034%. This is the raw material; every smooth quantity higher up is a controlled average of something that's actually chopping.

A switched buck converter's triangular inductor-current ripple and its regulated output voltage settling to 12 V
The switched buck: the inductor current ripples as a triangular sawtooth at the switching frequency (top) while the output voltage regulates to 12 V within 0.034% (bottom). The ripple is real and ever-present — control is the art of getting a smooth average out of it.
THE PROBLEM

A three-phase motor's currents fight each other.

Transform the machine into the rotating dq frame and a spinning three-phase motor becomes two currents: id (flux) and iq (torque). But they're cross-coupled — command a torque-producing voltage and the flux current gets stirred along with it, and vice versa. Open-loop, a step in one axis disturbs the other by several amps. You can't independently set torque without first untangling that coupling.

An open-loop PMSM where a voltage step on the torque axis disturbs the flux current — cross-coupling
The cross-coupling problem: in the open-loop dq machine a step on the torque (q) axis stirs the flux (d) current by several amps. The two axes are tangled together — which is exactly what field-oriented control exists to fix.
Under FOC the torque current tracks its step command crisply while the flux current stays pinned at zero
The hero — field-oriented control: with the right transform and decoupling feedforward, the torque current (iq) tracks its step command crisply (0.74% error) while the flux current (id) stays pinned at zero. Two decoupled knobs out of a tangled three-phase machine — that's what makes a motor controllable.
REALIZING IT

Turn the voltage command back into switching.

The controller computes a smooth dq voltage; the inverter can only switch. Inverse-Park plus carrier PWM turns the command into the actual on/off pole voltages, and the motor's inductance averages them back into a near-sinusoidal phase current. The smooth current the controller assumed and the chopped voltage the hardware delivers are two views of the same thing — the PWM is the bridge between them.

A switched three-phase pole voltage producing a near-sinusoidal phase current through the motor inductance
Carrier PWM: the inverter's switched pole voltage (top, ±Vdc) is what the hardware actually applies; the motor inductance averages it into the near-sinusoidal phase current the control design assumed (bottom). Square in, sine out.
DRIVING A LOAD

Wrap a speed loop around the torque.

Torque control is the inner loop; a real drive commands speed. A cascade adds an outer speed PI that asks the FOC torque loop for exactly the torque needed — so the motor tracks a speed reference and shrugs off a load-torque disturbance (a 3 N·m step recovers to 0.285% residual). Past base speed, field weakening drives the flux current negative to trade torque for range, extending usable speed well past where a fixed-flux drive runs out — at a rated efficiency of 96%.

A cascade speed loop tracking a speed reference and rejecting a load-torque step disturbance
The cascade speed loop: an outer speed PI commands the FOC torque loop, tracking the speed reference and rejecting a 3 N·m load step down to 0.285% residual. Inner torque loop, outer speed loop — the standard drive architecture, built up from the switching layer.
VALIDATION

Every number re-derived at sign-off.

The V&V notebook rebuilds the converter, machine and controllers from scratch and re-derives the requirements, printing a PASS/FAIL board.

ResultRequirement
Buck output regulation0.034%R-01 < 2%
Averaged-model fidelity0.257 V RMSR-02 < 0.5 V
FOC torque-step decouplingiq 0.74% / id 0 AR-03
Speed-loop load rejection0.285%R-04 < 2%
Rated efficiency96.0%R-05 > 88%
HONEST SCOPE

Ideal switches, real control.

The deliverable is ten notebooks and the dossier — the models are switched ODEs with callbacks, not an acausal network. The switches are idealized (no device-level conduction/switching-loss physics beyond a lumped model), the thermal model is lumped, sensors are ideal with no estimation delay, and the PWM is carrier/sinusoidal rather than full space-vector with dead-time; the exact FOC decoupling is helped by the machine being non-salient. What the program does deliver is the complete drive stack — converter, averaging, dq machine, FOC, PWM, cascade speed control, field weakening — on reproducible numbers, the inverter-and-control layer one level below the EV-vehicle flagship.

Design your own motor drive.

Book a walkthrough and we'll set up your converter, machine and control loops, and run the switching, FOC and drive-cycle studies live.

DjiniousLabOne engineering notebook for model-based design — model, simulate, and generate on a living digital replica.