Simulink PLC Coder

Key Features

  • Automatic generation of IEC 61131-3 Structured Text
  • Simulink support, including reusable subsystems, PID controller blocks, and lookup tables
  • Stateflow support, including graphical functions, truth tables, and state machines
  • Embedded MATLAB support, including if-else statements, loop constructs, and math operations
  • Support for multiple data types, including Boolean, integer, enumerated, and floating-point, as well as vectors, matrices, buses, and tunable parameters
  • IDE support, including 3S-Smart Software Solutions CoDeSys, Rockwell Automation® RSlogix™ 5000, Siemens® SIMATIC® STEP® 7, Omron Sysmac Studio, and PLCopen XML
  • Test-bench creation

Simulink PLC Coder generates test benches that help you verify the Structured Text using PLC and PAC IDEs and simulation tools.

Simulink PLC Coder generates structured text from your model that an IDE can deploy to your industrial control system.
From model to Structured Text to application. Simulink PLC Coder generates Structured Text from your model that an IDE can deploy to your industrial control system.

Working with Simulink PLC Coder

In Simulink, you can generate Structured Text using Simulink PLC Coder by right-clicking on a Subsystem block and selecting the PLC Coder > Generate Code for Subsystem option in the resulting context menu. In MATLAB, you can invoke the plcgeneratecode command, which lets you create scripts to generate Structured Text using an automated, repeatable build process.

With support for more than 130 Simulink blocks, all Stateflow constructs, and many Embedded MATLAB functions, Simulink PLC Coder can fully implement your control system models comprising feedback loops, mode and state logic, and math-intensive algorithms. You can use Simulink PLC Coder to convert discrete-time plant models into Structured Text for hardware-in-the-loop (HIL) testing. Alternatively, you can use Simulink Coder to generate C/C++ code for HIL testing with discrete-time or continuous-time models.

Generating structured text with Simulink PLC Coder.
Generating Structured Text in Simulink with Simulink PLC Coder. Right-click on a Subsystem block and select the PLC Coder > Generate Code for Subsystem option in the resulting context menu.

Code Optimization and IDE Integration

Simulink PLC Coder provides optimizations that reduce the memory size and increase the execution speed of the generated Structured Text. These optimizations include:

  • Dead-code elimination
  • Expression folding
  • For-loop fusion
  • Inline parameters
  • Signal storage reuse  
  • Subsystem reuse

Your optimization needs can change with your project’s development phase. For example, during rapid prototyping, you might place parameters in global memory for tuning or calibration; during a subsequent production build, you might generate parameters with their literal numeric values using the Inline parameters option to produce more optimized code.

Simulink PLC Coder can output Structured Text in a variety of file formats used by third-party IDEs. File formats supported by Simulink PLC Coder include:  

  • 3S-Smart Software Solutions CoDeSys
  • B&R Automation Studio™
  • Beckhoff® TwinCAT®
  • Omron Sysmac Studio
  • KW-Software MULTIPROG®
  • Phoenix Contact® PC WORX™
  • Rockwell Automation® RSLogix™ 5000
  • Siemens® SIMATIC® STEP® 7 IDE
  • IDEs that use generic ASCII files
  • PLCopen XML

To generate Structured Text, you select from the list of supported IDEs in the Simulink PLC Coder configuration parameters dialog box. The Structured Text can then be integrated and compiled using the selected IDE.

Example of optimized structured text.
Example of optimized Structured Text. Simulink PLC Coder generates optimized, well-integrated code for Simulink, Stateflow, and Embedded MATLAB functions.

Code Test and Verification

Simulink PLC Coder inserts comments and user-specified block descriptions in the Structured Text so that you can trace text back to the model. Built-in identifier naming control lets you create unique identifiers that preserve object names and signal names in the model. These capabilities help you conduct more efficient code reviews and document how the model was implemented.

Simulink PLC Coder can simulate the model prior to Structured Text generation and package the results into a test harness that is generated with the algorithm code. The test harness serves to verify that model simulation behavior and Structured Text execution results match within an acceptable tolerance. You can then execute the test and analyze the results using your IDE or PLC device.

Example of well-commented structured text.
Example of well-commented Structured Text. Simulink PLC Coder can be configured to include high levels of commenting that enhance readability and traceability.

Try Simulink PLC Coder

Get trial software

Control System Design Using Simulink and RSLogix 5000

View webinar