Main Content

Optimize Simscape Three-Phase PMSM Drive Model for Efficient HDL Code Generation and Synthesis

This example shows how to generate an optimized three-phase PMSM model from a Simscape™ model using a PMSM block optimized for FPGA deployment.

Simscape Model with PMSM Block Optimized for FPGA Deployment

In this example, you use the sschdl.generateOptimizedModel function to convert a Simscape three-phase permanent magnet synchronous motor (PMSM) model to an optimized equivalent for HDL code generation and synthesis. First, you replace the Simscape PMSM (Simscape Electrical) block with an equivalent optimized PMSM block and generate an HDL implementation model by using the Simscape HDL Workflow Advisor. Then, for this implementation model, you generate the HDL code and synthesize the results by using the guided steps in the HDL Workflow Advisor. For more information, see HDL Workflow Advisor Tasks. You can then deploy the generated HDL code onto a Speedgoat® FPGA I/O module.

Generating an optimized model by replacing the Simscape PMSM block with an optimized PMSM block provides:

  • Improved resource utilization on FPGA boards

  • Improved timing on hardware facilitating higher switching frequency

  • Dead time stability when using the Backward Euler local solver

  • Tunability for run-time parameters (Simulink tunable parameters and Simscape run-time parameters) on the FPGA

Set Up Synthesis Tool Path

To synthesize the generated HDL code, before you use HDL Coder™ to generate code, set up your synthesis tool path. For example, if your synthesis tool is Xilinx® Vivado®, install the latest version of Xilinx Vivado as shown in HDL Language Support and Supported Third-Party Tools and Hardware.

Then, set the tool path to the installed Xilinx Vivado executable by using the hdlsetuptoolpath function:

hdlsetuptoolpath('ToolName','Xilinx Vivado','ToolPath','C:\Xilinx\Vivado\2022.1\bin\vivado.bat')

Permanent Magnet Synchronous Motor (PMSM) Model

The PMSM drive model is a physical system in Simscape. This model uses field-oriented control (FOC) to control the speed of a three-phase PMSM. You can use the PMSM and a three-phase inverter in a typical hybrid vehicle. In the model, inside the Simscape Plant subsystem, the Permanent Magnet Synchronous Motor is a nonlinear block. The Three-phase inverter subsystem has the switching elements as insulated gate bipolar transistors (IGBTs) modeled using dynamic switches. In the model, the inverter is connected to the battery. This model runs at a time step of 1 μs with a switching frequency of 25 kHz.

Open the model in the MATLAB® command prompt.

open_system("sschdlexPMSMDriveSimscapeMotor")

To see the waveforms, simulate the model and open the Scope block.

sim("sschdlexPMSMDriveSimscapeMotor")
open_system("sschdlexPMSMDriveSimscapeMotor/Scope")

Generate Optimized PMSM Model

You can optimize this model for FPGA deployment by replacing the Simscape PMSM block with an optimized PMSM block. To generate equivalent tunable parameters in the optimized model, set the parameters in the Simscape Permanent Magnet Synchronous Motor block of sschdlexPMSMDriveSimscapeMotor > Simscape Plant subsystem as run-time parameters.

To optimize the model, run the sschdl.generateOptimizedModel function at the MATLAB® command prompt:

generatedModel =
sschdl.generateOptimizedModel("sschdlexPMSMDriveSimscapeMotor","ReplaceSwitches",0,"ReplacePMSM",1);

The generated optimized model for the three-phase PMSM drive model is saved as sschdlexPMSMDriveSimscapeMotor_generated. When the Simscape PMSM block is replaced with an equivalent optimized PMSM block, the Simscape network splits and a secondary Solver Configuration (Simscape) block is automatically added and connected.

You can check the initial conditions of the Simscape PMSM block by using the Variable Viewer (Simscape). To open the Variable Viewer, in the model window, on the Debug tab, click Simscape > Variable Viewer. The sschdl.generateOptimizedModel function automatically sets initial conditions for the optimized PMSM block based on the original Simscape model. If you tune the run-time parameters in the generated optimized model, rerun the sschdl.generateOptimizedModel function to generate optimized PMSM block with updated initial conditions.

The generated optimized PMSM can operate in either torque-driven or speed-driven mode. In the Permanent Magnet Synchronous Motor block inside the Simscape Plant subsystem, set External load parameter to Torque-driven or Speed-driven based on whether there is a torque or speed load in the mechanical network. Inertia in the mechanical system must be modeled externally to the motor (in speed-driven mode) or within the motor (in torque-driven mode). The optimized PMSM block does not support modeling external inertia while in torque-driven mode.

To open the optimized model, at the MATLAB® command prompt, enter:

open_system("sschdlexPMSMDriveOptimizedMotor")

When you simulate this model, the waveforms of this model and the original Simscape model are same. To see how the model works, simulate the model.

sim("sschdlexPMSMDriveOptimizedMotor")
open_system("sschdlexPMSMDriveOptimizedMotor/Scope")

Generate HDL Code and Synthesize the Results

To generate the HDL code, first generate an HDL implementation model from the Simscape model by using the Simscape HDL Workflow Advisor. The Advisor converts the Simscape plant model to an HDL-compatible implementation model from which you generate HDL code.

To open the Advisor, run the sschdladvisor function for the Simscape Plant subsystem of your model.

sschdladvisor("sschdlexPMSMDriveOptimizedMotor/Simscape Plant")

After the task passes in the Advisor, you see a link to the generated HDL implementation model. You generate HDL code for this generated HDL implementation model and synthesize the HDL code. For details about the HDL code generation and synthesis of code, see Generate FPGA Bitstream for Two-Phase DC-DC Converter with Tunable Run-Time Parameters.

You can select the data type precision in the Generate implementation model task pane of the Simscape HDL Workflow Advisor. For generating the synthesis results, set the Target Frequency (MHz) to 105 in Set Target Frequency task of HDL Workflow Advisor.

See Also

| | |

Topics