Main Content

Tunable Block Parameters and Tunable Global Parameters

To change the behavior of a real-time application, you can tune Simulink® Real-Time™ tunable parameters. In Simulink external mode, you can change the parameters directly in the block or indirectly by using MATLAB® variables to create tunable global parameters. Simulink Real-Time Explorer and the MATLAB language enable you to change parameter values and MATLAB variables as your real-time application is executing.

Note

Simulink Real-Time does not support parameters of multiword data types.

Tunable Parameters

Simulink Coder™ defines two kinds of parameters that can be modified during execution: tunable block parameters and tunable global parameters. Simulink Real-Time support for tunable parameters includes:

  • Variables for block parameters that are present in the top model workspace or MATLAB base workspace. These variables are tunable global parameters.

  • Literal expressions for block parameters that are present in the top model workspace or data dictionary. These expressions are tunable block parameters.

  • Instance-specific block parameters that are present in referenced models. These parameters are tunable global parameters.

Tunable Block Parameters

A tunable block parameter is a literal expression in the top model workspace or data dictionary that you reference in a Simulink block dialog box.

Suppose that you assign the value 5/2 to the Amplitude parameter of a Signal Generator block. Amplitude is a tunable parameter.

Tunable Global Parameter

A tunable global parameter is a variable in the top model workspace or MATLAB base workspace that you reference in a Simulink block dialog box. Suppose that you enter A in the Amplitude parameter of a Signal Generator block. Variable A is a tunable parameter. You can tune the values of MATLAB variables that are grouped in a parameter structure. For example:

  1. Assign a parameter structure that contains the field Ampl to variable A.

  2. Enter A.Ampl in the Amplitude parameter of a Signal Generator block.

  3. Change the amplitude of the signal generator by tuning the value of A.Ampl in the MATLAB workspace during simulation.

Tunable Global Parameters from Referenced Models

There are some limitations on tuning parameters in referenced models. For more information about using instance-specific block parameters and using model arguments to configure these, see:

Inlined Parameters

To optimize execution efficiency, you can change the Default parameter behavior option from Tunable to Inlined on the Code Generation > Optimization pane.

You cannot tune inlined block parameters. You can define a tunable global parameter or Simulink.Parameter object, enter it in the parameter field in the block dialog box, and tune the MATLAB variable or object.

For more information about inlined parameters, see Default parameter behavior.

Tune Global Parameters by Using External Mode

In external mode, Simulink Real-Time connects your Simulink model to your real-time application. The block diagram becomes a user interface for the real-time application.

You can change a block parameter value during execution in the block dialog box. When you click OK, Simulink transfers the new value to the real-time application. For more information, see Tune Parameters by Using Simulink® External Mode.

You can change a tunable global parameter during execution by assigning a new value to the MATLAB workspace. You must then explicitly command Simulink to transfer the data. Do one of the following:

  • Press Ctrl+D.

  • On the Real-Time tab, click Prepare > Signal Table. On the Parameters tab, edit the parameters and click Update Diagram.

Tune Global Parameters by Using Simulink Real-Time Explorer

During real-time execution, Simulink Real-Time Explorer becomes a user interface for the real-time application.

To access a block parameter value, navigate to the block in the Explorer model hierarchy. You can change the value in a text entry box in the parameter window. When you apply the new value, Simulink Real-Time transfers the new value to the real-time application. For more information, see Tune Parameters by Using Simulink® Real-Time™ Explorer.

You can access a tunable global parameter at the top level of the model hierarchy. Change it the same way as you would a tunable block parameter.

You can use Simulink Real-Time Explorer instrument panels to tune block parameters and global parameters.

Tune Global Parameters by Using MATLAB Language

To change the values of tunable block parameters and tunable global parameters during execution, use the Simulink Real-Time command setparam. For more information, see Tune Parameters by Using MATLAB Language.

These code examples use the model slrt_ex_osc. To change a block parameter value, use a nonempty block path and the parameter name. For example, to change the amplitude of the signal generator:

openExample('slrt_ex_osc');
slbuild('slrt_ex_osc');
tg = slrealtime('TargetPC1');
load(tg,'slrt_ex_osc')
start(tg);
setparam(tg, 'Signal Generator', 'Amplitude', 4.57)

To change a tunable global parameter, use the variable name. For example, to change the amplitude of the signal generator via the parameter structure field A.Ampl:

openExample('slrt_ex_osc');
slbuild('slrt_ex_osc');
tg = slrealtime('TargetPC1');
load(tg,'slrt_ex_osc')
start(tg);
setparam(tg, '', 'A.Ampl', 4.57)

See Also

|

Related Topics