Main Content

Model Architecture and Design

Design models intended for Simulink® PLC Coder™ code generation

When developing Simulink models for generating structured text or ladder logic code, consider:

  • Blocks and libraries for which code generation is supported. For a list of Simulink blocks supported for PLC code generation, see Simulink Block List (PLC Code Generation).

  • Setting up a model for fixed point data type code generation.

  • Setting up a multirate model for code generation.

  • Setting up a MATLAB Function for code generation.

  • Existing limitations when using Simulink PLC Coder to generate either structured text or ladder logic code.

Model Settings

expand all

Generate Functions Instead of Function BlockEnable generation of function definitions in place of function block definitions (Since R2021a)
Emit Data type Worksheet Tags for PCWorxEnable generation of datatypeWorksheet tags
Aggressively Inline Structured Text Function CallsOptimize generated code by inlining function calls
Allow nesting of UDTs if fields are more than allowed thresholdOptimize the generation of user-defined tags (Since R2023a)
Enable unsigned integer and double datatypes in generated codeEnable generation of unsigned integer and double data types (Since R2023a)
Generate Testbench for SubsystemEnable the generation of testbench code for the subsystem
Include Testbench Diagnostic CodeEnable generation of diagnostic code to identify testbench failures
Maximum number of fields allowed in a UDTModify the maximum number of elements in a user-defined tag (Since R2023a)
Signal Builder Block Time Range to Generate Multi TestbenchEnable generation of multiple variable-size testbenches (Since R2021a)
Code Output DirectoryPath to the output directory where the generated code is saved
Allow Functions with Zero InputsEnable code generation of Function with no inputs (Since R2020a)
Show Full Target ListShow the full list of supported target IDEs
Suppress Auto-Generated Data TypesEnable the suppression of auto generated data types for arrays
Target IDE PathProvide full path to target IDE installation directory
Target IDESpecify target IDE for the generated code
Include CommentsInclude comments in generated code
Simulink Block / Stateflow Object CommentsInclude Simulink block or Stateflow object comments
Include Block DescriptionInclude block description in generated code
Show Eliminated BlocksInclude eliminated block comments
Remove Code from Floating-Point to Integer Conversions That Wraps Out-Of-Range ValuesEnable code removal from floating-point to integer conversions
Default Parameter BehaviorRepresent numeric block parameters in generated code
Fold temporary variable using function block instance output variableOptimize output variables by using expression folding (Since R2022b)
Generate Reusable CodeEnable optimized reusable code generation for reusable subsystems
Inline Named ConstantsImprove code readability by inlining named constants in generated code
Remove unused ssmethod FB call argumentsGenerate compact code by removing unused function block ssmethod calls (Since R2023a)
Reuse MATLAB Function Block VariablesReuse MATLAB Function Block variables in generated code
Loop Unrolling ThresholdSpecify minimum array size width for generating for loops
Signal Storage ReuseOptimize memory by reusing memory storage locations
Externally Defined IdentifiersSpecify the names of identifiers to be suppressed in the generated code
Use Subsystem Instance Name as Function Block Instance NameUse model subsystem instance name as function block instance name
Generate enum Cast FunctionGenerate typecast function to convert enumeration type (Since R2020a)
Override Target Default enum Name BehaviorOverride default enum variable behavior to use enum names instead of enum values
Inline Enum Cast FunctionInline generate enum cast function (Since R2021a)
Override Target Default Maximum Identifier LengthEnable the overriding of the maximum number of characters in identifiers
Preserve Alias Type Names for Data TypesPreserve Simulink.AliasType names in generated code
Maximum Identifier LengthSpecify maximum number of characters in identifiers
Reserved NamesAvoid name conflicts with custom code
Use the Same Reserved Names as Simulation TargetSpecify whether to use reserved names from the Simulation Target Pane
Absolute-Time Temporal LogicSpecify if the generated code uses a target timer or target independent counter (Since R2020b)
Generate Logging CodeCollect target run-time data for generated code
Remove Initialization Statements for Externally Defined State VariablesPrevent initialization of externally defined variables (Since R2020b)
Keep Top-Level ssmethod Name the Same as the Non-Top Level NameGenerate code for individual model subsystems and integrate the generated code externally (Since R2020a)
Remove Top-level Subsystem Ssmethod TypeRemove the ssmethod type from the top-level subsystem
Use output argument syntax in function and function block callsEnable the generation of => syntax in generated code (Since R2023a)
Generate Model Web ViewGenerate model web view
Generate Traceability ReportGenerate model-to-code and code-to-model traceability report
Open Report AutomaticallyDisplay code generation reports automatically

Topics

Structured Text Code Generation Guidelines and Limitations

Code Reuse

Ladder Logic Code Generation Guidelines and Limitations

Motion Instruction Simulation and Code Generation

Featured Examples