Main Content

PLC Code Generation Basics

Generate structured text

The basic steps for code generation are:

  • Create a model or open an existing model.

  • Configure the model for code generation by selecting the solver.

  • Configure PLC Coder code generation options.

The PLC Coder configuration parameters provide several options for the code generation.

Apps

Simulink PLC CoderGenerate structured text and ladder diagram code from Simulink models, Stateflow charts, and MATLAB functions

Functions

plccoderdemosProduct examples
plccoderprefManage user preferences
plcgeneratecodeGenerate structured text or ladder diagram (L5X) for the atomic subsystem
plcopenconfigsetOpen Configuration Parameters dialog box for subsystem

Topics

Getting Started

Generate and Examine Structured Text Code

Get started with structured text code generation from a simple Simulink® model.

Integrate Generated Code with Custom Code

Call the generated function block with different values of the ssMethodType argument for subsystem initialization and computation steps.

Specify Custom Names for Generated Files

Override the default naming convention, that uses the model name for the generated Structured Text code file.

Generated Code Structure for Simple Simulink Subsystems

Map model objects in your Simulink subsystem to constructs in generated structured text code.

Create Custom Target IDE for Code Generation

Generate code for your custom target IDE by leveraging built-in plugin options.

Code Generation Files and Folders

Files Generated by Simulink PLC Coder

Find the location of files for manually importing the generated structured text code to your IDE.

Advanced Code Generation Topics

Generate Structured Text Code For Simulink Data Dictionary Defined Model Parameters

Configure model to generate structured text code for Simulink.Parameter objects within the model Simulink data dictionary (SLDD).

Structured Text Code Generation for Enum To Integer Conversion

Autogenerate structured text code for enum to integer conversion model.

PLC_RemoveSSStep for Distributed Code Generation

Generate structured text code for different components of your model.

Structured Text Code Generation for Subsystem Reference Blocks

This example shows how to autogenerate structured text code for subsystem reference blocks.

Global Tunable Parameter Initialization for PC WORX

Learn how global tunable parameters appear in code generated for the PC WORX™ IDE.

Variable-Size Signal Code Generation

Generate PLC structured text code for variable-size data.

Code Generation Control

Propagate Block Descriptions to Code Comments

View block descriptions from your model as comments in generated Structured Text code.

Code Generation for Simulink Models

Generated Code Structure for Reusable Subsystems

Generate structured text code from a reusable subsystem and identify the code reuse.

Generated Code Structure for Triggered Subsystems

Generate structured text code from a triggered subsystem and identify the trigger event-based execution in the generated code.

Generated Code Structure for Multirate Models

Generate structured text code from a multirate model and identify the multiple execution rates in the generated code.

Generated Code Structure for Subsystem Mask Parameters

Generate structured text code from a masked subsystem and identify the mask parameters in the generated code.

Code Generation for Stateflow charts

Generated Code Structure for Stateflow Charts

Generate structured text code from a Stateflow® Chart and identify event-based transitions or absolute time temporal logic in the generated code.

Generate Structured Text Code That Has Logging Instrumentation

Workflow for generating structured text code with logging instrumentation.

Code Generation for MATLAB Function Block

Generated Code Structure for MATLAB Function Block

Generate structured text code from a MATLAB Function block and identify the MATLAB® function content in the generated code.

Featured Examples