Main Content

Simulate and Generate Structured Text Code for a Stateflow® Chart

This example shows how to simulate and generate code for the ControlModule stateflow chart from the plcdemo_stateflow_controller model.

Open the Model


To start the simulation, click Run.

Generate Code

To generate code for the ControlModule chart, use plcgeneratecode. For more information, see plcgeneratecode:

generatedfiles = plcgeneratecode('plcdemo_stateflow_controller/ControlModule');

The plcdemo_stateflow_controller consists of stateflow charts to simulate a drive module. The TestHarness chart provides a test scenatio of starting, holding, and resetting the drive.


The BehaviorModel chart provides a simple chart to test the ControlModule chart behavior by injecting faults.


The ControlModule chart performs the drive control logic.