Main Content

sschdl.generateOptimizedModel

R2026b

Replace Simscape switches, converter blocks, and machine blocks with optimized equivalents for FPGA deployment

Since R2024a

    Description

    generatedModel = sschdl.generateOptimizedModel(input) returns an optimized model for FPGA deployment. The function replaces common Simscape™ switches, converter blocks, and machine blocks with their optimized equivalents and generates an optimized model. To learn more about dynamic (optimized) switch replacement, see Generate HDL Code for Simscape Models by Using Dynamic Switch Approximation.

    example

    generatedModel = sschdl.generateOptimizedModel(input,Name=Value) replaces Simscape switches or PMSM (Simscape Electrical) block, or machine blocks with optimized equivalents and tunes the parameter values for the dynamic switches using one or more name-value arguments.

    The generated optimized model has the same name as input but with the suffix _generated. Once the optimized model is generated, open the model and verify the connection. Connect any gate signal inports of the replaced blocks to their respective sources and remove additional Simulink-PS Converter (Simscape) blocks.

    example

    Examples

    collapse all

    Open the three-phase PMSM drive model at the MATLAB® command prompt.

    open_system("sschdlexThreePhasePMSMDrive")
    

    Open the Three-phase inverter subsystem that contains Simscape blocks.

    open_system("sschdlexThreePhasePMSMDrive/Three-phase inverter")
    

    To optimize the model for FPGA deployment, use the ReplaceSwitches name-value argument and run the sschdl.generateOptimizedModel function at the MATLAB command prompt.

    generatedModel = sschdl.generateOptimizedModel("sschdlexThreePhasePMSMDrive",ReplaceSwitches=true);
    
    The following blocks have been replaced: 
    'sschdlexThreePhasePMSMDrive/Three-phase inverter/IGBT A(H)'
    'sschdlexThreePhasePMSMDrive/Three-phase inverter/IGBT A(L)'
    'sschdlexThreePhasePMSMDrive/Three-phase inverter/IGBT B(H)'
    'sschdlexThreePhasePMSMDrive/Three-phase inverter/IGBT B(L)'
    'sschdlexThreePhasePMSMDrive/Three-phase inverter/IGBT C(H)'
    'sschdlexThreePhasePMSMDrive/Three-phase inverter/IGBT C(L)'
    
    Saving sschdlexThreePhasePMSMDrive as sschdlexThreePhasePMSMDrive_generated and replacing switch and converter blocks with equivalent FPGA HIL supported blocks.
    

    The generated optimized model for the three-phase PMSM drive model is saved as sschdlexThreePhasePMSMDrive_generated. In this model, the Three-phase inverter subsystem contains the replaced blocks.

    Open the PMSM drive model.

    open_system("sschdlexPMSMDriveSimscapeMotor")
    

    Optimize the model for FPGA deployment by replacing the Simscape™ PMSM (Simscape Electrical) block with an optimized equivalent.

    Use the ReplacePMSM name-value argument with the sschdl.generateOptimizedModel function at the MATLAB command prompt.

    generatedModel = sschdl.generateOptimizedModel("sschdlexPMSMDriveSimscapeMotor",ReplacePMSM=true);
    
    Warning: 'ReplacePMSM' is being deprecated and will be removed in a future
    release. Please use 'ReplaceMachines' instead of 'ReplacePMSM'. 
    The following blocks have been replaced: 
    'sschdlexPMSMDriveSimscapeMotor/Simscape Plant/Permanent Magnet Synchronous Motor'
    
    The following Rotational Motion Sensor blocks have been replaced: 
    'sschdlexPMSMDriveSimscapeMotor/Simscape Plant/Encoder/Ideal Rotational Motion Sensor'
     These blocks now output angular position values wrapped in the range [0,2pi).
    The HIL optimized machine blocks operate in either Torque-driven or Speed-driven mode. In the machine block, set the appropriate mode for the External load parameter based on whether there is a torque or speed source in the mechanical network. Inertia in the mechanical system must be modeled externally to the machine (in Speed-driven mode) or within the machine (in Torque-driven mode). The optimized machine block does not support modeling external inertia while in Torque-driven mode.
    Saving sschdlexPMSMDriveSimscapeMotor as sschdlexPMSMDriveSimscapeMotor_generated and replacing switch, converter, and machine blocks with equivalent FPGA HIL supported blocks.
    

    The generated optimized model for the three-phase PMSM drive model is saved as sschdlexPMSMDriveSimscapeMotor_generated. In this model, the Simscape PMSM block is replaced with an optimized PMSM block.

    Input Arguments

    collapse all

    Simscape model name or a cell array of Solver Configuration (Simscape) block paths, specified as a character vector or string scalar, or a cell array of character vectors or string scalars. You can specify a Solver Configuration block attached to the Simscape network that you want to optimize within the model.

    Data Types: char | string | cell

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: generatedModel = sschdl.generateOptimizedModel("sschdlexThreePhasePMSMDrive",ReplaceSwitches=1);

    Example: generatedModel = sschdl.generateOptimizedModel("sschdlexTwoPhaseDCDCConverterExample",AveragedSwitch=1);

    Example: generatedModel = sschdl.generateOptimizedModel("sschdlexHalfWaveRectifierExample",FineTune=true);

    Since R2024b

    Option to replace Simscape switches in the model, specified as numeric or logical 1 (true) or 0 (false).

    The supported switches and converter blocks include:

    Data Types: logical

    Since R2024b

    Option to replace Simscape PMSM (Simscape Electrical) block in the model, specified as numeric or logical 1 (true) or 0 (false). On replacement of the Simscape PMSM block with an equivalent optimized PMSM block, the Simscape network splits and a secondary Solver Configuration (Simscape) block is automatically added and connected.

    The sschdl.generateOptimizedModel function generates an optimized PMSM block with the initial conditions computed for the original Simscape model. You can check the initial conditions of the Simscape PMSM block by using the Configure 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 change parameters in the original Simscape model, rerun the sschdl.generateOptimizedModel function to generate optimized PMSM block with updated initial conditions.

    When you replace the PMSM (Simscape Electrical) block, the sschdl.generateOptimizedModel function also replaces the Ideal Rotational Motion Sensor (Simscape) block with an optimized equivalent that wraps the angular position calculation to the range [0, 2π). This wrapping prevents numeric errors that can accumulate during long-running simulations, eliminating validation mismatches in angular position, speed, and current between the generated HDL implementation model and the Simscape model.

    Note

    The ReplacePMSM name-value argument will be removed in a future release. To replace the Simscape PMSM (Simscape Electrical) block in the model, use the ReplaceMachines name-value argument instead.

    Data Types: logical

    Since R2026b

    Option to replace Simscape machine blocks in the model with their optimized equivalents for FPGA HIL deployment, specified as numeric or logical 1 (true) or 0 (false).

    The supported machine blocks are:

    Tip

    If you modify parameters in the original Simscape model after generating the optimized model, rerun the sschdl.generateOptimizedModel function to regenerate the optimized model with initial conditions updated to reflect the modified model parameters.

    The sschdl.generateOptimizedModel function generates an optimized machine block with the initial conditions computed for the original Simscape model.

    To verify the initial conditions, use Variable Viewer. In the model window, on the Debug tab, click Simscape > Variable Viewer. To learn more about Variable Viewer, see Configure the Variable Viewer (Simscape).

    If you change parameters in the original Simscape model, update the initial conditions in the optimized model:

    1. Update parameters in the original Simscape model.

    2. Rerun the sschdl.generateOptimizedModel function to generate optimized PMSM block with updated initial conditions.

    3. Continue with the Simscape HDL Workflow Advisor or parameter tuning using the new optimized model.

    When you replace a machine block, the sschdl.generateOptimizedModel function also replaces the Ideal Rotational Motion Sensor (Simscape) block with an optimized equivalent that wraps the angular position calculation to the range [0, 2π). This wrapping prevents numeric errors that can accumulate during long-running simulations, eliminating validation mismatches in angular position, speed, and current between the generated HDL implementation model and the Simscape model.

    Data Types: logical

    Since R2024b

    Option to replace all Simscape switches in the model with the dynamic equivalents of Averaged Switch, specified as numeric or logical 1 (true) or 0 (false).

    Data Types: logical

    Since R2026a

    Option to enable fine-tuning of the parameter values for dynamic switches in the generated optimized model, specified as numeric or logical 1 (true) or 0 (false).

    Dependencies

    To fine-tune the parameter values for the dynamic switches, you require a Simulink® Design Optimization™ toolbox license.

    Data Types: logical

    Output Arguments

    collapse all

    Path of the generated model that is optimized for HDL code generation, returned as a structure array.

    In the generated optimized model, when you double-click any dynamic switch block, the parameter values of block parameters Conductance and Time scaling are set to Gs and s respectively, and are configured by using a Simulink.Parameter object. The values Gs and s are stored in the base workspace and referenced from the block.

    Limitations

    • In the model, if a parameter references any workspace variable or an expression, then the parameter value is replaced by the evaluated value.

    • To be compatible for replacement with the ReplaceMachines option, the Simscape machine blocks must use the parameter configurations listed in this table:

      ParameterPMSM (Simscape Electrical)BLDC (Simscape Electrical)FEM-Parameterized PMSM (Simscape Electrical)Hybrid Excitation PMSM (Simscape Electrical)Switched Reluctance Machine (Simscape Electrical)
      Modeling optionNo thermal portNo thermal port2-D partial derivative data | No thermal portNo thermal portNo thermal port
      Electrical connectionExpanded three-phase portsExpanded three-phase ports—Expanded three-phase portsExpanded three-phase ports
      Winding typeWye-wound or Delta-wound Wye-wound or Delta-wound Wye-wound or Delta-wound Wye-wound or Delta-wound —
      Modeling fidelityConstant Ld, Lq and PMConstant Ld and Lq—Constant Ld, Lq, Lmf, Lf, and PM—
      Stator parameterizationSpecify Ld, Lq, and L0Specify Ld, Lq, and L0—Specify Ld, Lq, and L0Specify parametric data
      Permanent magnet flux linkage parameterizationSpecify flux linkage————
      Zero sequenceExcludeExclude—Exclude—
      Rotor angle definitionAngle between the a-phase magnetic axis and the q-axisAngle between the a-phase magnetic axis and the q-axis—Angle between the a-phase magnetic axis and the q-axis—
      ModelNoneNoneNone—None
      Rotor damping'0''0''0''0''0'
      Ld matrix, Ld(id,iq)NonzeroNonzeroNonzeroNonzero—
      Lq matrix, Lq(id,iq)NonzeroNonzeroNonzeroNonzero—
      Back EMF profile—All Back EMF profile options supported———
      Interpolation method——Linear——
    • The generated optimized machine block operates in either torque-driven or speed-driven mode. Set the External load parameter to 'Torque-driven' or 'Speed-driven' based on whether the mechanical network applies a torque or speed load to the motor. In torque-driven mode, model inertia within the motor. In speed-driven mode, model inertia externally in the mechanical network. The optimized machine block does not support modeling external inertia in the mechanical network while in torque-driven mode.

    Version History

    Introduced in R2024a

    expand all