Run Real-Time Simulation of Permanent Magnet Synchronous Motor
This example shows how to run a real-time simulation of a permanent magnet synchronous motor (PMSM) that is externally controlled at high switching frequency. The real-time application runs on a Speedgoat® target computer that has an IO334 I/O module installed. To open the models in this example and build the real-time application requires these products:
Simulink Real-Time Target Support Package
Speedgoat I/O Blockset
Speedgoat HDL Coder™ Integration Package
Speedgoat IO334-325K I/O module with IO334-21 plugin
HDL Coder is required for design customizations.
You can use the Simulink Real-Time model and its corresponding bitstream file to simulate a permanent magnet synchronous motor system that is externally controlled in closed-loop at high switching frequency (100kHz) with sufficiently small time step (50 nanoseconds).
Simulink Model for Permanent Magnet Synchronous Motor System
The permanent Magnet synchronous motor system model is a physical system in Simulink. The system consists of three components, an inverter block, a permanent magnet synchronous motor block, and an incremental encoder block. The HDL-compatible Simulink implementation of the subcycle-averaging inverter block reads the PWM duty-cycle from "Gates" inport and DC voltage input from "V_plus" and "V_minus", and outputs the line voltages from outport "Vll_abc". You can set its fault flag from Fault_Word port.
The permanent magnet synchronous motor block is an HDL Coder compatible implementation of a three-phase exterior permanent magnet synchronous motor (PMSM) with sinusoidal back electromotive force. It takes the input line voltage from the subcycle-averaging inverter block and outputs shaft angular velocity, shaft angular position, three phase currents, and motor torque. This block can also take an external speed or torque as input.
The Simulink implementation of quadrature encoder converts the angular position of the motor shaft to digital pulses. To see more details, open the model:
model = 'slrt_ex_pmsm'; open_system(fullfile(matlabroot,'toolbox','slrealtime','examples',model));
set_param(model, 'SimulationCommand', 'Update');
load_system('slrt_ex_pmsm') open_system('slrt_ex_pmsm/Motor and Inverter HDL Wrapper/Motor and Inverter Mathmatical Models')
This model verifies the three-phase output currents and encoder's digital signals resulting from the input torque signal. To see how the model works, simulate the model.
This example also provides the corresponding Simulink Real-Time interface model and the bitstream generated by using the HDL Workflow Advisor, which you can download to a Speedgoat FPGA I/O 334-21 target.
model_gm = 'slrt_ex_pmsm_gm'; open_system(fullfile(matlabroot,'toolbox','slrealtime','examples',model_gm));
1. Reconfigure the parameters for PMSM system to your values from the PMSM configuration block mask.
2. Make sure that the development computer has a connection to the target computer.
3. Make sure that the bitstream file is in your working folder, build the model, and download the real-time application to the target computer. On the Real-Time tab, click Run on Target. Or, use the
slbuild command and the
4. Run the real-time application by using the Run on Target button.
5. Open the Simulation Data Inspector by double-clicking the Simulation Data Inspector icon or by using the
The FPGA bitstream file
MotorAndInverterHDLWrapper.mcs is available in the Simulink Real-Time examples folder.
For the Motor Control Blockset version of this example that demonstrates hardware-in-the-loop (HIL) simulation of PMSM, see Field-Oriented Control (FOC) of PMSM Using Hardware-In-The-Loop (HIL) Simulation (Motor Control Blockset).
Close All Open Files