This example shows how to perform parameter tuning and data logging with a Simulink® model running in External mode on ARM Cortex-based VEX Microcontroller targets.
ARM Cortex-based VEX Microcontroller
USB A-A Cable
The following figure shows the example model.
open_system('vexarmcortex_external_mode'); close_system('vexarmcortex_external_mode/Scope', 0);
In this example, you will learn how to run a Simulink model, tune parameters and log data in External mode.
Set up the hardware
Connect the ARM Cortex-based VEX Microcontroller to the computer using a USB A-A Cable. The connection should automatically enable serial connection between the Microcontroller and the host computer.
Set up the model
1. Open the Example Model. This model has already been configured for External mode. To setup External mode for a new model, follow the steps below.
2. Open Model Configuration Parameters and navigate to the Hardware Implementation pane.
3. Select Hardware board as ARM Cortex-based Vex Microcontroller.
4. Select External from the Simulation mode drop-down list in the Simulink Editor Window and specify a desired value for the stop time. Specify the stop time as 'inf' to run the model continuously on the target hardware.
Run the model in External mode
When running in External mode, the host computer communicates with the target to log data and tune parameters. To run the Example Model in External mode:
1. Press the Run button in the Simulink Editor. Simulink generates the code, loads the executable and connects to the target. View the Diagnostic Viewer to track progress.
2. While the model is running in External mode, open the Scope connected to the Gain block to monitor its output.
3. Press the Stop button in the Simulink Editor to terminate the External mode simulation.
Simulink External mode provides parameter tuning while the generated executable is running on the target hardware. When the parameter values are changed in the Simulink model, the modified values are communicated to the target hardware immediately.
To tune parameters in External mode:
1. Run the model in External mode.
2. While the model is running, double click on the Gain block and change the Gain value. View the result on the Scope. The amplitude of the sine waveform changes accordingly.
3. To switch the input source, double click on the Manual Switch block. View the result on the Scope. If the Verbose is selected in the Model Configuration Parameters > Hardware Implementation > Target Hardware Resources > External mode, the status of the parameter change is displayed on the MATLAB Command Window.
4. Stop External mode simulation.
To log External mode data to a MAT file, you can either use the Scope or the To Workspace block. Simulink supports multiple data logging schemes. The below steps explain, the default, manually triggered scheme.
1. Click on the Data Archiving button of the External Mode Control Panel (Code > External Mode Control Panel ) . Check the Enable Archiving option. Use the Directory parameters to specify the destination of your log file, and File to specify the name of your log file.
In Data Archiving, new data sets are saved in new MAT files (log files). Each data set is of the size of the Duration (Code > External Mode Control Panel > Signal & Triggering > Duration). Duration specifies the minimum contiguous data to be collected by External mode.
2. Open the Scope connected to the Gain block and click on the Configuration Properties button.
3. Navigate to the Logging tab and check the Log data to workspace option. Specify a name in Variable name. The logged data is saved in this variable. To save the corresponding time instants along with the logged data, select Save Format as Structure With Time.
Note: If you do not check the Log data to workspace option, empty MAT-files will be created.
4. Run the model in External mode by clicking on the Run button. Navigate to the folder specified for saving the logged data(path mentioned in step 1). Several MAT files will be created, each containing a structure with 25 contiguous data samples. You can change the size of the contiguous data samples by changing Duration (Code > External Mode Control Panel > Signal & Triggering > Duration).
5. Press the Stop button in the Simulink Editor to terminate the External mode simulation.
1. There might be problem cases in which External mode on the Vex microcontroller doesn't start. In such cases, the serial Port (COM Port) may not have been closed properly. To overcome this, connect and disconnect the USB A-A cable.
2. Increasing the Duration allows MAT file logging with large contiguous data sets. A high value of Duration may result in Not enough memory on the target to process the packet warning, and consequently cause no data to be logged. If you face this warning, either decrease the number of scopes or decrease the Duration (Code > External Mode Control Panel > Signal & Triggering > Duration).