The problem
Almost every modern EV traction drive uses a permanent-magnet synchronous motor with field-oriented control, because it gives smooth torque, high efficiency and fast response. The concepts (reference frames, decoupled current control, voltage limits) are often taught only as equations. A full simulation shows how each block contributes and gives a base for later work on field weakening and sensorless control.
Objectives
- Model a surface-mounted PMSM and a three-phase inverter.
- Implement Clarke, Park and inverse Park transforms and SVPWM.
- Tune d- and q-axis current PI controllers from motor parameters.
- Add an outer speed loop and test torque and speed steps.
- Compare an average-value inverter model with a switching one.
What you need
Tools and toolboxes
- Simulink — Controller, transforms, logging and multi-rate structure.
- Simscape Electrical — PMSM block, three-phase inverter (average or switching) and DC source.
- Motor Control Blockset — Clarke Transform, Park Transform, Inverse Park Transform, Space Vector Generator and PI controller blocks. Optional: the same transforms can be built from basic Simulink blocks.
Software
- MATLAB R2023b or later
- Simulink
- Simscape Electrical
- Motor Control Blockset (optional)
Extra parts and data
None beyond the software above.
Key concepts
- Clarke and Park transforms
- Clarke turns three phase currents into two stationary components (α, β); Park rotates them by the rotor angle into d and q components that are constant in steady state.
- Torque equation
- For a surface PMSM, Te = 1.5·p·ψm·iq, so torque is controlled by iq while id is held at zero below base speed.
- Current loop tuning by pole cancellation
- Choosing Kp = L·ωc and Ki = R·ωc cancels the winding's R–L pole, giving a first-order closed loop with bandwidth ωc.
- Space-vector PWM
- A modulation method that synthesises the reference voltage vector from adjacent inverter states, using about 15 per cent more of the DC-link voltage than sine-triangle PWM in the linear range.
Step-by-step guide
- 1
Set example motor and inverter parameters
Choose a labelled example for a two-wheeler traction motor: 48 V DC link, 4 pole pairs, Rs = 0.05 ohm, Ld = Lq = 0.2 mH, permanent-magnet flux linkage 0.012 Wb, J = 0.005 kg·m², rated current 100 A peak. Compute rated torque from 1.5·p·ψm·iq and the base speed at which back-EMF reaches the available voltage Vdc/√3. Put everything in a script.
Checkpoint: Script prints rated torque of about 7.2 N·m and a base speed consistent with Vdc/√3 for the example.
- 2
Build the motor and inverter
Place the Simscape Electrical PMSM block with the parameters, an inertia and a load torque source. Start with an average-value three-phase inverter driven by duty cycles, which runs fast and is enough to tune controllers. Measure phase currents and rotor angle from the block. Use a fixed-step discrete or local solver with a 1 µs plant step and a 100 µs controller rate (10 kHz).
Checkpoint: Applying balanced three-phase voltages at a fixed frequency spins the motor at the matching synchronous speed.
- 3
Implement the transforms
Add Clarke and Park Transform blocks (or build them from Gain and Trigonometric Function blocks) and convert electrical angle as pole pairs times mechanical angle. Test them open loop: with the motor spun at constant speed by a velocity source and phase currents injected, id and iq must be constant. Check the sign conventions and angle alignment, since a wrong offset is the most common FOC bug.
Checkpoint: With a pure q-axis current injected, the Park output shows iq constant and id near zero.
- 4
Tune the current loops
Choose a current loop bandwidth, for example 2π·500 rad/s, well below the 10 kHz sampling rate. Set Kp = L·ωc and Ki = R·ωc for both axes, and add decoupling feed-forward terms (−ωe·Lq·iq on d, +ωe·(Ld·id + ψm) on q). Limit the voltage vector magnitude to Vdc/√3 and use anti-windup. Test iq steps with the rotor locked, then at speed.
Checkpoint: An iq step from 0 to 50 A reaches 63 per cent in roughly 1/ωc (about 0.3 ms) with negligible coupling into id.
- 5
Add SVPWM and the speed loop
Feed the inverse Park outputs into a Space Vector Generator to produce duty cycles. Add an outer PI speed loop running at 1 kHz whose output is iq*, saturated at rated current, with id* = 0. Tune the speed loop to roughly one tenth of the current loop bandwidth. Apply speed steps with and without load torque. Keep a record of the speed-loop gains and the iq limit, as they set the maximum acceleration the drive can achieve.
Checkpoint: Speed step to half base speed settles without overshoot beyond your target, with iq saturating briefly during acceleration.
- 6
Verify torque and steady state
At several operating points log electromagnetic torque from the motor block and compare with 1.5·p·ψm·iq. Check that phase currents are sinusoidal with the expected amplitude, and that id stays at zero. Use Simulation Data Inspector to overlay commanded and measured currents and speed, and record steady-state errors. Include at least one point in generating mode with negative iq, and confirm that DC-link power reverses sign as expected during regeneration.
Checkpoint: Measured torque matches the equation within a few per cent at all tested points.
- 7
Switch to a switching inverter
Replace the average inverter with a switching bridge of ideal switches at 10 kHz and rerun the same tests. Compare current ripple, torque ripple and simulation time. Use a smaller fixed step (for example 0.5 µs) and check that halving it changes nothing meaningful. Note how much more slowly the switching model runs and when each model should be used.
Checkpoint: Switching and average models agree on mean torque and speed, with visible ripple only in the switching model.
- 8
Run a drive profile and report
Drive the model with a speed demand derived from a short urban drive-cycle segment and a road-load torque, and log energy drawn from the DC link. Write up the parameter derivation, tuning method, test results and the comparison of inverter models. Mention that operation above base speed needs field weakening, which this design does not include. Quote the energy figure as a model result for the example parameters, not a property of any real motor.
Checkpoint: A report with reproducible plots, the tuning calculations and a clear statement of the operating range covered.
Testing & validation
- Park transform outputs are constant in steady state with correct angle alignment.
- Current step response matches the designed bandwidth.
- Torque matches 1.5·p·ψm·iq at several points.
- Speed loop tracks steps under load without instability.
- Average and switching inverter models agree on mean quantities.
Expected results
A complete, tuned FOC drive model of a PMSM with documented current and speed loop design, verified torque production, and a comparison of average and switching inverter models.
Take it further
- Add field weakening for operation above base speed.
- Model an interior PMSM with Ld < Lq and add MTPA control.
- Add encoder quantisation and delay and measure their effect.
- Replace the rotor angle sensor with a sliding-mode observer.
Viva and review questions
Why is id set to zero in a surface PMSM below base speed?
With Ld = Lq there is no reluctance torque, so torque depends only on iq; any id adds copper loss without adding torque.
How did you choose the current controller gains?
By pole cancellation: Kp = L·ωc and Ki = R·ωc, which cancels the R–L pole and leaves a first-order loop with bandwidth ωc, chosen well below the sampling frequency.
Why decouple the d and q axes?
In the rotating frame each axis voltage contains a speed-dependent term from the other axis current; feeding these forward stops a change in one current disturbing the other.
Why start with an average-value inverter?
It runs much faster and has no switching ripple, so controller tuning is quicker; the switching model is then used to confirm the result and see ripple.
Learn it at DIYguru
These DIYguru courses and programmes teach what this project needs.
