Permanent-Magnet Synchronous Machine
This example shows an inverter-fed, 8-pole, surface-mount permanent-magnet synchronous machine (PMSM) with an outer speed regulator and an inner hysteresis-type current controller.

Electrical and Machine Model
The inverter circuit is modeled as an ideal three-legged bridge with a stiff 310 VDC supply. The phase currents are being measured for closed-loop current control. A hysteresis controller is implemented to control the switching of the three legs of the inverter. This AC motor is a synchronous machine with surface-mounted magnets (Ld=Lq). The machine is modeled to have a sinusoidal back electromotive force (EMF). It is assumed that the magnetic strength of the rotor magnets is unchanged during the operation. The load torque on the PMSM is modeled using a Controlled Torque Source. A more detailed description about the PMSM can be found here.
Control
The speed of the PMSM is regulated by an outer speed loop using a PI controller with an anti-windup mechanism. The output of the PI controller is the torque-producing quadrature current setpoint (iq*) for the electric machine. It is translated into an equivalent phase current setpoint (iabc*). The measured phase currents are compared to the corresponding reference currents. The error signal created as the difference between the two is then fed into a hysteresis current controller to generate the switching signal for each inverter leg.
Simulation
Run the simulation with the model as provided to view the behavior at startup followed by a change in the load torque. The machine is accelerated from standstill to the desired speed in the first 12.7 ms. During the acceleration, the PI controller output is saturated and the maximum machine torque is applied. At steady state, the average torque generated by the machine is equal to the load torque.
The PMSM initially experiences a constant load torque of 3 Nm. At 40 ms, the load torque is stepped down to 1 Nm. In order to maintain the desired speed, the outer speed regulator reduces the current setpoint resulting in lower amplitude of the fundamental of the phase currents. The magnitude of the torque ripple remains unchanged due to the unchanged hysteresis band of the current controller.
Save the trace of the stator currents in the "is_abc" scope. Label this as "Speed=700". Next, change the speed setpoint (w_ref) to 350. Rerun the simulation. Notice that the fundamental frequency of the stator currents are halved when the machine speed is halved.