Parameter Tuning and Signal Logging over Serial Communication

With Monitor & Tune (External Mode), you can log signals and tune parameters while the model is running on the target hardware in real time. When you change parameter values from within Simulink, the modified parameter values are communicated to the target hardware immediately. Also, you can monitor the effects of the parameters tuning activity by viewing the algorithm signals on the scopes.

You can run your model on the external mode via two communication interfaces, serial or CAN.

For external mode with serial communication, you have a ready-to-use COM port on the USB drive if your target hardware supports it or the COM1 port on your computer with RS–232 cable. For more information on how to set up serial communication, see Set Up Serial Communication with Target Hardware. You can configure the external mode for different baud rates that your communication interface supports.

To run your model in external mode with CAN Calibration Protocol(CCP), use the CAN Calibration Protocol block and a Vector CAN case hardware. External mode uses the eCAN module to run external mode. You can configure the external mode with any available eCAN module. For more information, see Set Up CAN Communication with Target Hardware. You can configure the baud for eCAN.

The external mode with ‘ert.tlc’ downloads the executable, runs the model, and establishes external mode connection in a single step.

Monitor and Tune over Serial Communication

Monitor and Tune (External Mode) over Serial Communication can be done using either of the two available protocols:

  • Classic External Mode

    In this method, you will setup Serial communication between Simulink® and Texas Instruments™ C2000 board to tune the parameters and monitor the signal of an algorithm running on the board.

  • External Mode over Universal Measurement and Calibration (XCP)

    Simulink provides these additional features for the targets that support XCP:

    • Dashboard objects such as Slider and Dashboard Scope. For more information, see Dashboard (Simulink)

    • Simulation Data Inspector (SDI) for visualizing the logged signals. For more information, see Simulation Data Inspector (SDI)

Based on the maximum and the minimum baud that the SCI_A module supports, you can run your model in external mode over different baud rates.

To prepare your model for external mode with serial communication:

  1. In the Configuration Parameters dialog box, select Model Configuration Parameters > Hardware Implementation .

  2. Select a C2000 processor from the Hardware Implementation > Hardware board drop-down list.

  3. Under Target Hardware Resources, select External mode(Classic)/External Mode over Universal Measurement and Calibration (XCP).

  4. In Communication interface drop-down list, select serial.

  5. Specify the corresponding COM port that the target hardware uses.

    For the COM port on your computer, select Start > Control Panel > Device Manager > Ports (COM & LPT)

  6. Make sure that the Verbose check box is selected to view the external mode execution progress and updates in the Diagnostic Viewer or in the Command Window.

  7. To execute your model with a specific baud:

    Under Target Hardware Resources, select the SCI_A pane and then specify the desired baud in Desired baud rate in bits/sec parameter.

    The default baud is 115200 bits/sec. For better performance, you may increase the baud to a value that your hardware board permits.

Your model is now ready to perform Monitor and Tune action (External Mode) over serial communication.

To perform the Monitor and Tune action :

  1. Open the Model.

  2. Go to theHardware tab and click Monitor & Tune.

    For more information, see Parameter Tuning and Signal Logging with Serial Communication

Note

  • For targets with small RAM such as F28027, the code has to be booted from flash. To boot the code from flash, select TI Piccolo F2802x (boot from flash) in Hardware Implementation > Hardware board drop-down list

  • Parameter tuning and signal logging for 8-bit data type is not supported in external mode over serial

Monitor and Tune over CCP

You can tune parameters and log signals (External Mode) using Simulink external mode with CCP. For signal logging and parameter tuning with a third-party calibration tool, see CAN Calibration Protocol with Third Party Tools.

The external mode is supported using the CAN Calibration Protocol block and ASAP2 interface. The ASAP2 interface is used to get information about where a parameter or signal exists in the target memory. The CAN Calibration Protocol block is used to communicate with the target, download parameter updates, and upload signal information.

To prepare your model for external mode over CCP, perform these tasks:

  1. To set up external mode, see Set Up Your Model for External Mode.

  2. To run your model in external mode with ert.tlc, see Monitor and Tune Your Model (External Mode).

  3. To tune your parameters, see Tuning Parameters.

For more information, see:

Set Up Your Model for External Mode

  1. Add a CCP driver block to your model from the Simulink Block Library.

  2. Identify signals that you want to tune. Associate them with Simulink.Parameter or canlib.Parameter objects with ExportedGlobal storage class. Set the data type and value of the object. See Using Supported Objects and Data Types.

  3. Identify signals you want to log. Associate them with canlib.Signal objects. Set the data type of the canlib.Signal. See Using Supported Objects and Data Types.

    For information about visualizing logged signal data, see Viewing and Storing Signal Data.

  4. Load the Simulink.Parameter or canlib.Parameter and canlib.Signal data objects into the base workspace.

  5. Select Simulation > Model Configuration Parameters.

  6. In the Configuration Parameters dialog box, select Optimization > Signals and Parameters pane.

  7. Select Default parameter behavior > Inlined and click Configure.

  8. In the Model Parameter Configuration dialog box that opens, define the (global) tunable parameters for your models.

  9. In the Configuration Parameters dialog box, select Code Generation > Interface pane.

  10. Set the Interface parameter to ASAP2.

Monitor and Tune Your Model (External Mode)

To perform Monitor & Tune action :

  1. Open the Model.

  2. Go to the Hardware tab and click Monitor & Tune.

    Your model now runs in the external mode over CCP.

Configuring the Host Vector CAN Application Channel

For external mode, the host-side CAN connection must use the 'MATLAB 1' application channel. To configure the application channel that the Vector CAN drivers use, in the Command Window:

TargetsComms_VectorApplicationChannel.configureApplicationChannels
Use this tool to configure your host-side CAN channel settings.

If you try to connect using an application channel other than 'MATLAB 1', you see the following warning:

Warning:
It was not possible to connect to the target using CCP. 
An error occurred when issuing the CONNECT command. 

If you have not already installed the Vector CAN drivers, you get the following error message in the command window:

??? Error using ==>
TargetsComms_VectorApplicationChannel.TargetsComms_VectorApplicationChannel>
TargetsComms_VectorApplicationChannel.configureApplicationChannels at 40
Unable to launch the application channel configuration utility. 
The "vcanconf" utility was not found on the Windows System Path. 
To fix this error, make sure the required CAN drivers are installed on this computer;
refer to the product documentation for details.
If you want to use CAN to transmit or receive CAN messages between your host PC and your target, you need VN1600 supported by the Vector CAN Driver Library. Choose the driver libraries to support profiling, downloading, and external mode. Make sure that the library, vcand32.dll, is placed in the Windows® system32 folder.

Using Supported Objects and Data Types

Supported objects are:

  • Simulink.Parameter or canlib.Parameter for parameter tuning

  • canlib.Signal for signal logging

Supported data types are:

  • uint8, int8

  • uint16, int16

  • uint32, int32

  • single

Define data objects for the signals and parameters of interest for ASAP 2 file generation. For ease of use, create a MATLAB® file to define the data objects so that you only have to set up the objects only once.

To set up tunable parameters and signal logging:

  1. Associate the parameters that you want to tune with Simulink.Parameter or canlib.Parameter objects with ExportedGlobal storage class. It is important to set the data type and value of the parameter object. For an example of how to create such a Simulink.Parameter object for tuning, see the following code:

    stepSize = Simulink.Parameter;
    stepSize.DataType = 'uint8';
    stepSize.CoderInfo.StorageClass = 'ExportedGlobal';
    stepSize.Value = 1;

  2. Associate the signals that you want to log with canlib.Signal objects.Set the data type of the canlib.Signal. The following code example shows how to declare such a canlib.Signal object for logging.

    counter = canlib.Signal;
    counter.DataType = 'uint8'; 

  3. Associate the data objects that you defined in the MATLAB file with parameters or signals in the model. For the previous code examples, you can set the Constant value in a Source block to stepSize, and set a Signal name to counter in the Signal Properties dialog box. stepSize and counter are the data objects defined in the code.

Tuning Parameters

  1. In the workspace, set dataobject.value while the model is running in external mode. For example, to tune the parameter stepSize (that is, to change its value) from 1 to 2, at the command line, enter:

    stepSize.value = 2
    You see output similar to the following:
    stepSize = 
    
      Parameter with properties:
    
              Value: 2
          CoderInfo: [1×1 Simulink.CoderInfo]
        Description: ''
           DataType: 'uint8'
                Min: []
                Max: []
               Unit: ''
         Complexity: 'real'
         Dimensions: [1 1]

  2. Update the model (press Ctrl+D) to apply the changed parameter.

Viewing and Storing Signal Data

To view the logged signals, attach a supported scope type to the signal.

To customize the signals that are logged:

  1. In the Simulink Editor, select Code > External Mode Control Panel.

  2. In External Mode Control Panel, click Signal & Triggering.

  3. In External Signal & Triggering box, clear the check boxes for scope data that you do not want to log.

Storing signal data for further analysis. You can further analyze the logged data in MATLAB.

  1. To use the data archiving in external mode, in the External Mode Control Panel, click Data Archiving.

    1. In the Enable Data Archiving dialog box, select the check box Enable archiving.

    2. Edit the Directory and File fields. Review the other settings.

    3. Click Apply and close the dialog box.

  2. Open the Scope parameters by clicking the scope parameters icon in the scope window toolbar.

    Select the check box Save data to workspace.

  3. In the Variable name field, edit the variable name. The data that is displayed in the scope at the end of the external mode session is available in the workspace with this variable name.

    The data that was previously displayed in the scope is stored in .mat files.

    For example, at the end of an external mode session, the following variable and files are available in the workspace and the current folder:

    • A variable ScopeData5 with the data currently displayed on the scope:

      ScopeData5
      
      ScopeData5 = 
      
               time: [56x1 double]
            signals: [1x1 struct]
          blockName: 'c28x_ccp_ert/Scope1'

    • In the current folder, .mat files for the three previous durations of scope data:

      ExternalMode_0.mat  
      ExternalMode_2.mat  
      ExternalMode_1.mat
      

Limitations

Multiple signal sinks (for instance, scopes) are not supported.

Only the following kinds of scopes are supported with external mode logging:

  • Simulink Scope block

  • Simulink Display block

  • Viewer type: scope — To use this option in your model, right-click a signal in the model, and select Create & Connect Viewer > Simulink > Scope. The other scope types listed are not supported (for instance, floating scope).

    Before connecting to external mode, right-click the signal and select Signal Properties. In the dialog box, select the Test point check box, and click OK.

  • GRT is supported only for parameter tuning.

  • You cannot log signals with sample rates more than 10 kHz.

  • Top-level builds are supported for external mode. Subsystem builds are not supported for external mode.

  • Logging and tuning of nonscalars is not supported. It is possible to log nonscalar signals by breaking down the signal into its scalar components. For an example of how to do this signal deconstruction, see the CCP example models, which use a Demux and Signal Conversion block with contiguous copy.

  • Logging and tuning of complex numbers is not supported. It is possible to work with complex numbers by breaking down the complex number into its real and imaginary components. You can perform this breakdown using the following blocks in the Simulink Math Operations library: Complex to Real-Imag, Real-Imag to Complex, Magnitude-Angle to Complex, and Complex to Magnitude-Angle.

See Also