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.
Note: 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.
Open model
slrt_ex_osc
.Connect to the target computer. On the Real-Time tab, toggle the Disconnected indicator to Connected.
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.
From the Simulation block diagram, double-click the block labeled Gain1
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.
To stop the simulation, click Stop.
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
.
Open model slrt_ex_osc
. in the MATLAB Command Window, type:
openExample('slrealtime/SlrtAddIOBlocksToSimulinkModelExample'); open_system('slrt_ex_osc');
In the Simulink® Editor, on the Real-Time tab, click Run on Target.
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.
On the Real-Time tab, click Prepare > Signal Table.
In the Model Data Editor, click the Parameters tab. Modify parameters values in the Model Data Editor in the base workspace.
Click Prepare > Update All Parameters.
To stop the simulation before it ends, click Stop.