Simulink® PLC Coder™ User's Guide
Simulink® PLC Coder™ User's Guide
User’s Guide
R2014a
How to Contact MathWorks
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
508-647-7000 (Phone)
508-647-7001 (Fax)
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
March 2010 Online only New for Version 1.0 (Release 2010a)
September 2010 Online only Revised for Version 1.1 (Release 2010b)
April 2011 Online only Revised for Version 1.2 (Release 2011a)
September 2011 Online only Revised for Version 1.2.1 (Release 2011b)
March 2012 Online only Revised for Version 1.3 (Release 2012a)
September 2012 Online only Revised for Version 1.4 (Release 2012b)
March 2013 Online only Revised for Version 1.5 (Release 2013a)
September 2013 Online only Revised for Version 1.6 (Release 2013b)
March 2014 Online only Revised for Version 1.7 (Release 2014a)
Contents
Getting Started
1
Simulink PLC Coder Product Description . . . . . . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
v
Import Structured Text Code Automatically . . . . . . . . . 1-28
PLC IDEs That Qualify for Importing Code
Automatically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-28
Generate and Automatically Import Structured Text
Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-29
Troubleshoot Automatic Import Issues . . . . . . . . . . . . . . . . 1-30
vi Contents
Generated Code Structure for Multirate Models . . . . . . 2-13
vii
Generate a Traceability Report from Configuration
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Keep the Report Current . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6
Trace from Code to Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7
Trace from Model to Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8
Model Web View in Code Generation Report . . . . . . . . . . . 4-10
Generate a Static Code Metrics Report . . . . . . . . . . . . . . . . 4-13
Generate a Traceability Report from the Command Line . . 4-15
viii Contents
Controlling Generated Code Partitions
6
Function Block Partitioning Guidelines . . . . . . . . . . . . . 6-2
IDE-Specific Considerations
8
Rockwell Automation RSLogix Considerations . . . . . . . 8-2
Add-On Instruction and Function Blocks . . . . . . . . . . . . . . 8-2
Double-Precision Data Types . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Unsigned Integer Data Types . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Unsigned Fixed-Point Data Types . . . . . . . . . . . . . . . . . . . . 8-2
ix
Enumerated Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
Limitations
10
Coder Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Current Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Fixed-Point Data Type Limitations . . . . . . . . . . . . . . . . . . . 10-3
Permanent Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-5
x Contents
Functions — Alphabetical List
11
xi
xii Contents
1
Getting Started
Simulink PLC Coder generates test benches that help you verify the
Structured Text using PLC and PAC IDEs and simulation tools. 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
• Simulink support, including reusable subsystems, PID controller blocks,
and lookup tables
• Stateflow support, including graphical functions, truth tables, and state
machines
• Embedded MATLAB support, including if-else statements, loop constructs,
and math operations
• Support for multiple data types, including Boolean, integer, enumerated,
and floating-point, as well as vectors, matrices, buses, and tunable
parameters
• IDE support, including B&R Automation Studio®, PLCopen, Rockwell
Automation® RSLogix™ 5000, Siemens® SIMATIC® STEP® 7, and Smart
Software Solutions CoDeSys
• Test bench creation
1-2
PLC Code Generation in the Development Process
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.
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
1-3
1 Getting Started
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.
System Requirements
For a list of related products, see System Requirements at the MathWorks®
website.
1-4
View Supported Blocks Library
1-5
1 Getting Started
For a list of supported IDEs and platforms, see Supported IDEs at the
MathWorks website.
1-6
PLC Code Generation Workflow
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.
5 Select a solver.
7 Check that the model is compatible with the Simulink PLC Coder software.
1-7
1 Getting Started
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. On the Solver Options pane, select
fixed step. Select SingleTasking for tasking mode for periodic sample times.
Solvers
Choose a solver for your Simulink PLC Coder model.
1-8
Prepare Model for Structured Text Generation
4 Place the components for which you want to generate Structured Text
code in a subsystem.
1-9
1 Getting Started
6 In the top-level model, right-click the Subsystem block and select Block
Parameters (Subsystem).
1-10
Prepare Model for Structured Text Generation
1-11
1 Getting Started
8 Click OK.
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-12
Prepare Model for Structured Text Generation
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 verifies that your model satisfies the Simulink PLC Coder
criteria and displays an information window when done.
1-13
1 Getting Started
1-14
Prepare Model for Structured Text Generation
This command opens the block parameter dialog box so that you can select
the Treat as atomic unit check box.
You are now ready to generate Structured Text code for your IDE. See
“Generate and Examine Structured Text Code” on page 1-16.
1-15
1 Getting Started
2 Right-click the Subsystem block and select PLC Code > Options.
1-16
Generate and Examine Structured Text Code
3 In PLC Code > General options > Target IDE, select a target IDE.
For example, select CoDeSys 2.3.
4 Click Apply.
1-17
1 Getting Started
This button:
• 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.
The Simulink PLC Coder software generates Structured Text code and stores
it according to the target IDE platform. These platform-specific paths are
default locations for the generated code. To customize generated file names,
see “Specify Custom Names for Generated Files” on page 1-23.
1-18
Generate and Examine Structured Text Code
1-19
1 Getting Started
The example in this topic 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
For a description of how the generated code for the Simulink components
map to Structured Text components, see “Simulink® PLC Coder™ Mapping
Semantics” on page 2-2.
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-28.
1-21
1 Getting Started
plcdemo_simple_subsystem
plcopenconfigset('plcdemo_simple_subsystem/SimpleSubsystem')
generatedfiles = plcgeneratecode('plcdemo_simple_subsystem/SimpleSubsystem')
• You must have already generated code for the Siemens SIMATIC STEP 7
target IDE. If you have not yet done so, see “Generate Structured Text from
the Model Window” on page 1-16.
• You must have a Siemens SIMATIC STEP 7 project into which you want to
integrate the generated code.
2 In the browser window, navigate to the folder that contains the Simulink
PLC Coder generated code you want to integrate.
1-22
Generate and Examine Structured Text Code
7 Click OK.
8 In the SCL editor window, compile the model_name.scl file for the
Subsystem block.
The new Function Block is now integrated and available for use with the
existing Siemens SIMATIC STEP 7 project.
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.
1-23
1 Getting Started
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.
3 In the General tab, navigate to the Description section and enter the text
that you want to propagate and save the changes.
5 Generate code for the model as usual and observe that the comments have
propagated to the generated code.
1-24
Generate and Examine Structured Text Code
For Rockwell Automation RSLogix 5000 AOI/routine target IDEs, the coder
also generates the subsystem block description text as an AOI or routine
description L5X XML tag. The IDE can then import the tag as part of AOI
and routine definition in the generated code.
3 In the top level subsystem of the model, right-click the output line and
select Properties.
1-25
1 Getting Started
4 On the Logging and accessibility tab, click the Test point check box.
1-26
Generate and Examine Structured Text Code
5 Click OK.
For more information on signals with test points, see “What Is a Test Point?”.
1-27
1 Getting Started
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
Automatically” on page 3-10.
1-28
Import Structured Text Code Automatically
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 12-6.
3 Right-click the Subsystem block and select PLC Code > Generate and
Import Code for Subsystem.
The software:
a Generates the code.
If you want to generate, import, and run the Structured Text code, see “Import
and Verify Structured Text Code Automatically” on page 3-10.
1-29
1 Getting Started
1-30
Import Structured Text Code Automatically
• 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.
• 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-31
1 Getting Started
Before you start, make sure that you have a Stateflow license. The coder
supports absolute time temporal logic constructs that you specify in Stateflow
charts.
When the Simulink PLC Coder product generates code for a model that
uses absolute time temporal logic, it generates calls to this block.
3 Create your Simulink model using Stateflow charts for temporal logic
constructs.
4 Generate PLC code from your model and integrate it with the
PLC_CODER_TIMER function block in your IDE.
1-32
Integrate Absolute Time Temporal Logic Code
1-33
1 Getting Started
2 The PLC_CODER_TIMER function block is a template. Define the code for the
timer logic. Modify the function block by inserting the IDE-specific code
for RESET, BEFORE, and AFTER timer instructions.
1-34
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).
Replace this subsystem with your own
controller subsystem.
Command Profile Contains a utility subsystem in which the
coder calculates the position data based on
the parameters of the motion instructions
MAM command.
1-35
1 Getting Started
Subsystem Description
Drive Model Contains a minimalistic drive model.
Replace this subsystem with your own drive
model subsystem.
Drive Status Contains a utility subsystem that reads
drive status and returns that status to the
Controller subsystem.
Typically, you do not need to modify or
replace this subsystem.
3 In the template, replace the Drive Model subsystem with your drive (plant)
model.
1-36
Simulation and Code Generation of Motion Instructions
6 Generate code for the example model. To view the code in HTML
format, 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-37
1 Getting Started
MAM
• MAM
• MAFR
• MSO
1-38
Simulation and Code Generation of Motion Instructions
Rockwell Automation RSLogix 5000 IDE. For these UDTs, the example
defines only the fields used in the ExampleController chart of the
plcdemo_motion_control example. When you generate code, the coder
maps the bus data types to the motion instruction UDTs. If your controller
subsystem uses other fields of motion instruction UDTs, you must add
them to the definition of the corresponding Simulink bus data types. The
/toolbox/plccoder/plccoderdemos/PLCMotionType.mat file contains the
definitions of the Simulink bus data types. You can add more fields to these
definitions as required by your controller.
1-39
1 Getting Started
1-40
2
Mapping Simulink
Semantics to Structured
Text
2-2
Generated Code Structure for Simple Simulink® Subsystems
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
Note The coder maps alias data types to the base data type in the
generated code.
2-3
2 Mapping Simulink® Semantics to Structured Text
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.
2-4
Generated Code Structure for Reusable Subsystems
The example in this topic shows generated code for the CoDeSys Version 2.3
IDE. Generated code for other IDE platforms looks different.
2 Right-click the Subsystem 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_reusable_subsystem.exp.
2-5
2 Mapping Simulink® Semantics to Structured Text
Instance variables
Instance invocations (call sites)
Reused code in
FUNCTION_BLOCK
Look for two instance variables that correspond to the two instances
declared inside the parent FUNCTION_BLOCK ReusableSubsystem
(_instance_ReusableSubsystem_S1_1: ReusableSubsystem_S1 and
_instance_ReusableSubsystem_S1_0: ReusableSubsystem_S1). The
code invokes these two instances separately by passing in different inputs.
The code invokes the outputs per the Simulink execution semantics.
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.
2-7
2 Mapping Simulink® Semantics to Structured Text
Generated code
2-8
Generated Code Structure for Stateflow® Charts
The example in this topic shows generated code for the CoDeSys Version 2.3
PLC IDE. Generated code for other IDE platforms looks different.
2 Right-click the ControlModule chart and select PLC Code > Generate
Code for Subsystem.
2-9
2 Mapping Simulink® Semantics to Structured Text
The Simulink PLC Coder software aggressively inlines the generated code
for the Stateflow chart. The coder performs this inlining because different
functions from Stateflow charts share some global state data. However,
function blocks in Structured Text code do not share state data. As a result,
the coder software cannot map these functions onto separate function blocks.
Instead, it must inline these functions.
2-10
Generated Code Structure for MATLAB Function Block
The example in this topic shows generated code for the CoDeSys Version 2.3
IDE. Generated code for other IDE platforms looks different.
2 Right-click the TankControl 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_eml_tankcontrol.exp.
2-11
2 Mapping Simulink® Semantics to Structured Text
MATLAB code
Generated code
for MATLAB
subfunctions
2-12
Generated Code Structure for Multirate Models
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.
VAR_GLOBAL
plc_ts_counter1: DINT;
END_VAR
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:
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.
2-13
2 Mapping Simulink® Semantics to Structured Text
SS_STEP:
(* 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;
2-14
Generated Code Structure for Multirate Models
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-15
2 Mapping Simulink® Semantics to Structured Text
2-16
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-17
2 Mapping Simulink® Semantics to Structured Text
2-18
Generated Code Structure for Subsystem Mask Parameters
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
2-19
2 Mapping Simulink® Semantics to Structured Text
SS_INITIALIZE:
(* InitializeConditions for Atomic SubSystem: '<S1>/Filt1' *)
2-20
Generated Code Structure for Subsystem Mask Parameters
rtp_InitialValue := 4.0,
rtp_Filt1_Order_Enable := TRUE);
Out2 := i1_Filt1.Out;
2-21
2 Mapping Simulink® Semantics to Structured Text
For example, suppose your model has a global array variable, ParArrayXLUT:
ParArrayXLUT=[0,2,6,10];
2-22
3
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.
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:
3-2
Generated Files
Generated Files
Depending on the target IDE platform, the Simulink PLC Coder software
generates code into one or more files. See “Generate Structured Text from
the Model Window” on page 1-16 for list of the target IDE platforms and
the possible generated files.
3-3
3 Generating Test Bench Code
For non top-level subsystems, in the generated code, the subsystem function
block prototype has one of the following formats:
3-4
Integrate Generated Code into Custom Code
3-5
3 Generating Test Bench Code
Check that you have connected the inputs and outputs of the subsystem
for which you want to generate the test bench. You can import this test
bench with the generated code to the target IDE to verify that the output is
functionally and numerically equivalent to the output from the execution
of a Simulink model.
3-6
Generate and Manually Import Test Bench Code
Right-click the Subsystem block and select PLC Code > Options.
In PLC Code > General options > Target IDE, select your target IDE,
for example, CoDeSys 2.3.
Click Apply.
3-7
3 Generating Test Bench Code
This button:
• Generates Structured Text code (same as the PLC Code > Generate
Code for Subsystem option)
• Generates the test bench for code through Simulink simulation
• Combines the generated code and test bench into model_name.exp (for
example, plcdemo_simple_subsystem.exp)
When the code generation is complete, an information window is displayed.
Click OK.
3-8
Generate and Manually Import Test Bench Code
The Simulink PLC Coder software generates Structured Text code and writes
it to current_folder/plcsrc/plcdemo_simple_subsystem.exp. Depending
on the target IDE, the coder might generate additional supporting files.
bdclose(sys)
See the user manual for your target IDE for information on how to import
generated code into the target IDE.
3-9
3 Generating Test Bench Code
These topics assume that you have read “Import Structured Text Code
Automatically” on page 1-28. If you have not yet done so, read that topic first.
It also assumes that you are confident that your model produces Structured
Text that does not require visual examination.
If you do not want to run and verify the generated code and want only to
import it, see “Generate and Automatically Import Structured Text Code”
on page 1-29.
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.
b In the Project Path field, type or select a path to which you have write
privileges.
c Click Next.
3-10
Import and Verify Structured Text Code Automatically
d In the remaining wizard dialog boxes, click Next to leave the default
selections. At the end of the wizard, click Finish.
• Logical POUs
• Physical Hardware
5 Check that the project tree has only top-level nodes for Libraries, Data
Types, Logical POUs, and Physical Hardware. There should be no
subtree nodes.
8 Click OK.
When you are ready, open your model, right-click the Subsystem block, and
select one of the following:
The coder:
4 Imports the generated code and test bench in XML file to the IDE.
5 If you selected PLC Code > Generate, Import, and Verify Code for
Subsystem, the IDE also runs the generated code to verify it.
3-11
3 Generating Test Bench Code
The following procedure assumes that you have installed your target PLC
IDE in a default location. 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 12-6 for more details.
2 Right-click the Subsystem block and select PLC Code > Generate,
Import, and Verify Code for Subsystem.
d Imports the generated code and test bench to the new project in the
target IDE.
e On the target IDE, runs the generated code to verify it.
3-12
4
In the Configuration Parameters dialog box, in the Report panel, you see
these options.
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
4-2
Information in Code Generation Reports
box or the command line. A typical traceability report looks something like
this figure:
4-3
4 Code Generation Reports
2 Open the Configuration Parameters dialog box and navigate to the PLC
Code Generation pane.
4 Click Apply.
4-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.
4-5
4 Code Generation Reports
For more information on using the report that you generate for tracing, see:
4-6
Create and Use Code Generation Reports
S1/Gain
4-7
4 Code Generation Reports
corresponding block in the model editor window. You can use the same
method to trace other block from the HTML report.
• 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 4-4 or “Generate a
Traceability Report from the Command Line” on page 4-15.
4-8
Create and Use Code Generation Reports
4-9
4 Code Generation Reports
• 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/.
2 Open the Configuration Parameters dialog box and navigate to the Code
Generation pane.
4-10
Create and Use Code Generation Reports
4 To enable model web view, select Report > Generate model Web view.
5 Click Apply.
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.
4-11
4 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 top model’s report
is displayed.
4-12
Create and Use Code Generation Reports
For more information about navigating between the generated code and the
model diagram, see:
• 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”.
1 Open the Configuration Parameters dialog box and navigate to the PLC
Code Generation pane.
4-13
4 Code Generation Reports
3 Click Apply.
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.
4-14
Create and Use Code Generation Reports
open_system('plcdemo_simple_subsystem');
generatedfiles = plcgeneratecode('plcdemo_simple_subsystem/SimpleSubsystem')
4-15
4 Code Generation Reports
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 should familiarize yourself with potential code limitations
of your IDE. For example, some IDE’s might have limits on the number of
variables or lines of code in a function block.
4-16
Working with the Static Code Metrics Report
Report Contents
The Static Code Metrics Report is divided into the following sections:
4-17
4 Code Generation Reports
4-18
5
Tunable Parameters
Block parameters can be either tunable or nontunable. A tunable parameter
is a parameter that you can change while a simulation is running. With the
Simulink PLC Coder software, you can tune parameters:
The coder maps tunable parameters in the generated code as listed in the
following table:
5-2
Tunable Parameters
5-3
5 Working with Tunable Parameters in the Simulink® PLC Coder™ Environment
5-4
Configure Your Model for Tunable Parameters
This table lists the possible tunable parameters and how you can set them
using either Simulink.Parameter or the Configuration Parameters dialog
box. When using Simulink.Parameter, enter the entire command without
hyphens.
5-5
5 Working with Tunable Parameters in the Simulink® PLC Coder™ Environment
5-6
Configure Your Model for Tunable Parameters
5-7
5 Working with Tunable Parameters in the Simulink® PLC Coder™ Environment
Note The coder does not support tuning parameters of bus data type.
2 Select the Sum, Gain, and Unit Delay blocks and create an atomic
subsystem with inputs U, U1, and U2 and outputs Y, Y1, and Y2. Rename
the Subsystem block as SimpleSubystem. When you are finished, the top
model and atomic subsystem model look like the following model:
5-8
Identify Tunable Parameters
4 Double-click SimpleSubsystem.
5-9
5 Working with Tunable Parameters in the Simulink® PLC Coder™ Environment
5 The three Gain blocks have the constants that you want to make tunable:
K1, K2, and K3.
5-10
Identify Tunable Parameters
5-11
5 Working with Tunable Parameters in the Simulink® PLC Coder™ Environment
Note Alternatively, you can use the Model Explorer to create constants as
Simulink.Parameter and define them. For more information, see “Work with
Simulink.Parameter Objects Using Model Explorer” on page 5-15.
5-12
Tune Parameters Using Simulink.Parameter Objects
4 To run the script at model load time, enter the name of the script that you
created, for example, setup_tunable_params.
5-13
5 Working with Tunable Parameters in the Simulink® PLC Coder™ Environment
5 Click Apply.
7 In the Model close function pane, enter the clear command to clear
these constants. For example:
clear K1 K2 K3;
5-14
Tune Parameters Using Simulink.Parameter Objects
When you close the model, this command clears these constants from the
MATLAB workspace.
9 In the MATLAB Command Window, you can change the parameter values
using the Simulink.Parameter.Value field.
10 When you are done, save the model, and generate and inspect the code.
5-15
5 Working with Tunable Parameters in the Simulink® PLC Coder™ Environment
The Contents pane is updated with the contents of the MATLAB base
workspace.
4 In the Dialog pane for the Simulink.Parameter object, edit the Storage
class and Value parameters. Click Apply to save changes.
5 When you are done, save the model, and generate and inspect the code.
For more information about using the Model Explorer to work with data
objects, see “Using the Model Explorer to Create Data Objects”.
5-16
Configure Tunable Parameters Using Configuration Parameters
3 In the Model pre-load function pane, enter the three constants K1, K2,
and K3. Assign initial values to them. For example:
K1 = 0.1;
K2 = 0.2;
K3 = 0.3;
5-17
5 Working with Tunable Parameters in the Simulink® PLC Coder™ Environment
4 Click Apply.
6 In the Model close function pane, enter the clear command to clear
these constants. For example:
clear K1 K2 K3;
5-18
Configure Tunable Parameters Using Configuration Parameters
When you close the model, this command clears these constants from the
MATLAB workspace.
5-19
5 Working with Tunable Parameters in the Simulink® PLC Coder™ Environment
you have not yet done so, see “Defining Tunable Parameter Values in the
MATLAB Workspace” on page 5-17.
You must already be familiar with the tunable parameter properties on the
Global (tunable) parameters pane. For more information, see Setting
Tunable Parameter Properties in the Simulink Coder™ documentation.
4 Click Configure.
5-20
Configure Tunable Parameters Using Configuration Parameters
5 In the Model Parameter Configuration dialog box, from the Source list,
select Referenced workspace variables.
6 Use the Ctrl key to select the parameters and click Add to table >> to add
them to the Global (tunable) parameters table.
5-21
5 Working with Tunable Parameters in the Simulink® PLC Coder™ Environment
You can also optionally set the storage type qualifier for a parameter to
const.
9 Select the Target IDE and Output Directory settings, then click
Generate code.
5-22
Configure Tunable Parameters Using Configuration Parameters
Some target IDEs do not support the access of global variables. In this case,
the Simulink PLC Coder software uses SimulinkGlobal as the automatic
storage class.
5-23
5 Working with Tunable Parameters in the Simulink® PLC Coder™ Environment
16 Observe that K1 does not appear in the VAR section of the generated code.
(Compare to Step 10.)
Note The Simulink PLC Coder software does not support setting the
parameter storage class to ImportedExternPointer. If you set the
parameter to this value, the software treats it the same as ImportedExtern.
5-24
6
• 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.
6-2
One Function Block for Atomic Subsystems
6-3
6 Controlling Generated Code Partitions
6-4
Multiple Function Blocks for Nonvirtual Subsystems
6-5
6 Controlling Generated Code Partitions
• Function packaging
• Function name options
6-6
Control Generated Code Using Subsystem Block Parameters
2 If the Treat as atomic unit check box is not yet selected, select it.
6-7
6 Controlling Generated Code Partitions
6 In the Function name field, specify a custom name. For example, type
my_own_subsystem.
6-8
7
Integrating Externally
Defined Symbols
• 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.
7-2
Integrate Custom Function Block in Generated Code
3 In the MATLAB editor, minimally define inputs, outputs, and stubs. For
example:
function Y = fcn(U,V)
% Stub behavior for simulation. This block
% is replaced during code generation
Y = U + V;
7-3
7 Integrating Externally Defined Symbols
7-4
Integrate Custom Function Block in Generated Code
7-5
7 Integrating Externally Defined Symbols
7-6
8
IDE-Specific Considerations
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.
8-2
Rockwell Automation® RSLogix™ Considerations
limitations for fixed-point data type support, see “Fixed-Point Data Type
Limitations” on page 10-3.
8-3
8 IDE-Specific Considerations
Design your model so that the possible precision loss of numerical results of
the generated code does not change the expected semantics of the model.
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.
8-4
Siemens® SIMATIC® STEP® 7 Considerations
fixed-point data types in the model. For more information about coder
limitations for fixed-point data type support, see “Fixed-Point Data Type
Limitations” on page 10-3.
8-5
8 IDE-Specific Considerations
8-6
9
Inport
Bus Creator
9-2
Supported Simulink® Blocks
Bus Selector
Constant
Demux
Discrete-Time Integrator
Gain
Ground
Logical Operator
Mux
Product
Relational Operator
Saturation
Scope
Subsystem
Inport
Outport
Sum
Switch
Terminator
Unit Delay
9-3
9 Supported Simulink® and Stateflow® Blocks
Discontinuities
Rate Limiter
Relay
Saturation
Saturation Dynamic
Wrap To Zero
Discrete
Difference
Discrete Derivative
Discrete Filter
PID Controller
Discrete State-Space
Discrete-Time Integrator
Integer Delay
9-4
Supported Simulink® Blocks
Memory
Tapped Delay
Unit Delay
Zero-Order Hold
Bit Clear
Bit Set
Bitwise Operator
Compare To Constant
Compare To Zero
Detect Change
Detect Decrease
Detect Increase
9-5
9 Supported Simulink® and Stateflow® Blocks
Extract Bits
Interval Test
Logical Operator
Shift Arithmetic
Lookup Tables
Dynamic-Lookup
PreLookup
Math Operations
Abs
Add
Assignment
Bias
Divide
Dot Product
Gain
Math Function
Matrix Concatenate
9-6
Supported Simulink® Blocks
MinMax
Permute Dimensions
Polynomial
Product
Product of Elements
Reciprocal Sqrt
Reshape
Rounding Function
Sign
Slider Gain
Sqrt
Squeeze
Subtract
Sum
Sum of Elements
Trigonometric Function
Unary Minus
Vector Concatenate
9-7
9 Supported Simulink® and Stateflow® Blocks
Model Verification
Assertion
Model-Wide Utilities
DocBlock
Model Info
Atomic Subsystem
CodeReuse Subsystem
Enabled Subsystem
Enable
9-8
Supported Simulink® Blocks
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
Selector
9-9
9 Supported Simulink® and Stateflow® Blocks
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
9-10
Supported Simulink® Blocks
Fcn
9-11
9 Supported Simulink® and Stateflow® Blocks
Stateflow
Chart
Truth Table
9-12
10
Limitations
Coder Limitations
In this section...
“Current Limitations” on page 10-2
“Fixed-Point Data Type Limitations” on page 10-3
“Permanent Limitations” on page 10-5
Current Limitations
The Simulink PLC Coder software does not support the following Simulink
semantics:
10-2
Coder 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
Properly configure block parameters:
4 For the Output data type parameter, select a fixed-point data type.
10-3
10 Limitations
9 Click OK.
10-4
Coder Limitations
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.
• No blocks that require continuous time semantics. This restriction includes
continuous integrators, zero-crossing blocks, physical modeling blocks,
and so on.
• No pointer data types.
• No recursion (including recursive events).
10-5
10 Limitations
Block Restrictions
In this section...
“Simulink Block Support Exceptions” on page 10-6
“Stateflow Chart Exceptions” on page 10-6
“Reciprocal Sqrt Block” on page 10-7
“Lookup Table Blocks” on page 10-7
1 Open the model and double-click the Stateflow chart that causes the issue.
10-6
Block Restrictions
4 In the Chart dialog box, navigate to the States When Enabling parameter
and select Held.
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-7
10 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 following target IDEs are 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.
10-8
11
Functions — Alphabetical
List
plccoderdemos
Syntax plccoderdemos
plccoderdemos
11-2
plccoderpref
Syntax plccoderpref
plccoderpref('plctargetide')
plccoderpref('plctargetide', preference_value)
plccoderpref('plctargetide', 'default')
plccoderpref('plctargetidepaths')
plccoderpref('plctargetidepaths','default')
Tips Use the Simulink Configuration Parameters dialog box to change the
installation path of a target IDE (Target IDE Path).
Input plctargetide
Arguments String directive that specifies the default target IDE.
11-3
plccoderpref
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
brautomation30 B&R Automation Studio 3.0 target
IDE
twincat211 Beckhoff TwinCAT 2.11 target IDE
multiprog50 KW-Software MULTIPROG 5.0 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
plcopen PLCopen XML target IDE
generic Generic target IDE
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.
11-4
plccoderpref
default
String that sets your preferences to the factory default.
plccoderpref('plctargetide')
plccoderpref('plctargetide', 'rslogix5000')
Assume that you have previously changed the installation path of the
CoDeSys 2.3 target IDE. Return the current target IDE installation
paths.
11-5
plccoderpref
Set the installation path of all target IDEs, including CoDeSys 2.3, to
factory default.
» plccoderpref('plctargetidepaths','default')
ans =
11-6
plcgeneratecode
plcdemo_simple_subsystem
generatedfiles = plcgeneratecode('plcdemo_simple_subsystem/SimpleSubsystem')
11-7
plcopenconfigset
Syntax plcopenconfigset(subsystem)
Examples Open the Configuration Parameters dialog box for the subsystem,
plcdemo_simple_subsystem/SimpleSubsystem.
plcdemo_simple_subsystem
plcopenconfigset('plcdemo_simple_subsystem/SimpleSubsystem')
11-8
12
Configuration Parameters
for Simulink PLC Coder
Models
In this section...
“PLC Coder: General Tab Overview” on page 12-3
“Target IDE” on page 12-4
“Target IDE Path” on page 12-6
“Code Output Directory” on page 12-8
“Generate testbench for subsystem” on page 12-9
12-2
PLC Coder: General
Configuration
To enable the Simulink PLC Coder options pane, you must:
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
“Prepare Model for Structured Text Generation” on page 1-8
12-3
12 Configuration Parameters for Simulink® PLC Coder™ Models
Target IDE
Select the target IDE in which to generate code.
Settings
Default: 3S CoDeSys 2.3
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.
B&R Automation Studio 3.0
Generates Structured Text code for B&R Automation Studio 3.0.
Beckhoff TwinCAT 2.11
Generates Structured Text code for Beckhoff TwinCAT 2.11 software.
KW-Software MULTIPROG 5.0
Generates Structured Text code in PLCopen XML for KW-Software
MULTIPROG 5.0.
Phoenix Contact PC WORX 6.0
Generates Structured Text code in PLCopen XML for Phoenix Contact
PC WORX 6.0.
Rockwell RSLogix 5000: AOI
Generates Structured Text code for Rockwell Automation RSLogix 5000
using Add-On Instruction (AOI) constructs.
Rockwell RSLogix 5000: Routine
Generates Structured Text code for Rockwell Automation RSLogix 5000
routine constructs.
Siemens SIMATIC Step 7 5.4
Generates Structured Text code for Siemens SIMATIC STEP 7 5.4.
Generic
Generates a pure Structured Text file. If the target IDE that you want is
not available for the Simulink PLC Coder product, consider generating
and downloading a generic Structured Text file.
12-4
PLC Coder: General
PLCopen XML
Generates Structured Text code formatted using PLCopen XML
standard.
Tip
Command-Line Information
Parameter: PLC_TargetIDE
Type: string
Value: 'codesys23' | 'codesys33' | 'rslogix5000' |
'rslogix5000_routine' | 'brautomation30' | 'multiprog50' |
'pcworx60' | 'step7' | 'plcopen' | 'twincat211' | 'generic'
Default: 'codesys23'
See Also
“Generate Structured Text from the Model Window” on page 1-16
12-5
12 Configuration Parameters for Simulink® PLC Coder™ Models
Settings
Default: C:\Program Files\3S Software
Tip
• The value of this parameter changes when you change the Target IDE
value.
12-6
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
“Import Structured Text Code Automatically” on page 1-28
12-7
12 Configuration Parameters for Simulink® PLC Coder™ Models
Settings
Default: plcsrc subfolder in your working folder
Command-Line Information
Parameter: PLC_OutputDir
Type: string
Value: string
Default: 'plcsrc'
See Also
“Generate Structured Text from the Model Window” on page 1-16
12-8
PLC Coder: General
Settings
Default: off
On
Enables generation of test bench code for subsystem.
Tips
If you right-click the Subsystem block and choose PLC Code > Generate
and Import Code for Subsystem, the software also generates the test
bench for the subsystem, regardless of the setting of the Generate testbench
for subsystem check box.
Dependency
This parameter is disabled if your model has absolute time temporal logic.
Note The Simulink PLC Coder software supports absolute time temporal
logic in Stateflow charts for the Rockwell Automation RSLogix 5000 IDE.
Command-Line Information
Parameter: PLC_GenerateTestbench
Type: string
Value: 'on' | 'off'
Default: 'off'
See Also
“Generate Structured Text from the Model Window” on page 1-16
12-9
12 Configuration Parameters for Simulink® PLC Coder™ Models
In this section...
“Comments Overview” on page 12-11
“Include comments” on page 12-11
“Include block description” on page 12-12
“Simulink block / Stateflow object comments” on page 12-13
“Show eliminated blocks” on page 12-14
12-10
PLC Coder: Comments
Comments Overview
Control the comments that the Simulink PLC Coder software automatically
creates and inserts into the generated code.
See Also
“Generate Structured Text from the Model Window” on page 1-16
Include comments
Specify which comments are in generated files.
Settings
Default: on
On
Places comments in the generated files based on the selections in the
Auto generated comments pane.
Off
Omits comments from the generated files.
Command-Line Information
Parameter: PLC_RTWGenerateComments
Type: string
Value: 'on' | 'off'
Default: 'on'
See Also
“Generate Structured Text from the Model Window” on page 1-16
12-11
12 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
“Generate Structured Text from the Model Window” on page 1-16
12-12
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
“Generate Structured Text from the Model Window” on page 1-16
12-13
12 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
“Generate Structured Text from the Model Window” on page 1-16
12-14
PLC Coder: Optimization
In this section...
“Optimization Overview” on page 12-15
“Signal storage reuse” on page 12-16
“Remove code from floating-point to integer conversions that wraps
out-of-range values” on page 12-18
“Loop unrolling threshold” on page 12-19
Optimization Overview
Select the code generation optimization settings.
See Also
“Generate Structured Text from the Model Window” on page 1-16
12-15
12 Configuration Parameters for Simulink® PLC Coder™ Models
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
12-16
PLC Coder: Optimization
Type: string
Value: 'on' | 'off'
Default: 'on'
See Also
“Generate Structured Text from the Model Window” on page 1-16
12-17
12 Configuration Parameters for Simulink® PLC Coder™ Models
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
Use this parameter to optimize code generation.
Command-Line Information
Parameter: PLC_PLCEnableEfficientCast
Type: string
Value: 'on' | 'off'
Default: 'on'
See Also
“Generate Structured Text from the Model Window” on page 1-16
12-18
PLC Coder: Optimization
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
“Generate Structured Text from the Model Window” on page 1-16
12-19
12 Configuration Parameters for Simulink® PLC Coder™ Models
In this section...
“Symbols Overview” on page 12-21
“Maximum identifier length” on page 12-22
“Use the same reserved names as Simulation Target” on page 12-23
“Reserved names” on page 12-24
“Externally Defined Symbols” on page 12-25
12-20
PLC Coder: Symbols
Symbols Overview
Select the automatically generated identifier naming rules.
See Also
“Generate Structured Text from the Model Window” on page 1-16
12-21
12 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
“Generate Structured Text from the Model Window” on page 1-16
12-22
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
“Generate Structured Text from the Model Window” on page 1-16
12-23
12 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.
Settings
Default: ( )
Tips
Command-Line Information
Parameter: PLC_RTWReservedNames
Type: string
Value: string
Default: ''
See Also
“Generate Structured Text from the Model Window” on page 1-16
12-24
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
12-25
12 Configuration Parameters for Simulink® PLC Coder™ Models
In this section...
“Generate traceability report” on page 12-26
“Generate model Web view” on page 12-27
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
“Generate Structured Text from the Model Window” on page 1-16
12-26
PLC Coder: 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
“Generate Structured Text from the Model Window” on page 1-16
12-27