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 learn how you can use the sschdl.generateOptimizedModel
function to convert the 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) 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 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. The PMSM is a nonlinear block in the model. The Three-phase inverter subsystem has the switching elements as 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.
sim("sschdlexPMSMDriveSimscapeMotor") open_system("sschdlexPMSMDriveSimscapeMotor/Scope")
Generate Optimized PMSM Model
You can modify this model to optimize it for FPGA deployment by replacing the Simscape PMSM block in the model with an optimized PMSM block. The generated optimized PMSM can operate in either Torque-driven
or Speed-driven
mode set . In the PMSM block, set the appropriate mode under External load parameter 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 generate equivalent tunable parameters in the optimized model, set the parameters in the Simscape PMSM block 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
. On replacement of the Simscape PMSM block with an equivalent optimized PMSM block the Simscape network splits. In the generated optimized model, copy the Solver Configuration block and connect to the mechanical network.
To open the optimized model, in the MATLAB® command prompt, enter:
open_system("sschdlexPMSMDriveOptimizedMotor")
When you simulate this model, the results 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
sschdl.generateOptimizedModel
| sschdladvisor
| hdladvisor
| sschdl.updateRuntimeParameters