Main Content

Tune Parameters by Using Simulink External Mode

To connect your Simulink® model to your real-time application, you use Simulink external mode simulation. The model becomes a user interface to your real-time application. Set up the Simulink interface in external mode to establish a communication channel between your Simulink model and your real-time application.

In Simulink external mode, when you change parameters in the Simulink model, Simulink downloads those parameters to the real-time application while it is running. You can change parameters in your program without rebuilding the Simulink model to create a new real-time application.


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

Tune Parameters by Using Block Diagram

After you download your real-time application to the target computer, you can connect your Simulink model to the real-time application. This procedure uses the Simulink model slrt_ex_osc. You must have already built and downloaded the real-time application for that model.

  1. Open model slrt_ex_osc.

  2. Connect to the target computer. On the Real-Time tab, toggle the Disconnected indicator to Connected.

  3. Build and download the real-time application to the target computer. Click Run on Target.

    The real-time application begins running on the target computer.

  4. From the Simulation block diagram, double-click the block labeled Gain1

  5. In the Block Parameters: Gain1 parameter dialog box, in the Gain text box, enter 800. Click OK.

    When you change a MATLAB® variable and click OK, the changed parameters in the model are downloaded to the real-time application.

  6. To stop the simulation, click Stop.

  7. Disconnect to the target computer. Toggle the Connected indicator to Disconnected.

    The Simulink model is disconnected from the real-time application. If you then change a block parameter in the Simulink model, the real-time application does not change.

Tune Parameters by Using Hold Updates and Update All Parameters

By using the Hold Updates button, you can tune multiple parameters and apply the tuning changes at once by using Update All Parameters, instead of tuning one parameter at a time. This example uses model slrt_ex_osc.

  1. Open model slrt_ex_osc. in the MATLAB Command Window, type:

  2. In the Simulink Editor, on the Real-Time tab, click Run on Target.

  3. Click Prepare > Hold Updates. The editor holds parameter updates until you click Hold Updates again.

    To set parameter values, you can set values either by clicking each block or by using the Model Data Editor in the base workspace.

  4. On the Real-Time tab, click Prepare > Signal Table.

  5. In the Model Data Editor, click the Parameters tab. Modify parameters values in the Model Data Editor in the base workspace.

  6. Click Prepare > Update All Parameters.

  7. To stop the simulation before it ends, click Stop.

Related Topics