This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

PLC Coder: Optimization

Optimization Overview

Select the code generation optimization settings.

See Also

Generate Structured Text from the Model Window

Default Parameter Behavior

Transform numeric block parameters into constant inlined values in the generated code. This option is available on the PLC Code Generation > Optimization pane in the Configuration Parameters dialog box.

Description

Transform numeric block parameters into constant inlined values in the generated code.

Category: Optimization

Settings

Default: Tunable for GRT targets | Inlined for ERT targets

Inlined

Set Default parameter behavior to Inlined to reduce global RAM usage and increase efficiency of the generated code. The code does not allocate memory to represent numeric block parameters such as the Gain parameter of a Gain block. Instead, the code inlines the literal numeric values of these block parameters.

Tunable

Set Default parameter behavior to Tunable to enable tunability of numeric block parameters in the generated code. The code represents numeric block parameters and variables that use the storage class Auto, including numeric MATLAB® variables, as tunable fields of a global parameters structure.

Tips

  • Whether you set Default parameter behavior to Inlined or to Tunable, create parameter data objects to preserve tunability for block parameters. For more information, see Create Tunable Calibration Parameter in the Generated Code (Simulink Coder).

  • When you switch from a system target file that is not ERT-based to one that is ERT-based, Default parameter behavior sets to Inlined by default. However, you can change the setting of Default parameter behavior later.

  • When a top model uses referenced models, or if a model is referenced by another model:

    • All referenced models must set Default parameter behavior to Inlined if the top model has Default parameter behavior set to Inlined.

    • The top model can specify Default parameter behavior as Tunable or Inlined.

  • If your model contains an Environment Controller block, you can suppress code generation for the branch connected to the Sim port if you set Default parameter behavior to Inlined and the branch does not contain external signals.

Command-Line Information

Parameter:PLC_PLCEnableVarReuse
Type: string
Value: 'on' | 'off'
Default: 'on'

See Also

Generate Structured Text from the Model Window

Signal Storage Reuse

Reuse signal memory. This option is available on the PLC Code Generation > Optimization pane in the Configuration Parameters dialog box.

Settings

Default: on

On

Reuses memory buffers allocated to store block input and output signals, reducing the memory requirement of your real-time program.

Off

Allocates a separate memory buffer for each block's outputs. This allocation makes block outputs global and unique, which in many cases significantly increases RAM and ROM usage.

Tips

  • This option applies only to signals with storage class Auto.

  • Signal storage reuse can occur among only signals that have the same data type.

  • Clearing this option can substantially increase the amount of memory required to simulate large models.

  • Clear this option if you want to:

    • Debug a C-MEX S-function.

    • Use a Floating Scope or a Display block with the Floating display option selected to inspect signals in a model that you are debugging.

  • If you select Signal storage reuse and attempt to use a Floating Scope or floating Display block to display a signal whose buffer has been reused, an error dialog box opens.

Command-Line Information

Parameter:PLC_PLCEnableVarReuse
Type: string
Value: 'on' | 'off'
Default: 'on'

See Also

Generate Structured Text from the Model Window

Remove Code from Floating-Point to Integer Conversions That Wraps Out-Of-Range Values

Enable code removal for efficient casts. This option is available on the PLC Code Generation > Optimization pane in the Configuration Parameters dialog box.

Settings

Default: on

On

Removes code from floating-point to integer conversions.

Off

Does not remove code from floating-point to integer conversions.

Tips

Use this parameter to optimize code generation.

Command-Line Information

Parameter: PLC_PLCEnableEfficientCast
Type: string
Value: 'on' | 'off'
Default: 'on'

See Also

Generate Structured Text from the Model Window

Generate Reusable Code

Using this option, you can generate better reusable code for reusable subsystems. For instance, if your model contains multiple instances of the same subsystem and some instances have constant inputs, by default, the generated code contains separate function blocks for each instance. If you select this option, the software does not consider whether the inputs to the subsystem are constant and generates one function block for the multiple instances.

This option is available on the PLC Code Generation > Optimization pane in the Configuration Parameters dialog box.

Settings

Default: off

On

Generates better reusable code for reusable subsystems.

Off

Reverts to its default behavior. Instead of a single reusable function block, the software generates separate function blocks for individual instances of a reusable subsystem because of certain differences in their inputs.

Tips

  • If you find multiple function blocks in your generated code for multiple instances of the same subsystem, select this option. The software performs better identification of whether two instances of a subsystem are actually the same and whether it can combine the multiple blocks into one reusable function block.

  • If different instances of a subsystem have different values of a block parameter, you cannot generate reusable code. Clear this option or use the same block parameter for all instances.

  • Despite selecting this option, if you do not see reusable code for different instances of a subsystem, you can determine the reason. To determine if two reusable subsystems are identical, the code generator internally uses a checksum value. You can compare the checksum values for two instances of a subsystem and investigate why they are not identical.

    To get the checksum values for the two instances that you expect to be identical, use the function Simulink.SubSystem.getChecksum. If the checksum values are different, investigate the checksum details to see why the values are not identical.

Command-Line Information

Parameter:PLC_GenerateReusableCode
Type: string
Value: 'on' | 'off'
Default: 'off'

See Also

Inline Named Constants

Using this option, you can control inlining of global named constants. By default, the generated code contains named ssMethodType constants for internal states or other Simulink® semantics. If you select this option, the software replaces the named constants with its integer value.

This option is available on the PLC Code Generation > Optimization pane in the Configuration Parameters dialog box.

Settings

Default: off

On

Inlines named constants.

Off

Reverts to its default behavior and uses named constants in the generated code.

Command-Line Information

Parameter:PLC_InlineNamedConstant
Type: string
Value: 'on' | 'off'
Default: 'off'

See Also

Reuse MATLAB Function Block Variables

You can use this option to enable reuse of MATLAB function block variables in the generated code.

This option is available on the PLC Code Generation > Optimization pane in the Configuration Parameters dialog box.

Settings

Default: off

On

Generates code that reuses MATLAB Function block variables where appropriate.

Off

Reverts to its default behavior and does not reuse variables in the generated code.

Command-Line Information

Parameter:PLC_ReuseMLFcnVariable
Type: string
Value: 'on' | 'off'
Default: 'off'

See Also

Loop Unrolling Threshold

Specify the minimum signal or parameter width for which a for loop is generated. This option is available on the PLC Code Generation > Optimization pane in the Configuration Parameters dialog box.

Settings

Default: 5

Specify the array size at which the code generator begins to use a for loop instead of separate assignment statements to assign values to the elements of a signal or parameter array.

When the loops are perfectly nested loops, the code generator uses a for loop if the product of the loop counts for all loops in the perfect loop nest is greater than or equal to this threshold.

Command-Line Information

Parameter: PLC_RollThreshold
Type: string
Value: any valid value
Default: '5'

See Also

Generate Structured Text from the Model Window