Main Content

Prepare Model for Structured Text Generation

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 check box for Treat each discrete rate as a separate task.

Solvers

Choose a solver for your Simulink PLC Coder model.

Model Solver Setting
Variable-stepUse a continuous solver. Configure a fixed sample time for the subsystem for which you generate code.
Fixed-stepUse a discrete fixed-step solver.

Configuring Simulink Models for Structured Text Code Generation

You must already have a model for which you want to generate and import code to a PLC IDE. Before you use this model, perform the following steps.

  1. In the Command Window, open your model.

  2. Configure the model to use the fixed-step discrete solver. Click the solver link in the lower-right corner. The Solver information pane opens. In the pane, click the View solver settings button to open the Solver pane of the model configuration parameters. Under the Solver selection, 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.

    Optionally, rename In1 and Out1 to U and Y respectively. This operation results in a subsystem like the following figure:

  5. Save the model with the new subsystem.

  6. In the top-level model, right-click the Subsystem block and select Block Parameters (Subsystem).

  7. In the resulting block dialog box, select Treat as atomic unit.

  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.

You are now ready to:

Check System Compatibility for Structured Text Code Generation

You must already have a model that you have configured to work with the Simulink PLC Coder software.

  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.

    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.

You are now ready to generate Structured Text code for your IDE. See Generate and Examine Structured Text Code.