Calibrate ECU Parameters in CANape Using XCP-based Serial Interface
This example shows how to monitor signals and tune parameters of a Simulink model on Arduino™ Mega 2560 board using CANape® software. CANape is primarily used in optimizing parameterization (calibration) of electronic control units (ECU). By using CANape, you can calibrate parameter values and acquire measurement signals during system run time.
In this example, you will learn how to tune the parameters and monitor the signals in an algorithm in real time from CANape software.
Complete the Getting Started with Arduino Hardware example.
Required MathWorks Products
Simulink Support Package for Arduino™ Hardware
Required Third-party Software
CANape® 16.0 SP6
Any Arduino board as listed in the Supported Hardware section of Arduino Support from Simulink.
To open the pre-configured model, run this command at the MATLAB prompt:
This example contains three signals that are enabled for logging and two parameters for tuning. The three signals are:
Counter - Increments the output by STEP_PARAM at every time step
Sine_Wave - A sine wave
Pulse - A Pulse signal with tunable amplitude
Configuring Simulink Model for Arduino Board
The Simulink model provided in this example is preconfigured for Arduino Mega 2560, but it can be run on any of the Arduino boards. To use a hardware board other than Arduino Mega 2560 and enable calibration of parameters in CANape, follow these steps:
1. Open arduino_xcponserial_CANape model
2. Go to Modeling > Model Settings to open the Configuration Parameters dialog box.
3. Open the Hardware Implementation pane, and select the required Arduino board from the list in Hardware board parameter.
4. Expand Target hardware resources for that board.
5. Go to External mode tab and choose XCP on Serial as the Communication interface.
7. Choose CANape as the Host Interface.
8. Click Apply and OK.
Initiate Monitor and Tune Action for Simulink Model and Generate A2L File
On the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Monitor & Tune.
The Simulink model is deployed on the Arduino board and an A2L file named
arduino_xcponserial_CANape_CoderXCPSlave.a2l is generated in the current folder path in MATLAB. After successful deployment, CANape can be used to connect to the Arduino board for monitoring signals and tuning parameters.
Create New Project in CANape and Connect to Arduino board
1. Open Vector CANape 16.0 software. Create a new Project.
2. Drag and drop the A2L file generated from the model into CANape. This opens a new dialog box which creates a new device.
3. Click Next and finally click OK. A new device is created, and the Settings dialog box for the newly created device opens.
4. Expand the Protocol tab in the Settings dialog box. Click Transport Layer.
5. Ensure that you have selected the correct Channel (COM Port to which Arduino is connected) in the COM section. Modify the Baud Rate to 921600.
6. Click Accept all changes in the top-left corner of the Settings dialog box and close it.
7. Click Online to connect to the Arduino board.
Perform Measurement and Calibration from CANape
1. Open the list of signals and parameters by expanding the Devices tab in the Explorer pane.
2. Drag the signals that you want to monitor, to the Display area and select a graphic window.
3. Drag the parameters that you want to tune, to the Display area and select Parameter window.
4. Click Start measurement in the Start tab to start monitoring the selected signals.
5. Use the Parameter window to tune the parameters.
Troubleshoot Calibration in CANape
While you perform calibration of parameters using CANape, you may encounter these errors:
CANape fails to connect with the error:
No response from the ECU
To resolve this issue, check the COM Port and Baud Rate settings and ensure that they are correct. If the error persists, press Reset button on Arduino board and try to connect again.
Data Acquisition does not start when you click Start for the first time.
To resolve the issue, click Start again.
The issue occurred because CANape sends command 0xD7 (GET_DAQ_EVENT_INFO) and 0xDC (GET_DAQ_CLOCK) to the slave, even though these are not listed as supported optional commands in the ASAP2 file. By default, CANape has XCP_OPTIONAL_CMD_AUTO_LEARNING feature, which learns that the GET_DAQ_EVENT_INFO and GET_DAQ_CLOCK commands are not supported, and correctly sends DAQ on the second attempt. This information persists in the project database, so the failure does not occur again for the same project.
Signal monitoring or parameter tuning of type double can only be done on Arduino with ARM cores.