xPC Target |
 |
Parameter Tuning with Simulink External Mode
You use Simulink external mode to connect your Simulink block diagram to your target application. The block diagram becomes a graphical user interface to your target application. You set up Simulink in external mode to establish a communication channel between your Simulink block window and your target application.
In Simulink external mode, wherever you change parameters in the Simulink block diagram, Simulink downloads those parameters to the target application while it is running. This feature lets you change parameters in your program without rebuilding the Simulink model to create a new target application.
After you download your target application to the target PC, you can connect your Simulink model to the target application. This procedure uses the Simulink model xpcosc.mdl
as an example, and assumes you have created and downloaded the target application for that model.
- In the Simulink window, and from the Simulation menu, click External.
- A check mark appears next to the menu item External, and Simulink external mode is activated.
- In the Simulink block window, and from the Simulation menu, click Connect to target.
- All of the current Simulink model parameters are downloaded to your target application. This downloading guarantees the consistency of the parameters between the host model and the target application.
The target PC displays the following message where #
is the actual number of tunable parameters in your model.
- From the Simulation menu, click Start real-time code or in the MATLAB Command Window, type either
- The target application begins running on the target PC, and the target PC displays the following message.
- From the Simulation block diagram, click the block labeled Gain1.
- The Block Parameters: Gain1 parameter dialog box opens.

- In the Gain text box, enter
800
, and click OK.
- As soon as you change a model parameter and click OK or the Apply button on the Block Parameters: Gain1 dialog box, all of the changed parameters in the model are downloaded to the target application, as shown below.

- From the Simulation menu, click Disconnect from Target.
- The Simulink model is disconnected from the target application. Now, if you change a block parameter in the Simulink model, there is no effect on the target application. Connecting and disconnecting Simulink works regardless of whether the target application is running or not.
- From the Simulation menu, click Stop real-time code, or in the MATLAB Command Window, type either
- The target application on the target PC stops running, and the target PC displays the following messages.
| Parameter Tuning with MATLAB | | Parameter Tuning with a Web Browser |  |