Main Content

Generate Structured Text Code For Simulink Data Dictionary Defined Model Parameters

Simulink Data Dictionary (SLDD) is the preferred Model-Based-Design (MBD) data modeling and management tool. SLDD provides advantages such as data separation, logical partitioning, traceability, and so on. To achieve traceability between your generated code and model, and for code reusability and model and data sharing, use SLDD

Learning Objectives

In this tutorial, you learn how to:

  • Open the plcdemo_tunable_params model and migrate the model to use Simulink Data Dictionary (SLDD).

  • Generate code for the model.

Requirements

  • Base workspace variable definition must match the variable definition in the SLDD file. If there is a mismatch, Simulink® PLC Coder™ displays an error during the code generation process.

  • If your model has a Data Store Memory(DSM) object, you must have a matching Simulink.Signal object in the SLDD file.

Workflow

Migrate the plcdemo_tunable_params model base workspace variables to an SLDD file for code generation:

Note

Copy the plcdemo_tunable_params model to your current working directory prior to starting the workflow.

  1. Open the plcdemo_tunable_params model. To open the model, enter:

    openExample('plcdemo_tunable_params');

  2. From the Simulink Editor Modeling tab, click Model Explorer.

  3. Under the Model Hierarchy pane, click Base Workspace . The Contents pane displays the base workspace variables.

  4. Right-click K1, K2, and K3. Choose the Convert to parameter object option to convert them to the Simulink.Parameter type.

  5. Right-click plcdemo_tunable_params, and then select Properties.

  6. Select the External Data tab.

  7. Click New. Enter the file name as plcdemo_tunable_params.

  8. Click the Migrate data button. Then click Apply in response to the Link Model to Data Dictionarymessage and Migrate in response to the Migrate Data message.

  9. Click OK.

  10. To open the dictionary, in the Simulink Editor, click the model data badge in the bottom left corner, then click the External Data link. To inspect the contents of the dictionary, in the Model Explorer Model Hierarchy pane, under the External Data node, expand the dictionary node.

To generate code for the model, see Generate and Examine Structured Text Code.

Related Topics