This model shows how to map tunable parameters from the Simulink® model to the generated Structured Text code.
This model shows the different implementations of tunable parameters in the generated code. It makes use of three parameters K1, K2, and K3 defined in the MATLAB base workspace. To build the subsystem, right-click on the subsystem block and select PLC Code Generation > Generate Code for Subsystem. The Diagnostic Viewer with hyperlinks to the generated code is displayed automatically.
In this model:
K1 is set to "Auto" storage class
K2 is set to "ExportedGlobal" storage class
K3 is set to "ExportedGlobal" constant storage class
In the generated Structured Text code for compatible IDE targets:
K1 is mapped to a Function Block local variable
K2 is mapped to a global variable
K3 is mapped to a global constant
For the RSLogix 5000 Add On Instruction (AOI) format:
K1 is mapped to an AOI local tag
K2 and K3 are mapped to AOI input tags
For the RSLogix 5000 Routine format:
K1 is mapped to routine instance tag
K2 and K3 are mapped to global program tags
See the Simulink PLC Coder documentation on tunable parameter code generation for more information.
You can generate PLC Structured Text code for this subsystem by right-clicking on the subsystem block and select PLC Code -> Generate Code for Subsystem Alternatively, you can use the following command generatedFiles = plcgeneratecode('plcdemo_tunable_params/SimpleSubsystem');
After the code generation, the Diagnostic Viewer window is displayed with hyperlinks to the generated code files. You can open the generated files by clicking on the links.