Note
Ladder diagram generation from Stateflow® charts will be removed in a future release. To generate ladder diagrams, use Simulink® models instead. To create Simulink models compatible with ladder logic generation, do one of the following:
Use the blocks from the PLC Ladder library to create a model that is compatible with
ladder diagram generation. To open the PLC Ladder library, type
plcladderlib
at the MATLAB command prompt.
Import ladder logic from a L5X file with the plcimportladder
function.
To generate ladder logic from the Simulink models, use these functions: plcgeneratecode
and
plcgeneraterunnertb
Ladder Diagram semantics must be represented with switches and relays. Therefore, if you intend to generate a Ladder Diagram from a Stateflow chart, you cannot use some advanced features in your chart. The Stateflow chart must have the following form:
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.
The chart Action Language must be
C
.
Disable the following chart properties:
Enable Super Step Semantics
Execute (enter) Chart At Initialization
Initialize Outputs Every Time Chart Wakes Up
The chart must have at least one input and output. The input and output data must be Boolean.
Each output must correspond to a state in the chart. The output is true if the state is 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 chart must not have data with scope other than input or output.
The chart must not include:
Atomic subcharts
Multiple default transition
Simulink functions
Parallel states
State hierarchy
History junctions
Dangling transitions
Super transitions crossing subchart boundaries
Conditional default paths
Self transitions