Modeling Guidelines for Simscape Subsystem Replacement
To generate HDL code for Simscape™ algorithms, you generate an HDL implementation model by using the Simscape HDL
Workflow Advisor. If you follow certain guidelines when modeling the Simscape algorithm, the Simscape HDL Workflow Advisor replaces the Simscape subsystem with a corresponding
HDL Subsystem block in the HDL
implementation model. The
HDL Subsystem block contains the state-space
algorithm that uses HDL-compatible Simulink® blocks instead of Simscape blocks. You can generate HDL code for the
HDL Subsystem block
and deploy the code onto FPGA target devices and FPGAs on board Speedgoat® FPGA I/O modules. In this case, when you select the Generate
validation logic for the implementation model check box in the
Generate implementation model task of the Simscape HDL Workflow
Advisor, the Advisor generates a separate state-space validation model. This model compares
the outputs from the
HDL Subsystem and the original Simscape subsystem to verify that they are functionally equivalent.
If you do not follow the guidelines, the Simscape HDL Workflow Advisor might not be able to perform this replacement. In that case, the HDL implementation model contains the state-space algorithm with the original Simscape subsystem beside it. Before generating code, you modify the implementation model and rearrange the blocks such that it replaces the Simscape subsystem with the state-space algorithm. In this case, when you select the Generate validation logic for the implementation model check box, the Advisor places a validation logic subsystem inside the implementation model to verify functional equivalence.
In addition to these guidelines, make sure that the Simscape model is configured for compatibility with Simscape HDL Workflow Advisor. See Modeling Physical Systems in Simscape for HDL Compatibility.
Enclose Simscape Blocks Inside a Subsystem
Enclose the Simscape blocks for which you are generating an HDL implementation model inside a Subsystem block and provide the test inputs. Inside the Subsystem block, your model can have multiple hierarchies that use Simscape blocks.
Do not use masked subsystems. The Simscape HDL Workflow Advisor cannot replace masked subsystems in the HDL implementation model. For automatic subsystem replacement, you can use masked subsystems that have cosmetic masks. Cosmetic masks are masks that only have an icon but don't have any parameters or initialization code.
Inside the Subsystem block that contains Simscape blocks, at the input ports, add Simulink-PS Converter (Simscape) blocks. At the output ports of this subsystem, add PS-Simulink Converter (Simscape) blocks.
Use a meaningful name for the Simulink-PS Converter and PS-Simulink Converter blocks.
The Simscape HDL Workflow Advisor uses the names of the Simulink-PS Converter and PS-Simulink Converter blocks for the input and output ports of the
HDL Subsystemblock. Using a meaningful name makes it easier to identify what the input and output ports in the HDL implementation model correspond to.
In the Block Parameters dialog box of the Simulink-PS Converter block, click Input Handling on the Settings tab, set the Provided signals to
Input only, or change the Filtering and derivatives to
Filter input, derivatives calculatedor
Zero derivatives (piecewise constant).
For example, open the buck converter model. The Simscape_system block contains Simscape blocks. Blocks outside this subsystem form the test environment.
Simscape_system subsystem, the model uses Simscape blocks and physical signals. The model has Simulink-PS
Converter and PS-Simulink Converter blocks at the interfaces.
Provide unique names for these blocks such that they match the corresponding port
Multiple Simscape Network Considerations
If your Simscape model contains multiple networks:
Enclose each network inside a subsystem. Add Simulink-PS Converter and PS-Simulink Converter blocks at the subsystem interface.
Use a Solver Configuration (Simscape) block for each network. Use the same sample time across Solver Configuration blocks inside the different networks.
For example, this model contains more Simscape networks than Solver Configuration blocks, the Simscape network is not replaced with the HDL subsystem.
The Simscape HDL Workflow Advisor then replaces each Simscape subsystem with the corresponding
For an example that shows how to generate HDL code for a model that has multiple networks, see Generate HDL Code for Simscape Models with Multiple Networks.
Avoid Using Certain Blocks in Simscape Utilities Library
To generate an implementation model that replaces the Simscape subsystem with the state-space algorithm, in your original Simscape model, do not use these blocks from the Simscape > Utilities Library:
For example, this model contains Connection Label and Simscape Bus blocks inside two different subsystems. The Simscape HDL Workflow Advisor cannot replace these subsystems with the state-space algorithm.