CIM Practica 5 Documento Simulink PLC Coder
CIM Practica 5 Documento Simulink PLC Coder
CIM Practica 5 Documento Simulink PLC Coder
User's Guide
R2017a
How to Contact MathWorks
Phone: 508-647-7000
Getting Started
1
Simulink PLC Coder Product Description . . . . . . . . . . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
v
Import Structured Text Code Automatically . . . . . . . . . . . . 1-27
PLC IDEs That Qualify for Importing Code Automatically . 1-27
Generate and Automatically Import Structured Text Code . 1-27
Troubleshoot Automatic Import Issues . . . . . . . . . . . . . . . . 1-28
vi Contents
Generating Ladder Diagrams
3
Ladder Diagram Generation for PLC Controllers . . . . . . . . . 3-2
Ladder Diagram Generation Workflow . . . . . . . . . . . . . . . . . 3-4
vii
Code Generation Reports
5
Information in Code Generation Reports . . . . . . . . . . . . . . . . 5-2
viii Contents
Controlling Generated Code Partitions
7
Generate Global Variables from Signals in Model . . . . . . . . . 7-2
IDE-Specific Considerations
9
Integrate Generated Code with Siemens IDE Project . . . . . . 9-2
Integrate Generated Code with Siemens SIMATIC STEP 7
Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2
Integrate Generated Code with Siemens TIA Portal Projects . 9-2
ix
Enumerated Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-7
Limitations
11
Coder Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
Current Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
rand Function Support Limitations . . . . . . . . . . . . . . . . . . . 11-3
Workspace Parameter Data Type Limitations . . . . . . . . . . . 11-3
Traceability Report Limitations . . . . . . . . . . . . . . . . . . . . . 11-3
Fixed-Point Data Type Limitations . . . . . . . . . . . . . . . . . . . 11-4
Multirate Model Limitations . . . . . . . . . . . . . . . . . . . . . . . . 11-6
Permanent Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6
x Contents
Functions — Alphabetical List
12
xi
PLC Coder: Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-36
Report Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-37
Generate Traceability Report . . . . . . . . . . . . . . . . . . . . . . 13-37
Generate Model Web View . . . . . . . . . . . . . . . . . . . . . . . . 13-38
xii Contents
1
Getting Started
Simulink PLC Coder generates test benches that help you verify the Structured Text and
ladder diagrams using PLC and PAC IDEs and simulation tools. It also provides code
generation reports with static code metrics and bidirectional traceability between model
and code. Support for industry standards is available through IEC Certification Kit (for
IEC 61508 and IEC 61511).
Key Features
• Automatic generation of IEC 61131-3 Structured Text and ladder diagrams
• IDE support, including 3S-Smart Software Solutions CODESYS, Rockwell
Automation Studio 5000, Siemens TIA Portal, OMRON Sysmac Studio, and PLCopen
XML
• Simulink support, including reusable subsystems, PID controller blocks, and lookup
tables
• Stateflow support, including state machines, graphical functions, and truth tables
• 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
• Test bench creation
1-2
PLC Code Generation in the Development Process
Typically, you use a Simulink model to simulate a design for realization in a PLC.
Once satisfied that the model meets design requirements, run the Simulink PLC Coder
compatibility checker utility. This utility verifies compliance of model semantics and
blocks for PLC target IDE code generation compatibility. Next, invoke the Simulink PLC
Coder tool, using either the command line or the graphical user interface. The coder
generates Structured Text code that implements the design embodied in the model.
Usually, you also generate a corresponding test bench. You can use the test bench
with PLC emulator tools to drive the generated Structured Text code and evaluate its
behavior.
The test bench feature increases confidence in the generated code and saves time spent
on test bench implementation. The design and test process are fully iterative. At any
point, you can return to the original model, modify it, and regenerate code.
At completion of the design and test phase of the project, you can easily export the
generated Structure Text code to your PLC development environment. You can then
deploy the code.
Using Simulink PLC Coder, you can also generate Ladder Diagram code for your
applications from a Stateflow chart. The benefits are:
• You can design your application by using states and transitions in a Stateflow chart.
Once you complete the design, you can generate Ladder Diagram code in XML or
another format. You then import the generated code to an IDE such as CODESYS 3.5
or RSLogix™ AOI 5000 and view the ladder diagram.
• When you test your Stateflow chart by using a set of inputs, you can reuse these
inputs to create a test bench for the Ladder Diagram code. You import the test bench
to your PLC IDE and compare the results of simulation with the results of running
the ladder diagram. If the results match, the original Stateflow chart is equivalent to
the generated Ladder Diagram code.
1-3
1 Getting Started
Expected Users
The Simulink PLC Coder product is a tool for control and algorithm design and test
engineers in the following applications:
• PLC manufacturing
• Machine manufacturing
• Systems integration
If you want to download generated code to a PLC IDE, you should also be familiar
with your chosen PLC IDE platform. For a list of these platforms, see “Supported IDE
Platforms” on page 1-6.
Glossary
Term Definition
PAC Programmable automation controller.
PLC Programmable logic controller.
IEC 61131-3 IEC standard that defines the Structured Text language for which the
Simulink PLC Coder software generates code.
PLCopen Vendor- and product-independent organization that works with the
IEC 61131-3 standard. The Simulink PLC Coder product can generate
Structured Text using the PLCopen XML standard format. See http://
www.plcopen.org/pages/tc6_xml/xml_intro/index.htm for details.
Structured Text High-level textual language defined by IEC 61131-3 standard for the
programming of PLCs.
function block Structured Text language programming concept that allows the
encapsulation and reuse of algorithmic functionality.
1-4
PLC Code Generation in the Development Process
System Requirements
For a list of related products, see System Requirements at the MathWorks® website.
1-5
1 Getting Started
• 3S-Smart Software Solutions CODESYS Version 2.3 or 3.3 or 3.5 (SP4 or later)
• B&R Automation Studio® 3.0 or 4.0
• Beckhoff® TwinCAT® 2.11 or 3
• KW-Software MULTIPROG® 5.0 or 5.5
The Simulink PLC Coder software supports only the English version of KW-Software
MULTIPROG target IDE.
• OMRON Sysmac Studio Version 1.04, 1.05, 1.09 or 1.12
• Phoenix Contact® PC WORX™ 6.0
The Simulink PLC Coder software supports only the English version of Phoenix
Contact PC WORX target IDE.
• Rexroth IndraWorks version 13V12 IDE
• Rockwell Automation RSLogix 5000 Series Version 17, 18, 19 or 20 and Rockwell
Studio 5000 Logix Designer Version 21 or 24
Simulink PLC Coder can generate code for Add-On instructions (AOIs) and routine
code. The software supports automatic import and verification of generated code only
for the RSLogix IDEs and not the Studio 5000 IDE.
• Siemens SIMATIC® STEP® 7 Version 5.3, 5.4 or 5.5
The Simulink PLC Coder software assumes that English systems use English S7. It
assumes that German systems use German S7.
• Siemens TIA Portal V13
• Generic
• PLCopen XML
For a list of supported IDEs and platforms, see Supported IDEs at the MathWorks
website.
1-6
Supported IDE Platforms
1-7
1 Getting Started
1 Define and design a Simulink model from which you want to generate code.
2 Identify the model components for which you want to generate code for importing to
a PLC.
3 Place the components in a Subsystem block.
4 Identify your target PLC IDE.
5 Select a solver.
6 Configure the Subsystem block to be atomic.
7 Check that the model is compatible with the Simulink PLC Coder software.
8 Simulate your model.
9 Configure model parameters to generate code for your PLC IDE.
10 Examine the generated code.
11 Import code to your PLC IDE.
1-8
Prepare Model for Structured Text Generation
In this section...
“Tasking Mode” on page 1-9
“Solvers” on page 1-9
“Configuring Simulink Models for Structured Text Code Generation” on page 1-9
“Checking System Compatibility for Structured Text Code Generation” on page 1-14
Tasking Mode
This step is only required if your Simulink model contains multi-rate signals. If your
Simulink model does not contain multi-rate signals, you may proceed to solver selection.
Simulink PLC Coder only generates code for single-tasking subsystems. For multi-
rate subsystems, you must first explicitly set the tasking mode to single-tasking before
selecting a solver. In the model configuration, on the Solver pane, clear the checkbox for
Treat each discrete rate as a separate task.
Solvers
Choose a solver for your Simulink PLC Coder model.
1-9
1 Getting Started
2 Configure the model to use the fixed-step discrete solver. Select Simulation >
Model Configuration Parameters and in the Solver pane, set Type to Fixed-
step and Solver to discrete (no continuous states).
If your model uses a continuous solver, has a subsystem, configure a fixed sample
time for the subsystem for which you generate code.
3 Save this model as plcdemo_simple_subsystem1.
4 Create a subsystem containing the components for which you want to generate
Structured Text code.
1-10
Prepare Model for Structured Text Generation
Optionally, rename In1 and Out1 to U and Y respectively. This operation results in a
subsystem like the following figure:
1-11
1 Getting Started
1-12
Prepare Model for Structured Text Generation
8 Click OK.
9 Simulate your model.
10 Save your model. In later procedures, you can use either this model, or the
plcdemo_simple_subsystem model that comes with your software.
1-13
1 Getting Started
• Set up your subsystem to generate Structured Text code. See “Checking System
Compatibility for Structured Text Code Generation” on page 1-14.
• Generate Structured Text code for your IDE. See “Generate and Examine Structured
Text Code” on page 1-17.
1 In your model, navigate to the subsystem for which you want to generate code.
2 Right-click that Subsystem block and select PLC Code > Check Subsystem
Compatibility.
The coder checks whether your model satisfies the Simulink PLC Coder criteria.
When the checking is complete, a View diagnostics hyperlink appears at the
bottom of the model window. Click this hyperlink to open the Diagnostic Viewer
window.
1-14
Prepare Model for Structured Text Generation
If the subsystem is not atomic, right-click the Subsystem block and select PLC
Code, which prompts Enable “Treat as atomic unit” to generate code.
This command opens the block parameter dialog box. Select Treat as atomic unit.
1-15
1 Getting Started
You are now ready to generate Structured Text code for your IDE. See “Generate and
Examine Structured Text Code” on page 1-17.
1-16
Generate and Examine Structured Text Code
In this section...
“Generate Structured Text from the Model Window” on page 1-17
“Generate Structured Text with the MATLAB Interface” on page 1-19
“View Generated Code” on page 1-20
1-17
1 Getting Started
3 On the PLC Code Generation pane, select an option from the Target IDE list, for
example, 3S CoDeSys 2.3.
The default Target IDE list displays the full set of supported IDEs. To see a reduced
subset of the target IDEs supported by Simulink PLC Coder, disable the option
Show full target list. To customize this list, use the plccoderpref function.
4 Click Apply.
5 Click Generate code.
This button:
1-18
Generate and Examine Structured Text Code
• Generates Structured Text code (same as the PLC Code > Generate Code for
Subsystem option)
• Stores generated code in model_name.exp (for example,
plcdemo_simple_subsystem.exp)
This window has links that you can click to open the associated files. For more
information, see “Files Generated with Simulink PLC Coder” on page 1-23.
1-19
1 Getting Started
plcdemo_simple_subsystem
2 Open the Configuration Parameters dialog box using the plcopenconfigset
function:
plcopenconfigset('plcdemo_simple_subsystem/SimpleSubsystem')
3 Select a target IDE.
4 Configure the subsystem as described in “Prepare Model for Structured Text
Generation” on page 1-9.
5 Generate code for the subsystem:
generatedfiles = plcgeneratecode('plcdemo_simple_subsystem/SimpleSubsystem')
• Matrix data types: The coder converts matrix data types to single-dimensional vectors
(column-major) in the generated Structured Text.
• Generated code header: If your model has author names, creation dates, and model
descriptions, the generated code contains these items in the header comments. The
header also lists fundamental sample times for the model and the subsystem block for
which you generate code.
• Code comments: You can choose to propagate block descriptions to comments in
generated code. See “Propagate Block Descriptions to Code Comments” on page
1-22.
The figure illustrates generated code for the CoDeSys Version 2.3 PLC IDE. Generated
code for other platforms, such as Rockwell Automation RSLogix 5000, is in XML or other
format and looks different.
1-20
Generate and Examine Structured Text Code
If you are confident that the generated Structured Text is good, optionally change
your workflow to automatically generate and import code to the target IDE. For more
information, see “Import Structured Text Code Automatically” on page 1-27.
1-21
1 Getting Started
For specific IDEs, you can propagate the block descriptions into specific XML tags in the
generated code. The IDEs use the tags to create a readable description of the function
blocks in the IDE.
• For Rockwell Automation RSLogix 5000 AOI/routine target IDEs, the coder
propagates block descriptions from the model into the L5X AdditionalHelpText
XML tag. The IDE can then import the tag as part of AOI and routine definition in
the generated code.
• For CoDeSys 3.5 IDE, the coder propagates block descriptions from the model into the
documentation XML tag. When you import the generated code into the CoDeSys 3.5
IDE, the IDE parses the content of this tag and provides readable descriptions of the
function blocks in your code.
a Right-click the block for which you want to write a description and select
Properties.
b On the General tab, enter a block description.
2 Before code generation, specify that block descriptions must propagate to code
comments.
a Right-click the subsystem for which you are generating code and select PLC
Code > Options.
b Select the option Include block description on page 13-16.
1-22
Files Generated with Simulink PLC Coder
1-23
1 Getting Started
1-24
Files Generated with Simulink PLC Coder
1-25
1 Getting Started
To specify a different name for the generated files, set the Function name options
parameter in the Subsystem block:
1 Right-click the Subsystem block for which you want to generate code and select
Subsystem Parameters.
2 In the Main tab, select the Treat as atomic unit check box.
3 Click the Code Generation tab.
4 From the Function Packaging parameter list, select either Nonreusable
function or Reusable Function.
These options enable the Function name options and File name options
parameters.
5 Select the option that you want to use for generating the file name.
1-26
Import Structured Text Code Automatically
For the Rockwell Automation RSLogix routine format, you must generate testbench
code for automatic import and verification.
• Siemens SIMATIC STEP 7 Version 5.4 only for the following versions:
Working with the default CoDeSys Version 2.3 IDE should require additional changes
for only the KW-Software MULTIPROG 5.0 and Phoenix Contact PC WORX 6.0 IDE.
For information about automatically importing Structured Text code to these IDEs,
see “Import and Verify Structured Text to KW-Software MULTIPROG 5.0 and Phoenix
Contact PC WORX 6.0 IDEs” on page 4-5.
1-27
1 Getting Started
Note: While the automatic import process is in progress, do not touch your mouse or
keyboard. Doing so might disrupt the process. When the process completes, you can
resume normal operations.
You must have already installed your target PLC IDE in a default location, and it must
use the CoDeSys V2.3 IDE. If you installed the target PLC IDE in a nondefault location,
open the Configuration Parameters dialog box. In the PLC Coder node, set the Target
IDE Path parameter to the installation folder of your PLC IDE. See “Target IDE Path”
on page 13-10.
The software:
If you want to generate, import, and run the Structured Text code, see “Import and
Verify Structured Text Code” on page 4-4.
The Simulink PLC Coder software supports only the following versions of target IDEs for
automatic import and verification:
1-28
Import Structured Text Code Automatically
For the Rockwell Automation RSLogix routine format, you must generate testbench
code for automatic import and verification.
• Siemens SIMATIC STEP 7 Version 5.4 (English and German)
The following target IDEs currently do not support automatic import. For these target
IDEs, the automatic import menu items (Generate and Import Code for Subsystem
and Generate, Import, and Verify Code for Subsystem) are disabled.
When the Simulink PLC Coder software fails to finish automatically importing for the
target IDE, it reports an issue in a message dialog box. To remedy the issue, try the
following actions:
• Check that the coder supports the target IDE version and language setting
combination.
• Check that you have specified the target IDE path in the subsystem Configuration
Parameters dialog box.
• Close currently open projects in the target IDE, close the target IDE completely, and
try again.
• Some target IDEs can have issues supporting the large data sets the coder test bench
generates. In these cases, try to shorten the simulation cycles to reduce the data set
size, then try the automatic import again.
1-29
1 Getting Started
• Other applications can interfere with automatic importing to a target IDE. Try to
close other unrelated applications on the system and try the automatic import again.
1-30
Simulation and Code Generation of Motion Instructions
The Simulink PLC Coder software supports a workflow for the behavioral simulation and
code generation of motion instructions for the Rockwell Automation RSLogix 5000 IDE.
Subsystem Description
Controller Contains an example Stateflow chart with motion
instructions. The controller subsystem sends input
to the Command Profile subsystem (part of the
template).
1-31
1 Getting Started
1-32
Simulation and Code Generation of Motion Instructions
6 Generate code for the example model. To view the code in HTML format on page
5-4, in the coder configuration parameters, select the PLC Code Generation >
Report > Generate traceability report check box and click Apply.
Navigate to the PLC Code Generation node and click Generate code.
1-33
1 Getting Started
MAM
• MAM
• MAFR
• MSO
To use other Rockwell Automation RSLogix motion instructions in the model, you must
define your own stub functions to correspond to the RSLogix motion instructions in the
Motion Stub Functions chart.
1-34
Simulation and Code Generation of Motion Instructions
1-35
2
The example in this topic shows generated code for the CoDeSys Version 2.3 IDE.
Generated code for other IDE platforms looks different.
edit plcdemo_simple_subsystem.exp
The following figure illustrates the mapping of the generated code to Structured Text
components for a simple Simulink subsystem. The Simulink subsystem corresponds
to the Structured Text function block, Subsystem.
Note: The coder maps alias data types to the base data type in the generated code.
2-2
Generated Code Structure for Simple Simulink Subsystems
Subsystem
inputs and
outputs
Subsystem
State (DWork)
variables
Initialize and
step methods
Inlined
parameters
2 Inspect this code as you ordinarily do for PLC code. Check the generated code.
Note: The Simulink model for plcdemo_simple_subsystem does not contain signal
names at the input or output of the SimpleSubsystem block. So the generated code has
the port names U and Y as the input and output variable names of the FUNCTION_BLOCK.
However, even if your model does contain signal names, coder only uses port names in
the generated code.
2-3
2 Mapping Simulink Semantics to Structured Text
The example in this topic shows generated code for the CoDeSys Version 2.3 IDE.
Generated code for other IDE platforms looks different.
The Simulink PLC Coder software generates Structured Text code and places it in
current_folder/plcsrc/plcdemo_reusable_subsystem.exp.
3 If you do not have the plcdemo_reusable_subsystem.exp file open, open it in the
MATLAB editor.
The following figure illustrates the mapping of the generated code to Structured
Text components for a reusable Simulink subsystem. This graphic contains a copy
of the hierarchical subsystem, ReusableSubsystem. This subsystem contains two
identical subsystems, S1 and S2. This configuration enables code reuse between the
two instances (look for the ReusableSubsystem string in the code).
2-4
Generated Code Structure for Reusable Subsystems
4 Examine the generated Structured Text code. The code defines FUNCTION_BLOCK
S1 once.
Look for two instance variables that correspond to the two instances declared inside
the parent FUNCTION_BLOCK ReusableSubsystem (i0_S1: S1 and i1_S1: S1).
The code invokes these two instances separately by passing in different inputs. The
code invokes the outputs per the Simulink execution semantics.
5 For IEC 61131-3 compatible targets, the non-step and the output ssMethodType
do not use the output variables of the FUNCTION_BLOCK. Therefore, the generated
2-5
2 Mapping Simulink Semantics to Structured Text
Structured Text code for SS_INITIALIZE does not contain assignment statements
for the outputs Y1 and Y2.
2-6
Generated Code Structure for Triggered Subsystems
The example in this topic shows generated code for the CoDeSys Version 2.3 PLC IDE.
Generated code for other IDE platforms looks different.
The Simulink PLC Coder software generates Structured Text code and places it in
current_folder/plcsrc/plcdemo_cruise_control.exp.
3 If you do not have the plcdemo_cruise_control.exp file open, open it in the
MATLAB editor.
The following figure illustrates the mapping of the generated code to Structured
Text components for a triggered Simulink subsystem. The first part of the figure
shows the Controller subsystem and the triggered Stateflow chart that it contains.
The second part of the figure shows excerpts of the generated code. Notice the zero-
crossing functions that implement the triggered subsystem semantics.
2-7
2 Mapping Simulink Semantics to Structured Text
Generated code
2-8
Generated Code Structure for Stateflow Charts
2-9
2 Mapping Simulink Semantics to Structured Text
You can map the states and transitions in the chart to the generated code. For instance,
the transition from the state Aborting to Aborted appears in the generated code as:
2-10
Generated Code Structure for Stateflow Charts
ControlModule_IN_Aborting:
rtb_out := sABORTING;
(* During 'Aborting': '<S1>:11' *)
(* Graphical Function 'is_active': '<S1>:73' *)
(* Transition: '<S1>:75' *)
IF NOT drive_state.Active THEN
(* Transition: '<S1>:31' *)
is_c2_ControlModule := ControlModule_IN_Aborted;
(* Entry 'Aborted': '<S1>:12' *)
rtb_out := sABORTED;
(* Graphical Function 'stop_drive': '<S1>:88' *)
(* Transition: '<S1>:90' *)
driveOut.Start := FALSE;
driveOut.Stop := TRUE;
driveOut.Reset := FALSE;
END_IF;
2-11
2 Mapping Simulink Semantics to Structured Text
You can map states and transitions in the chart to the generated code. For instance, the
transition from state B to C appears as:
Temporal_IN_B:
(* During 'B': '<S1>:2' *)
temporalCounter_i1(timerAction := 2, maxTime := 4000);
IF temporalCounter_i1.done THEN
(* Transition: '<S1>:8' *)
is_c2_Temporal := Temporal_IN_C;
temporalCounter_i1(timerAction := 1, maxTime := 0);
ELSE
(* Outport: '<Root>/pulse' *)
pulse := 2.0;
END_IF;
2-12
Generated Code Structure for Stateflow Charts
FUNCTION_BLOCK PLC_CODER_TIMER
VAR_INPUT
timerAction: INT;
maxTime: DINT;
END_VAR
VAR_OUTPUT
done: BOOL;
END_VAR
VAR
plcTimer: TON;
plcTimerExpired: BOOL;
END_VAR
CASE timerAction OF
1:
(* RESET *)
plcTimer(IN:=FALSE, PT:=T#0ms);
plcTimerExpired := FALSE;
done := FALSE;
2:
(* AFTER *)
IF (NOT(plcTimerExpired)) THEN
plcTimer(IN:=TRUE, PT:=DINT_TO_TIME(maxTime));
END_IF;
plcTimerExpired := plcTimer.Q;
done := plcTimerExpired;
3:
(* BEFORE *)
IF (NOT(plcTimerExpired)) THEN
plcTimer(IN:=TRUE, PT:=DINT_TO_TIME(maxTime));
END_IF;
plcTimerExpired := plcTimer.Q;
done := NOT(plcTimerExpired);
END_CASE;
END_FUNCTION_BLOCK
2-13
2 Mapping Simulink Semantics to Structured Text
The example in this topic shows generated code for the CoDeSys Version 2.3 IDE.
Generated code for other IDE platforms looks different.
The Simulink PLC Coder software generates Structured Text code and places it in
current_folder/plcsrc/plcdemo_eml_tankcontrol.exp.
3 If you do not have the plcdemo_eml_tankcontrol.exp file open, open it in the
MATLAB editor.
The following figure illustrates the mapping of the generated code to Structured
Text components for a Simulink Subsystem block that contains a MATLAB Function
block. The coder tries to perform inline optimization on the generated code for
MATLAB local functions. If the coder determines that it is more efficient to leave the
local function as is, it places the generated code in a Structured Text construct called
FUNCTION.
4 Examine the generated Structured Text code.
2-14
Generated Code Structure for MATLAB Function Block
MATLAB code
Generated code
for MATLAB
subfunctions
2-15
2 Mapping Simulink Semantics to Structured Text
The example in this topic shows generated code for the CoDeSys Version 2.3 IDE.
Generated code for other IDE platforms looks different.
1 Open the plcdemo_multirate model. This model has two sample rates.
2 Right-click the SimpleSubsystem block and select PLC Code > Generate Code
for Subsystem.
The Simulink PLC Coder software generates Structured Text code and places it in
current_folder/plcsrc/plcdemo_multirate.exp.
3 If you do not have the plcdemo_multirate.exp file open, open it in the MATLAB
editor and examine the Structured Text code.
In this example, there are two rates, and the fast rate is twice as fast as the slow
rate, so the time step counter counts to 1, then resets:
IF plc_ts_counter1 >= 1 THEN
plc_ts_counter1 := 0;
ELSE
plc_ts_counter1 := plc_ts_counter1 + 1;
END_IF;
The generated code for blocks running at slower rates executes conditionally based
on the corresponding time step counter values. In this example, the generated
code for Gain1, Unit Delay1, and Sum1 executes every other time step, when
plc_ts_counter1 = 0, because those blocks run at the slow rate. The generated
code for Gain, Unit Delay, Sum, and Sum2 executes every time step because those
blocks run at the fast rate.
SS_STEP:
2-16
Generated Code Structure for Multirate Models
(* Outport: '<Root>/Y1' *)
Y1 := rtb_Gain;
IF plc_ts_counter1 = 0 THEN
(* Outport: '<Root>/Y2' *)
Y2 := rtb_Gain1;
END_IF;
IF plc_ts_counter1 = 0 THEN
END_IF;
In general, for a subsystem with n different sample times, the generated code has n-1
time step counter variables, corresponding to the n-1 slower rates. Code generated
from parts of the model running at the slower rates executes conditionally, based on the
corresponding time step counter values.
2-17
2 Mapping Simulink Semantics to Structured Text
For example, the following subsystem, Subsystem, contains two instances, Filt1 and
Filt2, of the same masked subsystem.
2-18
Generated Code Structure for Subsystem Mask Parameters
The two subsystems, Filt1, and Filt2, have different values assigned to their mask
parameters. In this example, Filt1_Order_Thau is a constant with a value of 5.
2-19
2 Mapping Simulink Semantics to Structured Text
2-20
Generated Code Structure for Subsystem Mask Parameters
Therefore, for the Filt1 subsystem, the Filt1_Order_Thau parameter has a value of 8,
and for the Filt2 subsystem, the Filt1_Order_Thau parameter has a value of 5.
The following generated code shows the Filt1 function block inputs. The
rtp_Filt1_Order_Thau input was generated for the Filt1_Order_Thau mask
parameter.
FUNCTION_BLOCK Filt1
VAR_INPUT
ssMethodType: SINT;
InitV: LREAL;
InitF: BOOL;
Input: LREAL;
rtp_Filt1_Order_Thau: LREAL;
rtp_InitialValue: LREAL;
rtp_Filt1_Order_Enable: BOOL;
END_VAR
The following generated code is from the FUNCTION_BLOCK Subsystem. The function
block assigns a value of 8 to the rtp_Filt1_Order_Thau input for the i0_Filt1
2-21
2 Mapping Simulink Semantics to Structured Text
SS_INITIALIZE:
(* InitializeConditions for Atomic SubSystem: '<S1>/Filt1' *)
2-22
Global Tunable Parameter Initialization for PC WORX
For example, suppose that your model has a global array variable, ParArrayXLUT:
ParArrayXLUT=[0,2,6,10];
In the generated code, the PLC_INIT_PARAMETERS function contains the following code
to initialize ParArrayXLUT:
2-23
3
Using Simulink PLC Coder, you can generate Ladder Diagram code for your applications
from a Stateflow chart (Stateflow). The benefits are:
• You can design your application by using states and transitions in a Stateflow chart.
Once you complete the design, you can generate Ladder Diagram code in XML or
another format. You then import the generated code to an IDE such as CODESYS 3.5
or RSLogix AOI 5000 and view the ladder diagram.
• When you test your Stateflow chart by using a set of inputs, you can reuse these
inputs to create a test bench for the Ladder Diagram code. You import the test bench
to your PLC IDE and compare the results of simulation with the results of running
the ladder diagram. If the results agree, the original Stateflow chart is equivalent to
the generated Ladder Diagram code.
The figure shows a simple Stateflow chart with three states and two transitions. Based
on the transition conditions, the chart transitions from one state to another.
3-2
Ladder Diagram Generation for PLC Controllers
• The chart has just started execution through the default transition.
• The previous active state is also State1 and the
conditions transitionCondition1 and transitionCondition2 are false.
You can import the generated Ladder Diagram code to CODESYS 3.5 and view the
diagram. A portion of the ladder diagram is shown.
3-3
3 Generating Ladder Diagrams
In the preceding ladder diagram, each rung of the ladder ends in a coil. The coil
corresponds to a state of the original chart. The contacts before the coil determine if the
coil receives power. You can compare the ladder diagram visually with the Stateflow
chart. For instance, the coil State1_new receives power in one of these two cases:
• The normally open contact State1 is closed and the normally closed contacts
transitionCondition1 and transitionCondition2 are open.
• The normally open contact stateflow_init is closed. This contact corresponds to
the default transition.
Once the coil State1_new receives power, the contact State1_new further down in the
ladder is then closed and the coil State1 receives power.
The ladder diagram executes from top to bottom and from left to right.
3-4
Ladder Diagram Generation for PLC Controllers
2 Generate Ladder Diagram code from the Stateflow chart. The code is in a format
suitable for import to an IDE.
Generate a test bench along with the code. The test bench is in the Structured Text
language. You can later import the code along with the test bench to your IDE. The
test bench invokes the Ladder Diagram code and compares the output against the
expected outputs from the original Stateflow chart.
See “Generate Ladder Diagram Code from Stateflow Chart” on page 3-10.
3 Import the generated Ladder Diagram code to your CODESYS 3.5 IDE. Validate the
diagram in the IDE by using the generated test bench.
See “Import Ladder Diagram Code to CODESYS 3.5 IDE and Validate Diagram” on
page 3-15.
3-5
3 Generating Ladder Diagrams
For the complete Ladder Diagram code generation workflow, see “Ladder Diagram
Generation Workflow” on page 3-4.
• The inputs and outputs to the chart must be Boolean. They will correspond to the
input and output terminals of your PLC.
• Each state in the chart must correspond to an output. The output is true if the state is
currently active.
To ensure that each state in the chart is mapped to an output, in the Properties
dialog box of each state, select Create output for monitoring. Then, select Self
activity.
• The transition conditions must involve only Boolean operations such as ~, & and |
between the inputs.
3-6
Prepare Chart for Ladder Diagram Generation
Some advanced Stateflow features are not supported because of inherent restrictions
in Ladder Diagram semantics. You can use the function plccheckforladder
to check if the chart has the required properties. You can also use the function
plcprepareforladder to change certain chart properties so that the chart is ready for
Ladder Diagram code generation.
You can start generating Ladder Diagram code from the chart. See the example in
“Generate Ladder Diagram Code from Stateflow Chart” on page 3-10.
3-7
3 Generating Ladder Diagrams
Using the test harness, Simulink PLC Coder can generate test benches for validation of
the Ladder Diagram code.
You can manually create a test harness by using the Signal Builder block or
autogenerate a test harness by using Simulink Design Verifier™. To autogenerate the
test harness:
1 Right-click the chart or a subsystem containing the chart. Select Design Verifier >
Generate Tests for Subsystem.
2 After test creation, select Create harness model.
The harness model is created. The model consists of the original subsystem coupled with
inputs from a Signal Builder block. The block consists of multiple test cases, so that the
states and transitions in your model are covered at least once.
You can also create tests by using other blocks from the Simulink library. However, you
must ensure that the inputs to the chart are Boolean.
3-8
Prepare Chart for Ladder Diagram Generation
You can now generate Ladder Diagram code from the chart and validate the diagram.
• To generate Ladder Diagram code only, use the original Stateflow chart.
• To generate Ladder Diagram code with test bench, use the Stateflow chart coupled
with the Boolean inputs from the test cases. For instance, if you create a harness
model with Simulink Design Verifier, use the harness model for the Ladder Diagram
code and test bench generation instead of the original chart.
See “Generate Ladder Diagram Code from Stateflow Chart” on page 3-10.
3-9
3 Generating Ladder Diagrams
• Generate code from a Stateflow chart that you can view as ladder diagrams in your
IDE.
• Generate test bench for validation of the Ladder Diagram code in your IDE.
For the complete Ladder Diagram code generation workflow, see “Ladder Diagram
Generation Workflow” on page 3-4.
3-10
Generate Ladder Diagram Code from Stateflow Chart
The chart consists of five states: Init, Fault, Red, Yellow, and Green. Based on the
input to the chart, transitions to any of these states can take place. For instance, the
state Red becomes active in the following scenarios:
• Initialization and power up: The previous state is Init and the condition
Power_Up is true.
• Fault rectification: The previous state is Fault and the condition VLDHealthy &
FaultRectified is true.
• Transitions from other colors: The previous state is Green or Yellow, the
conditions that allow transition to Red are true, and the conditions that allow
transition to another color or to the Fault state are false.
• Staying red: The previous state is Red and the conditions that allow transition to
another state are false.
3-11
3 Generating Ladder Diagrams
The figure shows a portion of the Ladder Diagram code generated from the chart when
viewed in the CODESYS 3.5 IDE. The ladder diagram consists of contacts (normally open
and normally closed) and coils (normal, set, and reset).
You can map elements of the original Stateflow chart to these coils and contacts. For
instance, the coil Red_new corresponds to the update of the state Red in the Stateflow
chart. For the coil to receive power, one of the following must be true:
• Initialization and power up: The normally open contacts Init and Power_Up
must be closed.
• Fault rectification: The normally open contacts Fault and T_1_1_trans must be
closed. The contact T_1_1_trans represents the transition condition VLDHealthy &
FaultRectified in the chart.
• Transitions from other colors: The normally open contact Green must be closed
and the following must be true:
• The normally open contact T_2_3_trans must be closed. This contact corresponds
to the chart condition that must be true for transition to the Red state.
• The normally closed contacts T_2_1_trans and T_2_2_trans must stay closed.
These contacts correspond to the chart condition that must be false for transition
to the Red state. If the conditions are true, the contacts open and the coil no longer
receives power.
3-12
Generate Ladder Diagram Code from Stateflow Chart
• Staying red: The normally open contact Red must be closed, and the normally
closed contacts T_4_1_trans and T_4_2_trans must stay closed. These contacts
correspond to the chart conditions that must be false for the Red state to continue to
be active. If the conditions are true, the contacts open and the coil no longer receives
power.
Right-click the chart and select PLC Code > Options. Specify a supported IDE for
the option “Target IDE” on page 13-5. See “IDEs Supported for Ladder Diagram
Code Generation” on page 1-7.
3 Right-click the chart and select PLC Code > Generate Ladder Logic for Chart.
If code generation is successful, in the subfolder plcsrc of the current working folder,
you see the file ModelName.xml. You import this file to your IDE and view the ladder
diagram. For the CODESYS 3.5 IDE, see “Import Ladder Diagram Code to CODESYS 3.5
IDE and Validate Diagram” on page 3-15.
You can also use the function plcgenerateladder to generate Ladder Diagram code
from a Stateflow chart.
1 Right-click the chart and select PLC Code > Options. Select the option “Generate
Testbench for Subsystem” on page 13-13.
2 Right-click the chart and select PLC Code > Generate Ladder Logic for Chart.
The test benches use the inputs to the original Stateflow chart. Therefore, you can create
test harnesses for the original chart and reuse them for validation of the Ladder Diagram
code.
3-13
3 Generating Ladder Diagrams
You can also use the function plcgenerateladder to generate test benches.
After generating the Ladder Diagram code and the test benches, you can import them to
your IDE. For the CODESYS 3.5 IDE, see “Import Ladder Diagram Code to CODESYS
3.5 IDE and Validate Diagram” on page 3-15.
3-14
Import Ladder Diagram Code to CODESYS 3.5 IDE and Validate Diagram
For this example, the CODESYS 3.5 IDE is used. You can also use one of the other
supported IDE. See “IDEs Supported for Ladder Diagram Code Generation” on page 1-7.
For the complete Ladder Diagram code generation workflow, see “Ladder Diagram
Generation Workflow” on page 3-4.
Select Project > Import PLCOpenXML and navigate to the folder containing the
XML file.
A dialog box opens with a full list of the components imported from the XML. If you
generate a test bench for validation, you also see the testbench.
3-15
3 Generating Ladder Diagrams
3 On the POUs pane, you see the project. View the ladder diagram in the project.
You can compare the ladder diagram with the original Stateflow chart.
For instance, if you generate Ladder Diagram code from the model
plcdemo_ladder_three_aspect, in the ladder diagram, you can identify the
transition from the Fault state to the Red state.
3-16
Import Ladder Diagram Code to CODESYS 3.5 IDE and Validate Diagram
a The normally open contacts VLDHealthy and FaultRectified are closed. Coil
T_1_1_trans receives power and is energized.
b The normally open contacts Fault and T_1_1_trans are closed. The coil
Red_new receives power and is energized. Note that other conditions not shown
in figure below also need to be satisfied.
c The normally open contact Red_new is closed. The coil Red receives power and is
energized.
Besides coils and normally open contacts , the ladder diagram also uses:
•
Normally closed contacts : They appear if the ~ operator is used in a
transition condition.
•
Set coils and reset coils : They are used in the ladder diagram for
chart initialization. Reset coils are also used if you enforce additional safeguards
against multiple states from being simultaneously active. See the argument
InsertGuardResets in plcgenerateladder.
3-17
3 Generating Ladder Diagrams
For more information about these symbols, refer to the IEC 61131-3 specifications.
4 Select Online > Simulation. Click the (Build) button and verify that there are
no build errors.
If the option is not active, you might have to change the version number in your
XML. Search for the version number in the XML and depending on the patch that
you have, replace it with the following version number:
1
Click the (Login) button and log in to the emulator device.
2
Click the (Start) button and begin simulation.
3 Double-click a test bench in your project. You see the following variables updating to
reflect the results of validation.
3-18
Restrictions on Stateflow Chart for Ladder Diagram Generation
• The inputs and outputs to the chart must be Boolean. These inputs and outputs
correspond to the input and output terminals of your PLC.
• Each state of the chart must correspond to a chart output.
• The expressions controlling the transition between states must involve only Boolean
operations between the inputs.
In addition, the chart must have the following properties. You can use the function
plccheckforladder to check if the chart has the required properties. You can also use
the function plcprepareforladder to change certain chart properties so that the chart
is ready for Ladder Diagram code generation.
To ensure that each state in the chart is mapped to an output, in the Properties
dialog box of each state, select Create output for monitoring. Then, select Self
activity.
3-19
3 Generating Ladder Diagrams
• The chart must not have data with scope other than input or output.
• The chart must not include:
• Atomic subcharts
• Multiple default transitions
• Simulink functions
• Parallel states
• State hierarchy
• History junctions
• Dangling transitions
• Super transitions crossing subchart boundaries
• Conditional default paths
• Self transitions
Related Examples
• “Prepare Chart for Ladder Diagram Generation” on page 3-6
• “Generate Ladder Diagram Code from Stateflow Chart” on page 3-10
• “Import Ladder Diagram Code to CODESYS 3.5 IDE and Validate Diagram” on
page 3-15
3-20
Restrictions on Stateflow Chart for Ladder Diagram Generation
More About
• “Ladder Diagram Generation for PLC Controllers” on page 3-2
3-21
4
The test bench runs the generated code to verify that the output is functionally and
numerically equivalent to the output from the execution of a Simulink model. The
following table shows how the test bench compares the expected and actual data values.
The relative tolerance comparison for single or double data types uses the following logic:
IF ABS(actual_value - expected_value) > (ERROR_TOLERANCE * expected_value) THEN
testVerify := FALSE;
END_IF;
To verify the generated code using the test bench, import the generated Structured Text
and the test bench data into your target IDE. You can import test bench code:
• Manually.
• Automatically, including running the test bench.
For more information, see “Import and Verify Structured Text Code” on page 4-4.
Depending on the target IDE platform, the Simulink PLC Coder software generates code
into one or more files. See “Files Generated with Simulink PLC Coder” on page 1-23 for
list of the target IDE platforms and the possible generated files.
4-2
Integrate Generated Code with Custom Code
To use ssMethodType with a FUNCTION_BLOCK for your model, in the generated code,
the top-level subsystem function block prototype has one of the following formats:
For non top-level subsystems, in the generated code, the subsystem function block
prototype has one of the following formats:
4-3
4 Generating Test Bench Code
If you want to only import the generated code, see “Generate and Automatically Import
Structured Text Code” on page 1-27.
1 Specify that test bench code must be generated for the subsystem.
If you do not specify that test bench code must be generated, when you automatically
verify the generated code, you see the error Testbench not selected.
2 You can generate the code and testbench, and manually import them to your target
IDE. For information on how to import generated code, see the user manual for your
target IDE.
Alternatively, after code generation, import and verify the generated code
automatically. Right-click the subsystem and select PLC Code > Generate,
Import, and Verify Code for Subsystem. The software:
4-4
Import and Verify Structured Text Code
• IDEs not supported for automatic import and verification, see “Troubleshoot
Automatic Import Issues” on page 1-28.
• Possible reasons for long testbench code generation time, see “Troubleshooting: Long
Test Bench Code Generation Time” on page 4-6.
1 Start the KW-Software MULTIPROG 5.0 or Phoenix Contact PC WORX 6.0 IDE.
2 Select File > Delete Template. Delete any template named Empty, and click OK
when done.
3 Select File > New Project, select Project Wizard, then click OK.
• Logical POUs
• Physical Hardware
5 Verify that the project tree has only top-level nodes for Libraries, Data Types,
Logical POUs, and Physical Hardware. There must not be any subtree nodes.
6 In the IDE, select File > Save As Template.
7 In Template Name, type Empty.
8 Click OK.
9 Close the IDE interface.
Open your model, right-click the Subsystem block, and select one of the following:
4-5
4 Generating Test Bench Code
Related Examples
• “Verify Generated Code with Multiple Test Benches” on page 4-7
4-6
Verify Generated Code with Multiple Test Benches
1 Provide multiple signal groups as inputs by using a Signal Builder block with
multiple signal groups (Simulink).
Instead of manually entering a Signal Builder block and creating multiple signal
groups, you can use Simulink Design Verifier to create a test harness model from
the subsystem. In the test harness model, a Signal Builder block with one or more
signal groups provides input to the subsystem. You can use this Signal Builder block
to provide inputs to your subsystem. However, if your model is complex, Simulink
Design Verifier can create large number of signal groups. See “Troubleshooting: Test
Data Exceeds Target Data Size” on page 4-9.
a Right-click the subsystem and select Design Verifier > Generate Tests for
Subsystem.
b In the Simulink Design Verifier Results Summary window, select Create
harness model.
4-7
4 Generating Test Bench Code
c Open the Inputs block in the test harness model. The Inputs block is a Signal
Builder block that can have one or more signal groups.
In the Signal Builder window, make sure that more than one signal group is
available in the Active Group drop-down list.
d Copy the Signal Builder block from the test harness model and use this block to
provide inputs to your original subsystem.
2 Specify that test benches must be generated for the subsystem.
4-8
Verify Generated Code with Multiple Test Benches
In your target IDE, you can see multiple test benches. Each test bench corresponds
to a signal group.
• Reduce the number of signal groups in the Signal Builder block and regenerate the
test benches.
• Increase the simulation step size for the subsystem.
Related Examples
• “Import and Verify Structured Text Code” on page 4-4
4-9
5
In the Configuration Parameters dialog box, in the Report panel, you see these options.
Note: You must have a Simulink Report Generator™ license to generate traceability
reports.
The coder provides the traceability report to help you navigate more easily between the
generated code and your source model. When you enable code generation report, the
coder creates and displays an HTML code generation report. You can generate reports
from the Configuration Parameters dialog box or the command line. Traceability report
generation is disabled when generating Ladder Diagrams from Stateflow chart. See
“Traceability Report Limitations” on page 11-3. A typical traceability report looks
something like this figure:
5-2
Information in Code Generation Reports
5-3
5 Code Generation Reports
In this section...
“Generate a Traceability Report from Configuration Parameters” on page 5-4
“Keep the Report Current” on page 5-6
“Trace from Code to Model” on page 5-7
“Trace from Model to Code” on page 5-8
“Model Web View in Code Generation Report” on page 5-9
“Generate a Static Code Metrics Report” on page 5-13
“Generate a Traceability Report from the Command Line” on page 5-14
5-4
Create and Use Code Generation Reports
5 Click PLC Code Generation > Generate code to initiate code and report
generation. The coder generates HTML report files as part of the code generation
process.
5-5
5 Code Generation Reports
5-6
Create and Use Code Generation Reports
1 In the generated code HTML report display, look for <S1>/Gain. Code Generation
Report has syntax highlighting for easy readability. PLC-specific keywords are
highlighted in blue, comments in green, and the rest of the code in black.
2 In the HTML report window, click a link to highlight the corresponding source
block. For example, in the HTML report shown in the previous figure, you click the
hyperlink for the Gain block (highlighted) to view that block in the model. Clicking
the hyperlink locates and displays the corresponding block in the model editor
window. You can use the same method to trace other block from the HTML report.
5-7
5 Code Generation Reports
• Subsystem
• Simulink block
• MATLAB Function block
• Truth Table block
• State Transition Table block
• Stateflow chart, or the following elements of a Stateflow chart:
• State
• Transition
• Graphical function
• MATLAB function
• Truth table function
You must have already generated code with a traceability report to trace a model
component to the generated code. If not, see “Generate a Traceability Report from
Configuration Parameters” on page 5-4 or “Generate a Traceability Report from the
Command Line” on page 5-14.
5-8
Create and Use Code Generation Reports
1 In the model window, right-click the component and select PLC Code > Navigate
to Code.
2 Selecting Navigate to Code activates the HTML code generation report. The
following figure shows the result of tracing the Gain block within the subsystem.
In the report, the highlighted tag S1/Gain indicates the beginning of the generated
code for the block. You can use the same method to trace from other Simulink,
Stateflow and MATLAB objects to the generated traceability report.
For a programmatic way to trace a block in the model to generated code, see rtwtrace.
To review and analyze the generated code, it is helpful to navigate between the code and
model. You can include a web view of the model within the HTML code generation report.
You can then share your model and generated code outside of the MATLAB environment.
You need a Simulink Report Generator license to include a Web view (Simulink Report
Generator) of the model in the code generation report.
5-9
5 Code Generation Reports
Web views require a web browser that supports Scalable Vector Graphics (SVG). Web
views use SVG to render and navigate models.
• Mozilla® Firefox® Version 1.5 or later, which has native support for SVG. To download
the Firefox browser, go to www.mozilla.com/.
• Apple Safari Web browser
• The Microsoft® Internet Explorer® web browser with the Adobe® SVG Viewer plug-in.
To download the Adobe SVG Viewer plug-in, go to www.adobe.com/svg/.
This example shows how to create an HTML code generation report which includes a web
view of the model diagram.
5-10
Create and Use Code Generation Reports
6 Click PLC Code Generation > Generate code to initiate code and report
generation. The code generation report for the top model opens in a MATLAB web
browser.
5-11
5 Code Generation Reports
7 In the left navigation pane, select a source code file. The corresponding traceable
source code is displayed in the right pane and includes hyperlinks.
8 Click a link in the code. The model web view displays and highlights the
corresponding block in the model.
9 To go back to the code generation report for the top model, at the top of the left
navigation pane, click the Back button until the report for the top model is displayed.
5-12
Create and Use Code Generation Reports
For more information about navigating between the generated code and the model
diagram, see:
When you are using the model web view, the HTML code generation report includes the
following limitations:
• Code is not generated for virtual blocks. In the model web view, if you click a virtual
block, the code generation report clears highlighting in the source code files.
• Stateflow truth tables, events, and links to library charts are not supported in the
model web view.
• Searching in the code generation report does not find or highlight text in the model
web view.
• In a subsystem build, the traceability hyperlinks of the root-level inports and outports
blocks are disabled.
• If you navigate from the actual model diagram (not the model web view in the
report), to the source code in the HTML code generation report, the model web view
is disabled and not visible. To enable the model web view, open the report again, see
“Open Code Generation Report” (Simulink Coder).
1 Open the Configuration Parameters dialog box and navigate to the PLC Code
Generation pane.
2 To enable report generation, select Report > Generate traceability report.
3 Click Apply.
5-13
5 Code Generation Reports
4 Click PLC Code Generation > Generate code to initiate code and report
generation. The coder generates HTML report files as part of the code generation
process. The Code Metrics Report is shown on the left navigation pane.
5-14
Create and Use Code Generation Reports
open_system('plcdemo_simple_subsystem');
2 Enable the code generation parameter PLC_GenerateReport. To view the output in
the model web view, also enable PLC_GenerateWebview:
set_param('plcdemo_simple_subsystem', 'PLC_GenerateReport', 'on');
set_param('plcdemo_simple_subsystem', 'PLC_GenerateWebView', 'on');
5-15
5 Code Generation Reports
Note: The requirement links must be associated with a model object. If requirements
links are associated with the code in a MATLAB Function block, they do not appear in
generated code comments.
Option Purpose
Include comments on page 13-15 Model information must appear in code
comments.
Generate traceability report on page After code is generated, a Code
13-37 Generation Report must be produced.
3 Generate code.
The Code Generation Report opens. The links to requirements documents appear in
generated code comments. When you view the code in the Code Generation Report,
you can open the links from the comments.
5-16
Working with the Static Code Metrics Report
In this section...
“Workflow for Static Code Metrics Report” on page 5-17
“Report Contents” on page 5-18
“Function Block Information” on page 5-19
You can use the information in the Static Code Metrics Report to assess the generated
code and make model changes before code implementation in your target IDE.
Before starting, you must familiarize yourself with potential code limitations of your
IDE. For example, some IDEs have limits on the number of variables or lines of code in a
function block.
For detailed instructions on generating the report, see “Generate a Static Code Metrics
Report” on page 5-13.
5-17
5 Code Generation Reports
Report Contents
The Static Code Metrics Report is divided into the following sections:
• File Information: Reports high-level information about generated files, such as lines
and lines of code.
• Global Variables: Reports information about global variables defined in the
generated code.
• Global Constants: Reports information about global constants defined in the
generated code.
5-18
Working with the Static Code Metrics Report
• Function Block Information: Reports a table of metrics for each function block
generated from your model.
5-19
6
To control how the block parameters appear in the generated code, you can either define
the parameters as Simulink.Parameter objects in the MATLAB workspace or use
the Model Parameter Configuration dialog box. For more information, see “Control
Appearance of Block Parameters in Generated Code” on page 6-5.
Simulink PLC Coder exports tunable parameters as exported symbols and preserves
the names of these parameters in the generated code. It does not mangle these names.
As a result, if you use a reserved IDE keyword as a tunable parameter name, the code
generation can cause compilation errors in the IDE. As a best practice, do not use IDE
keywords as tunable parameter names.
The coder maps tunable parameters in the generated code as listed in the following table:
6-2
Block Parameters in Generated Code
6-3
6 Working with Tunable Parameters in the Simulink PLC Coder Environment
6-4
Control Appearance of Block Parameters in Generated Code
For more information, see “Block Parameters in Generated Code” on page 6-2.
Simulink stores Simulink.Parameter objects outside the model. You can then
share Simulink.Parameter objects between multiple models.
• Use the Model Configuration Parameters dialog box to make the parameters
tunable.
Note: The MATLAB workspace parameter value must be of the same data type as
used in the model. Otherwise, the value of the variable in the generated code is set to
zero. See “Workspace Parameter Data Type Limitations” on page 11-3.
6-5
6 Working with Tunable Parameters in the Simulink PLC Coder Environment
The following script setup_tunable_params.m creates the constants K1, K2, and
K3 as Simulink.Parameter objects, assigns values, and sets the storage classes for
these constants. For more information on the storage classes, see “Block Parameters
in Generated Code” on page 6-2.
a In the model window, select File > Model Properties > Model Properties.
b In the Model Properties dialog box, on the Callbacks tab, select PreLoadFcn.
Enter setup_tunable_params for Model pre-load function.
6-6
Control Appearance of Block Parameters in Generated Code
c On the Callbacks tab, select CloseFcn. Enter clear K1 K2 K3; for Model
close function.
Every time that you open the model, the variables K1, K2, and K3 are loaded into the
base workspace. You can view the variables and their storage classes in the Model
Explorer.
3 Generate code and inspect it.
6-7
6 Working with Tunable Parameters in the Simulink PLC Coder Environment
FUNCTION_BLOCK SimpleSubsystem
.
.
VAR
K1: LREAL := 0.1;
.
.
END_VAR
.
.
END_FUNCTION_BLOCK
K2 ExportedGlobal K2 is a global variable.
VAR_GLOBAL
K2: LREAL := 0.2;
END_VAR
K3 ExportedGlobal and K3 is a global constant.
CoderInfo.CustomStorageClass
set to Const. VAR_GLOBAL CONSTANT
SS_INITIALIZE: SINT := 0;
K3: LREAL := 0.3;
SS_STEP: SINT := 1;
END_VAR
1 Specify that the variables K1, K2, and K3 must be initialized before the model loads
and that the MATLAB workspace must be cleared before the model closes.
6-8
Control Appearance of Block Parameters in Generated Code
b In the Model Properties dialog box, on the Callbacks tab, select PreLoadFcn.
Enter K1=0.1; K2=0.2; K3=0.3; for Model pre-load function.
c On the Callbacks tab, select CloseFcn. Enter clear K1 K2 K3; for Model
close function.
2 Select Simulation > Model Configuration Parameters.
3 Navigate to Optimization > Signals and Parameters. In the Simulation
and code generation section, specify that all parameters must be inlined in the
generated code. Select Inlined for Default Parameter Behavior.
4 To override the inlining and make individual parameters tunable, click Configure.
In the Model Parameter Configuration dialog box, from the Source list, select
Referenced workspace variables.
5 Ctrl+select the parameters and click Add to table >>.
By default, this dialog box sets all parameters to the SimulinkGlobal storage class.
Set the Storage class and Storage type qualifier as shown in this figure. For
more information on the storage classes, see “Block Parameters in Generated Code”
on page 6-2.
6-9
6 Working with Tunable Parameters in the Simulink PLC Coder Environment
FUNCTION_BLOCK SimpleSubsystem
.
.
VAR
K1: LREAL := 0.1;
.
6-10
Control Appearance of Block Parameters in Generated Code
VAR_GLOBAL
K2: LREAL := 0.2;
END_VAR
K3 ExportedGlobal and K3 is a global constant.
Storage type qualifier set
to Const. VAR_GLOBAL CONSTANT
SS_INITIALIZE: SINT := 0;
K3: LREAL := 0.3;
SS_STEP: SINT := 1;
END_VAR
6-11
7
1 Set up a data store in your model by using a Data Store Memory block.
2 Associate a Simulink.Signal object with the data store.
a In the model workspace, define a Simulink.Signal object with the same name
as the data store. Set the storage class of the object to ExportedGlobal or
ImportedExtern.
b In the Data Store Memory block parameters, on the Signal Attributes tab,
select Data store name must resolve to Simulink signal object.
3 In your model, attach the signals that you want to Data Store Read blocks that read
from the data store and Data Store Write blocks that write to the data store.
The Simulink.Signal object that is associated with the global Data Store Memory
block appears as a global variable in generated code.
Note: If you follow this workflow for Rockwell Automation RSLogix 5000 AOIs, the
generated code uses INOUT variables for the global data.
7-2
Control Code Partitions for Subsystem Block
• Generates a function block for the top-level atomic subsystem for which you generate
code.
• Generates a function block for an atomic subsystem whose Function packaging
parameter is set to Nonreusable function or Reusable function.
• Inlines generated code from atomic subsystems, whose Function packaging
parameter is set to Inline, into the function block that corresponds to the nearest
ancestor subsystem. This nearest ancestor cannot be inlined.
For code generation from a subsystem with no inputs or outputs, you must set the
Function packaging parameter of the block to Reusable function.
• Function packaging
• Function name options
Use the Function packaging parameter to specify the code format to generate for
an atomic (nonvirtual) subsystem. The Simulink PLC Coder software interprets this
parameter depending on the setting that you choose:
7-3
7 Controlling Generated Code Partitions
You can use the Function name options parameter to change the name of a subsystem
from the one on the block label. When the Simulink PLC Coder generates software, it
uses the string you specify for this parameter as the subsystem name. For example, see
plcdemo_hierarchical_virtual_subsystem:
7-4
Control Code Partitions for Subsystem Block
2 If the Treat as atomic unit check box is not yet selected, select it.
3 Click the Code Generation tab.
4 Set Function packaging to Nonreusable function.
5 Set Function name options to User specified.
6 In the Function name field, specify a custom name. For example, type
my_own_subsystem.
7-5
7 Controlling Generated Code Partitions
7-6
Control Code Partitions for Subsystem Block
7-7
7 Controlling Generated Code Partitions
7-8
Control Code Partitions for Subsystem Block
7-9
7 Controlling Generated Code Partitions
However, Simulink PLC Coder does not follow your inlining specifications exactly in the
following cases:
Explanation: A structured text function cannot have multiple outputs, therefore the
MATLAB function cannot be converted to a structured text function.
The following simple example illustrates the different cases. The model used here has a
Stateflow chart that contains four MATLAB functions fcn1 to fcn4.
7-10
Control Code Partitions for MATLAB Functions in Stateflow Charts
7-11
7 Controlling Generated Code Partitions
7-12
Control Code Partitions for MATLAB Functions in Stateflow Charts
7-13
7 Controlling Generated Code Partitions
7-14
Control Code Partitions for MATLAB Functions in Stateflow Charts
7-15
8
• Define the custom element in the subsystem for which you want to generate code.
• Name the custom element.
• In the Configuration Parameters dialog box, add the name of the custom element
to PLC Code Generation > Symbols > Externally Defined Symbols in the
Configuration Parameters dialog box.
• Generate code.
For a description of how to integrate a custom function block, see “Integrate Custom
Function Block in Generated Code” on page 8-3. For a description of the Externally
Defined Symbols parameter, see “Externally Defined Symbols” on page 13-33.
8-2
Integrate Custom Function Block in Generated Code
function Y = fcn(U,V)
% Stub behavior for simulation. This block
% is replaced during code generation
Y = U + V;
4 Change the MATLAB Function block name to ExternallyDefinedBlock.
5 Create a subsystem from this MATLAB Function block.
6 Complete the model to look like plcdemo_external_symbols.
8-3
8 Integrating Externally Defined Symbols
8-4
Integrate Custom Function Block in Generated Code
8-5
9
IDE-Specific Considerations
• How to generate code, see “Generate and Examine Structured Text Code” on page
1-17.
• The location of generated code, see “Files Generated with Simulink PLC Coder” on
page 1-23.
Unless you assigned a custom name, the file is called model_name.scl. After you
open the file, a new entry called model_name.scl appears under the Sources node.
3 Double-click the new entry. The generated code is listed in the SCL editor window.
4 In the SCL editor window, select Options > Customize.
5 In the customize window, select Create block numbers automatically and click
OK.
The new Function Block is now integrated and available for use with the existing
Siemens SIMATIC STEP 7 project.
Unless you assigned a custom name, the file is called model_name.scl. After you
open the file, a new entry called model_name.scl appears under the External
source files node.
9-2
Integrate Generated Code with Siemens IDE Project
3 Right-click the new entry and select Generate blocks from source.
The Siemens TIA Portal IDE compiles the new file and generates TIA Portal
program blocks from the code. The program blocks appear under the Program
blocks node. They are available for use with the existing Siemens TIA Portal
project.
9-3
9 IDE-Specific Considerations
plcdemo_simple_subsystem
2 In the Configuration Parameters dialog box, set Target IDE to Rockwell RSLogix
5000: AOI.
3 In the top-level subsystem of the model, right-click the output signal of
SimpleSubsystem and select Properties.
9-4
Use Internal Signals for Debugging in RSLogix 5000 IDE
5 Click OK.
6 Generate code for the top-level subsystem.
7 Inspect the generated code for the string Required=false.
For more information on signals with test points, see “What Is a Test Point?” (Simulink).
9-5
9 IDE-Specific Considerations
Design your model to use single-precision data type (single) as much as possible instead
of double-precision data type (double). If you must use doubles in your model, the
numerical results produced by the generated Structured Text can differ from Simulink
results. This difference is due to double-single conversion in the generated code.
Design your model to use signed integer data types (int8, int16, int32) as much as
possible instead of unsigned integer data types (uint8, uint16, uint32). Doing so avoids
overflow issues that unsigned-to-signed integer conversions can cause in the generated
code.
9-6
Rockwell Automation RSLogix Considerations
9-7
9 IDE-Specific Considerations
For Siemens PLC devices that support double-precision floating point types, use
Siemens TIA Portal: Double Precision as Target IDE for generating code.
The generated code uses the LREAL type for double-precision floating point types in the
model. For more information, see “Target IDE” on page 13-5.
Design your model to use int16 and int32 data types as much as possible instead of int8
or unsigned integer data types. The Simulink numerical results using int8 or unsigned
integer data types can differ from the numerical results produced by the generated
Structured Text.
Design your model so that effects of integer data type conversion of the generated code do
not change the expected semantics of the model.
9-8
Considerations for Siemens IDEs
INOUT Variables
The Siemens SIMATIC STEP 7 and the TIA Portal single-precision targets do not
support INOUT variables. If your Simulink model contains MATLAB Function blocks
with y = f ( y ) style in-place variables, coder generates code using normal input and
output variables. However, if the code generation option for the MATLAB Function block
is set to use Reusable function, this conversion is not possible. To fix this issue, rewrite
the MATLAB Function block without using in-place variables or change the block code
generation option to either Auto or Inline.
9-9
10
Supported Blocks
For Simulink semantics not supported by Simulink PLC Coder, see “Coder Limitations”
on page 11-2.
In this section...
“View Supported Blocks Library” on page 10-2
“Supported Simulink Blocks” on page 10-3
“Supported Stateflow Blocks” on page 10-12
“Blocks With Restricted Support” on page 10-12
10-2
Supported Blocks
This library contains two sublibraries, Simulink and Stateflow. Each sublibrary contains
the blocks that you can include in a Simulink PLC Coder model.
10-3
10 Supported Simulink and Stateflow Blocks
Inport
Bus Creator
Bus Selector
Constant
Demux
Discrete-Time Integrator
Gain
Ground
10-4
Supported Blocks
Logical Operator
Mux
Product
Relational Operator
Saturation
Scope
Subsystem
Inport
Outport
Sum
Switch
Terminator
Unit Delay
Discontinuities
Rate Limiter
Relay
Saturation
Saturation Dynamic
Wrap To Zero
10-5
10 Supported Simulink and Stateflow Blocks
Discrete
Difference
Discrete Derivative
Discrete Filter
PID Controller
Discrete State-Space
Discrete-Time Integrator
Integer Delay
Memory
Tapped Delay
Unit Delay
Zero-Order Hold
Bit Clear
Bit Set
Bitwise Operator
10-6
Supported Blocks
Compare To Constant
Compare To Zero
Detect Change
Detect Decrease
Detect Increase
Extract Bits
Interval Test
Logical Operator
Shift Arithmetic
Lookup Tables
Dynamic-Lookup
PreLookup
Math Operations
Abs
Add
10-7
10 Supported Simulink and Stateflow Blocks
Assignment
Bias
Divide
Dot Product
Gain
Math Function
Matrix Concatenate
MinMax
Permute Dimensions
Polynomial
Product
Product of Elements
Reciprocal Sqrt
Reshape
Rounding Function
Sign
Slider Gain
Sqrt
Squeeze
Subtract
Sum
10-8
Supported Blocks
Sum of Elements
Trigonometric Function
Unary Minus
Vector Concatenate
Model Verification
Assertion
Model-Wide Utilities
DocBlock
Model Info
Atomic Subsystem
CodeReuse Subsystem
10-9
10 Supported Simulink and Stateflow Blocks
Enabled Subsystem
Enable
Function-Call Subsystem
Subsystem
Inport
Outport
Signal Attributes
Signal Conversion
Signal Routing
Bus Assignment
Bus Creator
Bus Selector
Demux
From
Goto
Index Vector
Multiport Switch
Mux
10-10
Supported Blocks
Selector
Sinks
Display
Floating Scope
Scope
Stop Simulation
Terminator
To File
To Workspace
XY Graph
Sources
Constant
Counter Free-Running
Counter Limited
Enumerated Constant
Ground
Pulse Generator
User-Defined Functions
MATLAB Function
Fcn
10-11
10 Supported Simulink and Stateflow Blocks
Stateflow
Chart
Truth Table
The Simulink PLC Coder software supports the plclib blocks with the following
exceptions. Also, see “Coder Limitations” on page 11-2 for a list of limitations of the
software.
If you get unsupported fixed-point type messages during code generation, update
the block parameter. Open the block parameter dialog box. Navigate to the Signal
Attributes and Parameter Attributes tabs. Check that the Output data type and
Parameter data type parameters are not Inherit: Inherit via internal rule.
Set these parameters to either Inherit: Same as input or a desired non-fixed-point
data type, such as double or int8.
If you receive a message about consistency between the original subsystem and the S-
function generated from the subsystem build, and the model contains a Stateflow chart
that contains one or more Simulink functions, use the following procedure to address the
issue:
1 Open the model and double-click the Stateflow chart that causes the issue.
10-12
Supported Blocks
4 In the Chart dialog box, navigate to the States When Enabling parameter and
select Held.
5 Click Apply and OK and save the model.
To generate PLC code for a model that uses a Data Store Memory block, first define a
Simulink.Signal object in the base workspace. Then, in the Signal Attributes tab
of the block parameters, set the data store name to resolve to that Simulink.Signal
object.
For more information, see “Data Stores with Data Store Memory Blocks” (Simulink).
The Simulink PLC Coder software does not support the Simulink Reciprocal Sqrt block
signedSqrt and rSqrt functions.
Simulink PLC Coder has limited support for lookup table blocks. The coder does not
support:
Note: The Simulink PLC Coder software does not support the Simulink Lookup Table
Dynamic block. For your convenience, the plclib/Simulink/Lookup Tables library
contains an implementation of a dynamic table lookup block using the Prelookup and
Interpolation Using Prelookup blocks.
10-13
11
Limitations
11 Limitations
Coder Limitations
In this section...
“Current Limitations” on page 11-2
“rand Function Support Limitations” on page 11-3
“Workspace Parameter Data Type Limitations” on page 11-3
“Traceability Report Limitations” on page 11-3
“Fixed-Point Data Type Limitations” on page 11-4
“Multirate Model Limitations” on page 11-6
“Permanent Limitations” on page 11-6
Current Limitations
The Simulink PLC Coder software does not support the following Simulink semantics:
11-2
Coder Limitations
• Width block
Use a MATLAB Function block instead. In the MATLAB function on the block, use
the length function to compute input vector width.
• Cell arrays in MATLAB Function blocks
• In MATLAB Function blocks, only standard MATLAB functions are supported.
Functions from toolboxes are not supported. For the list of standard functions
supported for code generation, see “Functions and Objects Supported for C/C++ Code
Generation — Category List” (Simulink).
If you specify the type of the Simulink.Parameter object by using the DataType
property, use a typed expression when assigning a value to the parameter object. For
example, if the Simulink.Parameter object K1 is used to store a value of the type
single, use a typed expression such as single(0.3) when assigning a value to K1.
K1 = Simulink.Parameter;
K1.Value = single(0.3);
K1.StorageClass = 'ExportedGlobal';
K1.DataType = 'single';
11-3
11 Limitations
Note: If you do not configure the blocks and models as directed, the generated Structured
Text might:
• Not compile.
• Compile, but return results that differ from the simulation results.
Block Parameters
1 If the block in the subsystem has a Signal Attributes tab, navigate to that tab.
2 For the Integer rounding mode parameter, select Round.
3 Clear the Saturate on integer overflow check box.
4 For the Output data type parameter, select a fixed-point data type.
5 Click the Data Type Assistant button.
6 For the Word length parameter, enter 8, 16, or 32.
7 For the Mode parameter, select Fixed point.
8 For the Scaling parameter, select Binary point.
11-4
Coder Limitations
9 Click OK.
11-5
11 Limitations
• Change any continuous time input signals in the top-level subsystem to use discrete
fixed sample times.
• For the solver, select single-tasking execution.
The B&R Automation Studio IDE is not supported for multirate model code generation.
When you deploy code generated from a multirate model, you must run the code at the
fundamental sample rate.
Permanent Limitations
The Structured Text language has inherent restrictions. As a result, the Simulink PLC
Coder software has the following restrictions:
• The Simulink PLC Coder software supports code generation only for atomic
subsystems.
• The Simulink PLC Coder software supports automatic, inline, or reusable function
packaging for code generation. Nonreusable function packaging is not supported.
11-6
Coder Limitations
11-7
12
plccoderdemos
Product examples
Syntax
plccoderdemos
Description
plccoderdemos displays the Simulink PLC Coder examples.
Examples
Display Simulink PLC Coder Examples
See Also
plcopenconfigset
Introduced in R2010a
12-2
plccoderpref
plccoderpref
Manage user preferences
Syntax
plccoderpref
plccoderpref('plctargetide')
plccoderpref('plctargetide', preference_value)
plccoderpref('plctargetide', 'default')
plccoderpref('plctargetidepaths')
plccoderpref('plctargetidepaths','default')
plccoderpref('plctargetlist')
plccoderpref('plctargetlist',targetlist)
Description
plccoderpref displays the current set of user preferences, including the default target
IDE.
12-3
12 Functions — Alphabetical List
information, see “Target IDE” on page 13-5 and “Show Full Target List” on page
13-8.
Input Arguments
plctargetide
Value Description
codesys23 3S-Smart Software Solutions CoDeSys Version
2.3 (default) target IDE
codesys33 3S-Smart Software Solutions CoDeSys Version
3.3 target IDE
codesys35 3S-Smart Software Solutions CoDeSys Version
3.5 target IDE
brautomation30 B&R Automation Studio 3.0 target IDE
brautomation40 B&R Automation Studio 4.0 target IDE
generic Generic target IDE
indraworks Rexroth IndraWorks version 13V12 IDE
multiprog50 KW-Software MULTIPROG 5.0 target IDE
omron OMRON Sysmac Studio
plcopen PLCopen XML target IDE
pcworx60 Phoenix Contact PC WORX 6.0
rslogix5000 Rockwell Automation RSLogix 5000 Series target
IDE for AOI format
rslogix5000_routine Rockwell Automation RSLogix 5000 Series target
IDE for routine format
step7 Siemens SIMATIC STEP 7 Version 5 target IDE
studio5000 Rockwell Studio 5000 Logix Designer target IDE
for AOI format
12-4
plccoderpref
Value Description
studio5000_routine Rockwell Studio 5000 Logix Designer target IDE
for routine format
twincat211 Beckhoff TwinCAT 2.11 target IDE
twincat3 Beckhoff TwinCAT 3 target IDE
tiaportal Siemens TIA Portal
tiaportal_double Siemens TIA Portal with support for double
precision (LREAL type)
Default: codesys23
plctargetidepaths
String that specifies the target IDE installation path. Contains a 1-by-1 structure of the
installation paths of supported target IDEs.
codesys23: 'C:\Program Files\3S Software'
codesys33: 'C:\Program Files\3S CoDeSys'
codesys35: 'C:\Program Files\3S CoDeSys'
studio5000: 'C:\Program Files\Rockwell Software'
studio5000_routine: 'C:\Program Files\Rockwell Software'
rslogix5000: 'C:\Program Files\Rockwell Software'
rslogix5000_routine: 'C:\Program Files\Rockwell Software'
brautomation30: 'C:\Program Files\BrAutomation'
brautomation40: 'C:\Program Files\BrAutomation'
multiprog50: 'C:\Program Files\KW-Software\MULTIPROG 5.0'
pcworx60: 'C:\Program Files\Phoenix Contact\Software Suite 150'
step7: 'C:\Program Files\Siemens'
tiaportal: 'C:\Program Files\Siemens\Automation'
tiaportal_double: 'C:\Program Files\Siemens\Automation'
plcopen: ''
twincat211: 'C:\TwinCAT'
twincat3: 'C:\TwinCAT'
generic: ''
indraworks: ''
omron: ''
default
plctargetlist
Cell array of strings. Each string specifies a target IDE. You can specify any target IDE
that is available for the plctargetide argument.
12-5
12 Functions — Alphabetical List
Use the string default to reset the reduced Target IDE list.
Examples
Return Current Default Target IDE
plccoderpref('plctargetide')
ans =
'codesys23'
ans =
'rslogix5000'
Assume that you have previously changed the installation path of the CoDeSys 2.3 target
IDE. Return the current target IDE installation paths.
plccoderpref('plctargetidepaths')
ans =
codesys23: 'E:\hub\hub_share\share\apps\3S-Software\CoDeSys\v2.3'
codesys33: 'C:\Program Files\3S CoDeSys'
codesys35: 'C:\Program Files\3S CoDeSys'
studio5000: 'C:\Program Files\Rockwell Software'
studio5000_routine: 'C:\Program Files\Rockwell Software'
rslogix5000: 'C:\Program Files\Rockwell Software'
rslogix5000_routine: 'C:\Program Files\Rockwell Software'
12-6
plccoderpref
If you disable Show full target list, the drop down for Target IDE shows only a subset
of the supported IDEs. Customize this reduced list to contain only the IDEs CoDeSys 2.3
and Rockwell Automation RSLogix 5000 Series for AOI format.
targetlist = {'codesys23','rslogix5000'};
plccoderpref('plctargetlist',targetlist)
ans =
'codesys23' 'rslogix5000'
plccoderpref('plctargetlist','default')
ans =
12-7
12 Functions — Alphabetical List
Append the IDE CoDeSys 3.5 to the default reduced Target IDE list.
plccoderpref('plctargetlist', [plccoderpref('plctargetlist', 'default') 'codesys35'])
ans =
Columns 1 through 5
Column 6
'codesys35'
Append the IDE CoDeSys 3.5 to the current reduced Target IDE list.
plccoderpref('plctargetlist', [plccoderpref('plctargetlist') 'codesys35'])
ans =
Tips
Use the Simulink Configuration Parameters dialog box to change the installation path of
a target IDE (Target IDE Path).
Introduced in R2010a
12-8
plcgeneratecode
plcgeneratecode
Generate Structured Text for subsystem
Syntax
generatedfiles = plcgeneratecode(subsystem)
Description
generatedfiles = plcgeneratecode(subsystem) generates Structured Text for
the specified atomic subsystem in a model. subsystem is the fully qualified path name of
the atomic subsystem. generatedfiles is a cell array of the generated file names. You
must first load or start the model.
Examples
Generate Structured Text Code for Subsystem
plcdemo_simple_subsystem
12-9
12 Functions — Alphabetical List
generatedFiles = plcgeneratecode('plcdemo_simple_subsystem/SimpleSubsystem');
See Also
plcopenconfigset
Introduced in R2010a
12-10
plcopenconfigset
plcopenconfigset
Open Configuration Parameters dialog box for subsystem
Syntax
plcopenconfigset(subsystem)
Description
plcopenconfigset(subsystem) opens the Configuration Parameters dialog box for
the specified atomic subsystem in the model. subsystem is the fully qualified path name
of the atomic subsystem.
Examples
Open Configuration Parameters for Subsystem
open_system('plcdemo_simple_subsystem')
12-11
12 Functions — Alphabetical List
plcopenconfigset('plcdemo_simple_subsystem/SimpleSubsystem')
See Also
plcgeneratecode
Introduced in R2010a
12-12
plccheckforladder
plccheckforladder
Check whether Stateflow chart is ready for Ladder Diagram code generation
Syntax
plccheckforladder(chartPath)
Description
plccheckforladder(chartPath) checks whether a Stateflow chart (Stateflow) is
ready for Ladder Diagram code generation. The function shows errors in the Diagnostic
Viewer window if the chart has properties that do not allow Ladder Diagram code
generation on page 3-19.
Examples
Preparation of Stateflow Chart for Ladder Diagram Code Generation
The model contains a subsystem Subsys, which contains a Stateflow chart, 3Aspect.
Save the model elsewhere with the name plcdemo_ladder_three_aspect_copy.
Enable super step semantics for the chart. In the chart properties, select Enable Super
Step Semantics.
Check whether the Stateflow chart is ready for Ladder Diagram code generation.
plccheckforladder('plcdemo_ladder_three_aspect_copy/Subsys/3Aspect')
You see the following error message in the Diagnostic Viewer window:
Chart must not have superstep semantics enabled in Objects: 'Subsys/3Aspect'
12-13
12 Functions — Alphabetical List
plcprepareforladder('plcdemo_ladder_three_aspect_copy/Subsys/3Aspect')
Check again whether the chart is ready for Ladder Diagram code generation.
plccheckforladder('plcdemo_ladder_three_aspect_copy/Subsys/3Aspect')
There are no more error messages. The function plcprepareforladder has disabled
super step semantics for the chart.
Input Arguments
chartPath — Full path name of the Stateflow chart
character vector
Full path name of the Stateflow chart relative to the top-level Simulink model, specified
as a character vector. To obtain the full path, select the Stateflow chart in your model
and use the gcb function.
Example: gcb, 'ThreeAspectAutoSignal/Subsystem/AutoSignalChart'
See Also
See Also
plcgenerateladder | plcprepareforladder
Topics
“Prepare Chart for Ladder Diagram Generation” on page 3-6
“Generate Ladder Diagram Code from Stateflow Chart” on page 3-10
“Import Ladder Diagram Code to CODESYS 3.5 IDE and Validate Diagram” on page
3-15
“Ladder Diagram Generation for PLC Controllers” on page 3-2
“Supported IDE Platforms” on page 1-6
12-14
plccheckforladder
Introduced in R2016b
12-15
12 Functions — Alphabetical List
plcprepareforladder
Change some Stateflow chart properties to enable Ladder Diagram code generation
Syntax
plcprepareforladder(chartPath)
Description
plcprepareforladder(chartPath) changes certain properties of a Stateflow chart
(Stateflow) so that the chart is ready for Ladder Diagram code generation. The following
properties are changed:
Examples
open_system('plcdemo_ladder_three_aspect')
The model contains a subsystem Subsys, which contains a Stateflow chart, 3Aspect.
Save the model elsewhere with the name plcdemo_ladder_three_aspect_copy.
Enable super step semantics for the chart. In the chart properties, select Enable Super
Step Semantics.
Check whether the Stateflow chart is ready for Ladder Diagram code generation.
plccheckforladder('plcdemo_ladder_three_aspect_copy/Subsys/3Aspect')
12-16
plcprepareforladder
You see the following error message in the Diagnostic Viewer window:
Chart must not have superstep semantics enabled in Objects: 'Subsys/3Aspect'
Check again whether the chart is ready for Ladder Diagram code generation.
plccheckforladder('plcdemo_ladder_three_aspect_copy/Subsys/3Aspect')
There are no more error messages. The function plcprepareforladder has disabled
super step semantics for the chart.
Tips
• Before you use this function, make a backup copy of your model because the function
changes chart properties.
• The function does not change all properties that would allow for Ladder Diagram code
generation. You might still have to explicitly change certain properties. For the full
list of chart properties that are not allowed, see “Restrictions on Stateflow Chart for
Ladder Diagram Generation” on page 3-19.
Input Arguments
chartPath — Full path name of the Stateflow chart
character vector
Full path name of the Stateflow chart relative to the top-level Simulink model, specified
as a character vector. To obtain the full path, select the Stateflow chart in your model
and use the gcb function.
Example: gcb, 'ThreeAspectAutoSignal/Subsystem/AutoSignalChart'
See Also
See Also
plccheckforladder | plcgenerateladder
12-17
12 Functions — Alphabetical List
Topics
“Prepare Chart for Ladder Diagram Generation” on page 3-6
“Generate Ladder Diagram Code from Stateflow Chart” on page 3-10
“Import Ladder Diagram Code to CODESYS 3.5 IDE and Validate Diagram” on page
3-15
“Ladder Diagram Generation for PLC Controllers” on page 3-2
“Supported IDE Platforms” on page 1-6
Introduced in R2016b
12-18
plcgenerateladder
plcgenerateladder
Generate Ladder Diagram code from Stateflow chart
Syntax
plcgenerateladder(chartPath)
plcgenerateladder(chartPath,Name,Value)
Description
plcgenerateladder(chartPath) generates code from a Stateflow chart (Stateflow)
that you can import to an IDE such as CODESYS 3.5 and view as a ladder diagram.
Examples
Generate Ladder Diagram Code from Stateflow Chart
ans =
12-19
12 Functions — Alphabetical List
If code generation is successful, three files are generated in the subfolder plcsrc of your
current folder:
Generate Ladder Diagram code from the Stateflow chart, 3Aspect, along with a test
bench.
plcgenerateladder('plcdemo_ladder_three_aspect/Subsys/3Aspect', ...
'GenerateTestBench','on')
ans =
You can import the Ladder Diagram code and the test bench together to a target IDE
such as CODESYS 3.5. In the IDE, you can validate the ladder diagram against the test
bench.
12-20
plcgenerateladder
• “Import Ladder Diagram Code to CODESYS 3.5 IDE and Validate Diagram” on
page 3-15
Input Arguments
chartPath — Full path name of the Stateflow chart
character vector
Full path name of the Stateflow chart relative to the top-level Simulink model, specified
as a character vector. To obtain the full path, select the Stateflow chart in your model
and use the gcb function.
• The inputs and outputs to the chart must be Boolean. These inputs and outputs
correspond to the input and output terminals of your PLC.
• Each state of the chart must correspond to a chart output.
• The expressions controlling the transition between states must involve only Boolean
operations between the inputs.
For instance, in the following chart, c1, c2, c3 and c4 are Boolean inputs to the model.
A1, A2, A3 and A4 are Boolean outputs from the model.
12-21
12 Functions — Alphabetical List
Some advanced Stateflow features on page 3-19 are not supported because of inherent
restrictions in ladder logic semantics. See the full list of unsupported features.
Example: gcb, 'ThreeAspectAutoSignal/Subsystem/AutoSignalChart'
You can import the Ladder Diagram code and the test bench together to a target IDE
such as CODESYS 3.5. In the IDE, you can validate the ladder diagram against the test
bench.
In the ladder diagram, when the output coil corresponding to the active state is turned
on, reset coils can be used to force deactivation of other states. The reset coils act as a
safeguard against multiple states being simultaneously active. Specify whether the reset
coils must be generated.
• If you do not enable this option, each output is a coil that represents a state in the
chart.
The following figure shows an output of the diagram when imported into the
CODESYS 3.5 IDE. The output coil represents a state A1 in the chart. When the state
is active, the coil receives power.
12-22
plcgenerateladder
• If you enable this option, each output is a coil that represents a state of the chart.
The output is also coupled with reset coils that represent the other states. When a
particular state is active, the reset coils force deactivation of the other states.
The following figure shows an output in the ladder diagram when viewed in the
CODESYS 3.5 IDE. The output coil represents a state A1. To avoid multiple states
from being simultaneously active, the signal that turns the coil on also turns on the
reset coils associated with the other states A2, A3 and A4.
Specify whether a validation model must be generated. You can use the validation model
to compare the generated Ladder Diagram code against the original Stateflow chart.
When you simulate this validation model, for all inputs, the software verifies the output
of the second block against the first block. If the output of the second Subsystem block
does not match the first, the simulation fails.
12-23
12 Functions — Alphabetical List
'PLC_OutputDir' — Path relative to current folder where generated files are placed
'plcsrc' (default) | character vector
Path relative to the current folder, specified as a character vector. The generated code
files are placed in this subfolder. If you do not specify a value, the subfolder plcsrc is
used.
The output folder must not have the same name as the current folder. For instance, if
you do not specify an output folder, plcsrc is used. If the current folder is also plcsrc,
an error occurs.
Example: 'out\plccode'
See Also
See Also
plccheckforladder | plcprepareforladder
Topics
“Prepare Chart for Ladder Diagram Generation” on page 3-6
“Generate Ladder Diagram Code from Stateflow Chart” on page 3-10
“Import Ladder Diagram Code to CODESYS 3.5 IDE and Validate Diagram” on page
3-15
“Ladder Diagram Generation for PLC Controllers” on page 3-2
“Supported IDE Platforms” on page 1-6
Introduced in R2016b
12-24
13
In this section...
“PLC Coder: General Tab Overview” on page 13-4
“Target IDE” on page 13-5
“Show Full Target List” on page 13-8
“Target IDE Path” on page 13-10
“Code Output Directory” on page 13-12
13-2
PLC Coder: General
In this section...
“Generate Testbench for Subsystem” on page 13-13
13-3
13 Configuration Parameters for Simulink PLC Coder Models
Configuration
1 Create a model.
2 Add either an Atomic Subsystem block, or a Subsystem block for which you have
selected the Treat as atomic unit check box.
3 Right-click the subsystem block and select PLC Code > Options.
Tip
In addition to configuring parameters for the Simulink PLC Coder model, you can
also use this dialog box to generate Structured Text code and test bench code for the
Subsystem block.
See Also
13-4
PLC Coder: General
Target IDE
Select the target IDE for which you want to generate code. This option is available on the
PLC Code Generation node in the Configuration Parameters window.
The default Target IDE list shows the full set of supported targets. See “Show Full
Target List” on page 13-8.
To see a reduced subset of targets, disable the option Show full target list.
To customize this list and specify IDEs that you use more frequently, use the
plccoderpref function. See plccoderpref.
For version numbers of supported IDEs, see “Supported IDE Platforms” on page 1-6.
Settings
3S CoDeSys 2.3
Generates Structured Text (IEC 61131-3) code for 3S-Smart Software Solutions
CoDeSys Version 2.3.
3S CoDeSys 3.3
Generates Structured Text code in PLCopen XML for 3S-Smart Software Solutions
CoDeSys Version 3.3.
3S CoDeSys 3.5
Generates Structured Text code in PLCopen XML for 3S-Smart Software Solutions
CoDeSys Version 3.5.
B&R Automation Studio 3.0
Generates Structured Text code for B&R Automation Studio 3.0.
B&R Automation Studio 4.0
Generates Structured Text code for B&R Automation Studio 4.0.
Beckhoff TwinCAT 2.11
Generates Structured Text code for Beckhoff TwinCAT 2.11 software.
Beckhoff TwinCAT 3
Generates Structured Text code for Beckhoff TwinCAT 3 software.
KW-Software MULTIPROG 5.0
13-5
13 Configuration Parameters for Simulink PLC Coder Models
13-6
PLC Coder: General
Generates Structured Text code for OMRON® Sysmac® Studio Version 1.04, 1.05, or
1.09.
Tip
• Rockwell Automation RSLogix 5000 routines represent the model hierarchy using
hierarchical user-defined types (UDTs). UDT types preserve model hierarchy in the
generated code.
• The coder generates code for reusable subsystems as separate routine instances.
These subsystems access instance data in program tag fields.
Command-Line Information
Parameter: PLC_TargetIDE
Type: string
Value: 'codesys23' | 'codesys33' | 'codesys35' | 'rslogix5000' |
'rslogix5000_routine' | 'studio5000' | 'studio5000_routine' |
'brautomation30' | 'brautomation40' | 'multiprog50' | 'pcworx60' |
'step7' | 'plcopen' | 'twincat211' | 'twincat3' | 'generic' | 'indraworks'
| 'omron' | 'tiaportal' | 'tiaportal_double'
Default: 'codesys23'
See Also
13-7
13 Configuration Parameters for Simulink PLC Coder Models
Instead of viewing the full list each time to select an IDE that is not present in the
reduced Target IDE list, you can add this IDE to the reduced list. To specify your own
reduced Target IDE list, use the plccoderpref function. See plccoderpref.
Settings
Default: On
On
The Target IDE list displays the full set of supported IDEs. For more information,
see “Supported IDE Platforms” on page 1-6.
Off
The Target IDE list displays only the more commonly used IDEs. The default subset
contains the following IDEs:
You can change this default reduced Target IDE list using the plccoderpref
function.
Command-Line Information
Parameter: PLC_ShowFullTargetList
Type: string
Value: 'on' | 'off'
Default: 'on'
13-8
PLC Coder: General
You can change the contents of the reduced Target IDE list using the plccoderpref
function. See plccoderpref.
13-9
13 Configuration Parameters for Simulink PLC Coder Models
Settings
Tip
• When you change the Target IDE value, the value of this parameter changes.
13-10
PLC Coder: General
• If you right-click the Subsystem block, the PLC Code > Generate and Import
Code for Subsystem command uses this value to import generated code.
• If your target IDE installation is standard, do not edit this parameter. Leave it as the
default value.
• If your target IDE installation is nonstandard, edit this value to specify the actual
installation path.
• If you change the path and click Apply, the changed path remains for that target IDE
for other models and between MATLAB sessions. To reinstate the factory default, use
the command:
plccoderpref('plctargetidepaths','default')
Command-Line Information
See plccoderpref.
See Also
13-11
13 Configuration Parameters for Simulink PLC Coder Models
Settings
Command-Line Information
Parameter: PLC_OutputDir
Type: string
Value: string
Default: 'plcsrc'
See Also
13-12
PLC Coder: General
Settings
Default: off
On
Enables generation of test bench code for subsystem.
Dependency
This parameter is disabled if your model has absolute time temporal logic.
Command-Line Information
Parameter: PLC_GenerateTestbench
Type: string
Value: 'on' | 'off'
Default: 'off'
See Also
13-13
13 Configuration Parameters for Simulink PLC Coder Models
In this section...
“Comments Overview” on page 13-15
“Include Comments” on page 13-15
“Include Block Description” on page 13-16
“Simulink Block / Stateflow Object Comments” on page 13-17
“Show Eliminated Blocks” on page 13-18
13-14
PLC Coder: Comments
Comments Overview
Control the comments that the Simulink PLC Coder software automatically creates and
inserts into the generated code.
See Also
Include Comments
Specify which comments are in generated files. This option is available on the PLC Code
Generation > Comments node in the Configuration Parameters window.
Settings
Default: on
On
Places comments in the generated files based on the selections in the Auto
generated comments pane.
If you create links to requirements documents from your model using the Simulink
Verification and Validation software, the links also appear in generated code
comments.
Off
Omits comments from the generated files.
Command-Line Information
Parameter: PLC_RTWGenerateComments
Type: string
Value: 'on' | 'off'
Default: 'on'
See Also
13-15
13 Configuration Parameters for Simulink PLC Coder Models
Settings
Default: on
On
Places comments in the generated files based on the contents of the block properties
General tab.
Off
Omits block descriptions from the generated files.
Command-Line Information
Parameter: PLC_PLCEnableBlockDescription
Type: string
Value: 'on' | 'off'
Default: 'on'
See Also
13-16
PLC Coder: Comments
Settings
Default: on
On
Inserts automatically generated comments that describe block code and objects. The
comments precede that code in the generated file.
Off
Suppresses comments.
Command-Line Information
Parameter: PLC_RTWSimulinkBlockComments
Type: string
Value: 'on' | 'off'
Default: 'on'
See Also
13-17
13 Configuration Parameters for Simulink PLC Coder Models
Settings
Default: off
On
Inserts statements in the generated code from blocks eliminated as the result of
optimizations (such as parameter inlining).
Off
Suppresses statements.
Command-Line Information
Parameter: PLC_RTWShowEliminatedStatement
Type: string
Value: 'on' | 'off'
Default: 'off'
See Also
13-18
PLC Coder: Optimization
In this section...
“Optimization Overview” on page 13-20
“Signal Storage Reuse” on page 13-21
“Remove Code from Floating-point to Integer Conversions That Wraps Out-Of-Range
Values” on page 13-23
“Generate Reusable Code” on page 13-24
“Loop Unrolling Threshold” on page 13-26
13-19
13 Configuration Parameters for Simulink PLC Coder Models
Optimization Overview
Select the code generation optimization settings.
See Also
13-20
PLC Coder: Optimization
Settings
Default: on
On
Simulink PLC Coder software reuses memory buffers allocated to store block input
and output signals, reducing the memory requirement of your real-time program.
Off
Simulink PLC Coder software allocates a separate memory buffer for each block's
outputs. This allocation makes block outputs global and unique, which in many cases
significantly increases RAM and ROM usage.
Tips
Command-Line Information
Parameter:PLC_PLCEnableVarReuse
Type: string
Value: 'on' | 'off'
Default: 'on'
13-21
13 Configuration Parameters for Simulink PLC Coder Models
See Also
13-22
PLC Coder: Optimization
Settings
Default: on
On
Simulink PLC Coder software removes code from floating-point to integer
conversions.
Off
Simulink PLC Coder software does not remove code from floating-point to integer
conversions.
Tips
Command-Line Information
Parameter: PLC_PLCEnableEfficientCast
Type: string
Value: 'on' | 'off'
Default: 'on'
See Also
13-23
13 Configuration Parameters for Simulink PLC Coder Models
This option is available on the PLC Code Generation > Optimization node in the
Configuration Parameters window.
Settings
Default: off
On
Simulink PLC Coder software generates better reusable code for reusable
subsystems.
Off
Simulink PLC Coder software reverts to its default behavior. Instead of a single
reusable function block, the software might generate separate function blocks for
individual instances of a reusable subsystem because of certain differences in their
inputs.
Tips
• If you find multiple function blocks in your generated code for multiple instances of
the same subsystem, select this option. The software performs better identification
of whether two instances of a subsystem are actually the same and might be able to
combine the multiple blocks into one reusable function block.
• If different instances of a subsystem have different values of a block parameter, you
cannot generate reusable code. Disable this option or use the same block parameter
for all instances.
• Despite enabling this option, if you do not see reusable code for different instances of
a subsystem, you can determine the reason. To determine if two reusable subsystems
are identical, the code generator internally uses a checksum value. You can compare
the checksum values for two instances of a subsystem and investigate why they are
not identical.
13-24
PLC Coder: Optimization
Command-Line Information
Parameter:PLC_GenerateReusableCode
Type: string
Value: 'on' | 'off'
Default: 'off'
See Also
13-25
13 Configuration Parameters for Simulink PLC Coder Models
Settings
Default: 5
Specify the array size at which the code generator begins to use a for loop instead of
separate assignment statements to assign values to the elements of a signal or parameter
array.
When there are perfectly nested loops, the code generator uses a for loop if the product
of the loop counts for all loops in the perfect loop nest is greater than or equal to the
threshold.
Command-Line Information
Parameter: PLC_RollThreshold
Type: string
Value: any valid value
Default: '5'
See Also
13-26
PLC Coder: Symbols
In this section...
“Symbols Overview” on page 13-29
“Maximum Identifier Length” on page 13-30
“Use the Same Reserved Names as Simulation Target” on page 13-31
“Reserved Names” on page 13-32
“Externally Defined Symbols” on page 13-33
13-27
13 Configuration Parameters for Simulink PLC Coder Models
In this section...
“Preserve Alias Type Names for Data Types” on page 13-33
13-28
PLC Coder: Symbols
Symbols Overview
Select the automatically generated identifier naming rules.
See Also
13-29
13 Configuration Parameters for Simulink PLC Coder Models
Settings
Default: 31
Minimum: 31
Maximum: 256
You can use this parameter to limit the number of characters in function, type definition,
and variable names. Many target IDEs have their own restrictions. The Simulink PLC
Coder software complies with target IDE limitations.
Command-Line Information
Parameter: PLC_RTWMaxIdLength
Type: int
Value: 31 to 256
Default: 31
See Also
13-30
PLC Coder: Symbols
Settings
Default: off
On
Enables using the same reserved names as those specified in the Simulation Target
> Symbols pane pane.
Off
Disables using the same reserved names as those specified in the Simulation
Target > Symbols pane pane.
Command-Line Information
Parameter: PLC_RTWUseSimReservedNames
Type: string
Value: 'on' | 'off'
Default: 'off'
See Also
13-31
13 Configuration Parameters for Simulink PLC Coder Models
Reserved Names
Enter the names of variables or functions in the generated code that you do not want to
be used. This option is available on the PLC Code Generation > Symbols node in the
Configuration Parameters window.
Settings
Default: ( )
This action changes the names of variables or functions in the generated code to avoid
name conflicts with identifiers in custom code. Reserved names must be shorter than 256
characters.
Tips
Command-Line Information
Parameter: PLC_RTWReservedNames
Type: string
Value: string
Default: ''
See Also
13-32
PLC Coder: Symbols
Settings
Default: ( )
This action suppresses the definition of identifiers, such as those for function blocks,
variables, constants, and user types in the generated code. This suppression allows the
generated code to refer to these identifiers. When you import the generated code into the
PLC IDE, you must provide these definitions.
Tips
Command-Line Information
Parameter: PLC_ExternalDefinedNames
Type: string
Value: string
Default: ''
See Also
13-33
13 Configuration Parameters for Simulink PLC Coder Models
Using the Simulink.AliasType class, you can create an alias for a built-in Simulink
data type. If you assign an alias data type to signals and parameters in your model,
when you use this option, the generated code uses your alias data type to define variables
corresponding to the signals and parameters.
For instance, you can create an alias SAFEBOOL from the base data type boolean. If
you assign the type SAFEBOOL to signals and parameters in your model, the variables
in the generated code corresponding to those signals and parameters also have the
type SAFEBOOL. Using this alias type SAFEBOOL, you can conform to PLCOpen safety
specifications that suggest using safe data types for differentiation between safety-
relevant and standard signals.
Settings
Default: off
On
The generated code preserves alias data types from your model.
For your generated code to be successfully imported to your target IDE, the IDE must
support your alias names.
Off
The generated code does not preserve alias types from your model. Instead, the
base type of the Simulink.AliasType class determines the variable data type in
generated code.
Tips
The alias you define for a Simulink type must have the same semantic meaning as the
base Simulink type. It must not be a data type already supported in Structured Text
and semantically different from the base Simulink type. For instance, WORD is a data
type supported in Structured Text but is semantically different from an integer type.
If you define an alias WORD for a Simulink built-in integer type, for instance uint16,
and preserve the alias name, the type WORD that appears in your generated code is used
semantically as a WORD and not as an INT. The generated code has a different meaning
from that of the model.
Command-Line Information
Parameter: PLC_PreserveAliasType
Type: string
13-34
PLC Coder: Symbols
13-35
13 Configuration Parameters for Simulink PLC Coder Models
In this section...
“Report Overview” on page 13-37
“Generate Traceability Report” on page 13-37
“Generate Model Web View” on page 13-38
13-36
PLC Coder: Report
Report Overview
Specify whether a report must be produced, following code generation. Control the
appearance and contents of the report.
The code generation report shows a mapping between Simulink model objects and
locations in the generated code. The report also shows static code metrics about files,
global variables, and function blocks.
See Also
Settings
Default: off
On
Creates code generation report as HTML file.
Off
Suppresses creation of code generation report.
Command-Line Information
Parameter: PLC_GenerateReport
Type: string
Value: 'on' | 'off'
Default: 'off'
See Also
13-37
13 Configuration Parameters for Simulink PLC Coder Models
You can share your model and generated code outside of the MATLAB environment.
You need a Simulink Report Generator license to include a web View (Simulink Report
Generator) of the model in the code generation report.
Settings
Default: Off
On
Include model Web view in the code generation report.
Off
Omit model Web view in the code generation report.
Command-Line Information
Parameter: PLC_GenerateWebView
Type: string
Value: 'on' | 'off'
Default: 'off'
See Also
13-38