36.1. ECAT_CiA402
36.1.1. 1. Overview
The ECAT_CIA402 example demonstrates the use of ESC peripherals and the implementation of CANOPEN CiA402 protocol control motor function based on ETG slave protocol stack code (SSC).
36.1.2. 2. Prepare
Please refer to the README of ECAT_IO sample
This program uses the BLM57050-1000 brushless motor of “Leisai Intelligence”, please refer to the Leisai Intelligence website for the specific parameters of the motor.
Board settings refer to the development board documentation Motor Pin related content
After completing the above process, power on the driver board and observe that the current is normal. Then, power on the core board and confirm that the current is normal again. After that, you can burn the program and observe the running phenomenon.
36.1.3. 3. Project Setting
36.1.3.1. 3.1 Flash emulate EEPROM
Please refer to the README of ECAT_IO sample
Note: When using FLASH to simulate EEPROM, please allocate appropriate flash space for FLASH-EEPROM content to avoid conflicts with other flash contents
36.1.3.2. 3.2 Using virtual motor
By default, the actual motor is used for motion control. If a virtual motor is required, set “set (CONFIG_CIA402_USING_ACTUAL_MOTOR 0)” in the file CMakeLists. txt.
36.1.4. 4. Generate EtherCAT slave stack code
Due to licensing issues, HPMSDK does not provide EtherCAT slave protocol stack code (SSC). Users have download the SSC Tool from Beckoff’s official website and generate the slave stack code according to the steps.
36.1.4.1. 4.1. Download SSC Tool
Please refer to the README of ECAT_IO sample
36.1.4.2. 4.2 SSC Tool import configuration files
Please refer to the README of ECAT_IO sample, import configuration file path: <hpm_sdk>/samples/ethercat/ecat_cia402/SSC/Config/HPM_ECAT_CIA402_Config.xml
36.1.4.3. 4.3 Create slave stack files
create new project, select the configuration file

Specify the output path and generate slave stack code
36.1.4.4. 4.4 SSC code change
Add motor control related codes to the code generated by SSC by patching.
Execute in the command line window under the SSC directory:patch -d Src < ssc_cia402.patch

Note:If the patch command is not installed on your PC, you will need to install ver. 2.5.9 or a laterversion of GNU patch. If it is already installed, skip this step. Download the patch command (currently ver. 2.5.9) from the following Web page and store “patch.exe” in a folder on a path that makes the file executable from the command prompt. http://gnuwin32.sourceforge.net/packages/patch.htm
36.1.5. 5. TwinCAT Project setting
36.1.5.1. 5.1. Add ESI file
Copy the generated ESI xml by SSC tool in previous steps to TwinCAT(C:\TwinCAT\3.1\Config\Io\EtherCAT).
36.1.5.2. 5.2 Create Project
Please refer to the README of ECAT_IO sample
36.1.5.3. 5.3 Software Configuration
Please refer to the README of ECAT_IO sample
36.1.5.4. 5.4 Scan device
Please refer to the README of ECAT_IO sample
36.1.5.5. 5.5 Update EEPROM context
Please refer to the README of ECAT_IO sample, select ESI file

36.1.5.6. 5.6 NC axis control
scan device,add NC-Configuration, the default mode is csv:

check device sync unit setting, device should sync with NC task

check the link relationship between NC Axis and Devie

Check encoder parameter for NC Axis

Set the NC Task cycle, and the DC cycle will be the same as this value.
A larger cycle time can be set here to avoid the “0x1a Synchronization error” caused by communication jitter due to poor real-time performance of the PC when using it as the TwinCAT master station

Set DC mode

Set the NC axis parameters to disable the limit setting to avoid errors during testing operations.

active configuration,enter Run mode

NC axis online function description

ontrol NC axis motion on csv mode a. In “Enabling” option, click “Set->All”, enable the NC controller
b. Set the target position and speed, note that the target speed value should not exceed 7mm/s(Virtual motors have no speed limit). After setting, click “F5” to start
c. View actual postion and velocity

change NC axis control mode to csp

link NC Axis and Device

refer to step 8, reactivate the configuration
ontrol NC axis motion on csp mode a. Refer to the steps 10.a to enable the controller a. Set the target position and speed, note that the target speed value should not exceed 7mm/s. After setting, click “F5” to start
b. View actual postion and velocity

36.1.6. 6. Running the example
After the project is running correctly, the serial terminal will output the following information. The motor motion can be controlled through the TwinCAT NC Axis control page:
EtherCAT CiA402 sample
EEPROM loading with checksum error.
EtherCAT communication is possible even if the EEPROM is blank(checksum error),
but PDI not operational, please update eeprom context.
or
EtherCAT CiA402 sample
EEPROM loading successful, no checksum error.