|On this page…|
You can use External mode to tune parameters and monitor a model running on your target hardware.
External mode enables you to tune model parameters and evaluate the effects of different parameter values on model results in real time. Doing so helps you find the optimal values to achieve desired performance. This process is called parameter tuning.
External mode accelerates parameter tuning because you do not have to rerun the model each time you change parameters. You can also use External mode to develop and validate your model using the actual data and hardware for which it is designed. This software-hardware interaction is not available solely by simulating a model.
This workflow lists the tasks usually required to tune parameters with External mode:
In the model on your host computer, enable External mode.
Give the Simulink® software command to run the model on the target hardware.
(Optional) Observe the data External mode sends from the target hardware to sink blocks in the model on the host computer.
Change and apply parameter values in the model on your host computer.
Find the optimal parameter values by making adjustments and observing the results.
Save the new parameter values, disable External mode, and save the model.
Note: If you have the Embedded Coder® or Simulink Coder™ software, you can use External mode with a model that contains Model blocks (uses the "Model reference").
Connect the target hardware to your host computer.
Different types of target hardware can use different types of connections. Check the External mode topic for your target hardware to determine which type of connection to use.
On the model toolbar, set Simulation mode to External.
Set the Simulation stop time parameter, located to the left of Simulation mode on the model toolbar. The default value is 10.0 seconds. To run the model for an indefinite period, enter inf.
Click the Run button.
If your model does not contain a sink block, the MATLAB® Command Window displays a warning message. For example:
Warning: No data has been selected for uploading. > In C:\Program Files (x86)\MATLAB\R2013a Student1\toolbox\ realtime\realtime\+realtime\extModeAutoConnect.p> extModeAutoConnect at 17 In C:\Program Files (x86)\MATLAB\R2013a Student1\toolbox\ realtime\realtime\sl_customization.p>myRunCallback at 149
You can disregard this warning or add a sink block to the model.
After several minutes, Simulink starts running your model on the board.
Change parameter values in the model on your host computer.
Observe the corresponding changes in the model running on the hardware.
Any Simulink Sinks blocks in your model receive data from the hardware and display it on your host computer.
To stop the model running in External mode, click the black square Stop button located on the model toolbar, as shown here.
This action stops the process for the model running on the target hardware, and stops the model simulation running on your host computer.
If the Simulation stop time parameter is set to a specific number of seconds, External mode stops when that time elapses.
When you are finished using External mode, set Simulation mode back to Normal.
Using External Mode Control Panel provides additional control of External mode operations, including:
Connect or disconnect the model on the host computer to/from the model running on the target hardware.
Start and stop the model running on the target hardware.
Gather changes to parameter values in a batch before applying them concurrently to the model running on the target hardware.
To open the External Mode Control Panel dialog box, in the model window, select Code > External Mode Control Panel.
The Connect/Disconnect button connects or disconnects the model on your host computer to/from the model running on the target hardware. If the model is not running on the target hardware, clicking Connect automatically deploys and runs the model on the target hardware.
The Start Real-Time Code/Stop Real-Time Code button starts or stops the model running on the target hardware.
Batch download enables you to gather changes before using the Download button to simultaneously apply those changes to the model running on the hardware:
While Batch download is disabled, clicking OK or Apply in a block dialog box sends updated block parameter values from the block to the model running on the target hardware.
When you enable Batch download, clicking OK or Apply in a block dialog box stores updated block parameter values on the host computer. You can complete a set of changes before clicking Download to simultaneously send all of the updated values to the model running on the target hardware. This feature is useful for avoiding error conditions when a model contains blocks whose parameter values must be changed concurrently.
External Mode Control Panel displays "Parameter changes pending..." to the right of the Download button until the model running on the target hardware has applied the new parameter values.