Main Content

Signal Monitoring and Parameter Tuning over XCP on CAN Using Generated A2L

This example shows how to build a standalone system application that uses a generated A2L file for signal monitoring and parameter tuning over XCP on CAN. You can then use MATLAB® Compiler™ to deploy the standalone application for logging and fine-tuning of parameters using XCP, independent of MATLAB and Simulink®.

Introduction

XCP is a high-level protocol that allows you to acquire, stimulate, and calibrate data in electronic control units (ECU). XCP accesses ECU modules via an interface such as CAN. The XCP client communicates with one or more server modules by sending commands.

Using industry-standard A2L files, you can read and write to memory or perform data acquisition and stimulation.

An A2L file is a special description file that defines the implementation of an ECU. The information in an A2L file allows an XCP client to communicate with a server module via an XCP connection.

This example includes a ready-to-use app, created using MATLAB App Designer, which you can deploy as a standalone application using MATLAB Compiler.

Note: The .mlapp file provided with this example is the starting point; you can further customize the app as per your requirements before deploying.

Configure the Simulink Model for Signal Monitoring and Parameter Tuning

To generate the A2L file from the Simulink model, follow these steps:

  1. In the Simulink model, configure the required signals for logging. For more information, see Save Run-Time Data from Simulation.

  2. Set the calibration parameters to make them tunable, as explained in Create Tunable Calibration Parameter in the Generated Code (Simulink Coder).

  3. Open the Configuration Parameters window, navigate to Hardware Implementation > Target Hardware Resources, and click the External mode tab. Choose XCP on CAN as the Communication interface and Third party calibration tools as the Host interface. Select the correct value for CAN module parameter also.

  4. Connect the Texas Instruments C2000 board to the host computer.

  5. Set up CAN communication between the target hardware and the host computer, as explained in Set Up CAN Communication with Target Hardware.

  6. As explained in Signal Monitoring and Parameter Tuning over XCP on CAN Using Third-Party Calibration Tools, in the Hardware tab of Simulink toolstrip, click Build for Monitoring. This action builds the model, and also generates an A2L file in the current MATLAB folder path. The A2L file contains XCP peripheral information for using in third-party calibration tools. The file name of the A2L file is in this format: <modelname>.a2l.

  7. Click Deploy in the Simulink Toolstrip to deploy the executable onto the target.

Working with the App and Its Components

App PreviewV6.png

Before launching the app, perform these steps:

  1. Connect the Texas Instruments™ C2000 board to the host computer.

  2. Set up CAN communication between the target hardware and the host computer, as explained in Set Up CAN Communication with Target Hardware.

Proceed with these steps to interactively work with the app and perform signal monitoring and parameter tuning from the generated A2L file:

Step 1: Select CAN Values

The parameters CAN vendor, CAN device, and CAN channel number gets auto-populated with values based on the connected CAN module. Select the appropriate values for these parameters.

Step 2: Import the A2L File

In the app, click Import A2L file, and browse for the A2L file that was generated from the model.

Step 3: Select the Sample Rate from A2L

Select the appropriate sample rate, as defined in the A2L file, from the Sample rate selection parameter.

Step 4: Connect the C2000 Hardware and Start the XCP Session

Connect the Texas Instruments C2000 board to the PC and click Start XCP session.

You can view the signals that are configured for monitoring in the Signals from A2L file field.

Step 5: Plot the Signals for Visualization

Select the signal in the Signals from A2L file field and click Start Plotting. You can also select multiple signals by using Ctrl + click. You can view the signal values plotted against time (in seconds) in the Signal Visualization pane of the app.

Step 6: Tune a Specific Parameter with Updated Values

Select the required parameter for which you would like to change the value, using the Select parameter for tuning drop-down menu. Observe the Existing value field to know the current value.

Edit the Update parameter value field to the specify the required value.

You can monitor the updated signal in the Signal Visualization pane.

Additional Customization of the App

This ready-to-use app uses standard functions from Vehicle Network Toolbox. You can further edit the components and change the app behavior using MATLAB App Designer.

Callbacks Used in the App

  • startup: Uses the canChannelList (Vehicle Network Toolbox) function to fetch a list of available CAN channels and then processes this list to populate vendor, device ID, and device channel index dropdown menus in a user interface.

  • selectA2LFile: Manages the selection of an A2L file through a user interface. It loads the A2L file data and provides the values for Sample rate selection dropdown, as defined in the A2L file.

  • vendorModification: Filters device channel list based on selected vendor and updates device channel index dropdown with available channels.

  • deviceIDModification: Filters device channel list based on selected device ID and updates device channel index dropdown with available channels.

  • eventValueChange: Stops the measurement using the stopPlotOperation function, clears the measurement list using freeMeasurementLists (Vehicle Network Toolbox) function, creates a new list with the updated sample rate using createMeasurementList (Vehicle Network Toolbox) function, and restarts the measurement process on the channel using startMeasurement (Vehicle Network Toolbox) function.

  • ConnectXCP: Extracts parameters such as vendor, device ID, and device channel index from the drop-down lists to establish the XCP channel connection using xcpChannel (Vehicle Network Toolbox) function. Measurements and characteristics are retrieved from the A2L file information, and any existing measurement lists are cleared if a measurement is running, using stopMeasurement (Vehicle Network Toolbox) followed by freeMeasurementLists (Vehicle Network Toolbox). A new measurement list is created using createMeasurementList (Vehicle Network Toolbox), and then measurement is started by using startMeasurement (Vehicle Network Toolbox). It also updates the lists for signals and tunable parameters, and the current value of a selected tunable parameter is read and displayed.

  • plotLoggedData: Enables continuous plotting and creates animated line objects for each selected signal. A plotting loop reads data from the XCP channel using readDAQ (Vehicle Network Toolbox) and adds points to the animated lines in real-time.

  • stopPlotting: Executes the stopPlotOperation function to stop the plot operation, and restarts the measurement on the XCP channel using startMeasurement (Vehicle Network Toolbox) function.

  • closeConnection: Stops any active continuous plotting and measurement using stopMeasurement (Vehicle Network Toolbox), if they are running. It then disconnects the XCP channel from the server using disconnect (Vehicle Network Toolbox) function and clears the A2L information from the application's context.

  • modifyCurrentvalue: Reads the current value of the selected tunable parameter name and updates the Existing value field with the current value of the parameter.

  • updateParameterValue: Writes the specified user write value to the selected tunable parameter using writeCharacteristic (Vehicle Network Toolbox) function. Then it retrieves and displays the current value of the written parameter.

Function Used in the App

  • stopPlotOperation: Stops an ongoing measurement on an XCP channel using stopMeasurement (using isMeasurementRunning). Then it clears the data points.