Unlock EtherCAT-CoE: Practical Application with Motor Drive

9 min readApr 2, 2025

Video Link:

https://youtu.be/0_iVCYxcE10

Introduction

EtherCAT CoE (CAN over EtherCAT) is a communication protocol within the EtherCAT framework that integrates the CANopen application layer protocol into the EtherCAT network, facilitating device control and data exchange in distributed systems. It combines the user-friendliness of CANopen with the high-performance advantages of EtherCAT, making it widely used in fields such as industrial automation, motion control, and sensor networks.

Here are the key features and functions of CoE:

CANopen-Based

● The application layer of CoE directly adopts the CANopen device protocol, including the structure and services of the Object Dictionary.

● The Object Dictionary defines device parameters, communication objects, and control data, ensuring interoperability between devices.

Support for Standard Services

SDO (Service Data Object): Used for point-to-point configuration and diagnostic communication, SDO allows the master to exchange large volumes of data (such as parameter configurations) with slaves.

PDO (Process Data Object): Facilitates real-time communication by transmitting small amounts of periodic process data, supporting quick responses.

Emergency (EMCY) Messages: Used to report exceptional conditions or faults in the device.

NMT (Network Management): Provides functions for network management, such as starting, stopping, and resetting devices.

Efficient Transmission

● The bus architecture and high-speed frame processing capabilities of EtherCAT enable CoE to exchange data with lower latency and higher efficiency.

Support Multiple Application Scenarios

● Suitable for industrial equipment configuration, real-time monitoring, parameter diagnostics, and system integration.

Object Dictionary Mapping

● The Object Dictionary organizes device data and functionalities in a hierarchical structure.

● EtherCAT uses the CoE protocol to access variables within the Object Dictionary for parameter reading, writing, and real-time control.

Typical Applications

● Supports drives with complex control logic (e.g., servo drives).

● Engineering tools for monitoring, debugging, and configuring devices.

This section will demonstrate how to implement EtherCAT CoE master-slave communication using Beckhoff TwinCAT3 and the EtherKit development board. The example project supports both CSP and CSV operation modes.

Preparatory Steps

Software Environment

RT-Thread Studio

Download Link

RZN-FSP v2.0.0

Download Link

Beckhoff Automation TwinCAT3

Download Link

Hardware Environment

EtherKit Development Board (Purchase Link: Taobao)

One Ethernet cable

J-Link debugger

CiA402 Servo User Guide

First, let’s take a look at the CiA402 protocol: The CiA402 protocol (Communication Interface for Drive Systems) is defined by the CiA (CAN in Automation) organization for industrial automation, particularly for standardizing protocols in motor control systems. CiA402 serves as the sub-protocol for configuring drives and motion controllers over CANopen and extends and optimizes functionalities crucial for motion control systems based on the CANopen communication protocol. It is mainly used for controlling servo motors, stepper motors, and other types of electric drive systems.

Next, we will examine the FSA (Finite State Automaton) and the various states of the driver, as well as how to execute transitions between these states.

Below are detailed explanations of the various states corresponding to the above diagram:

For the controller, during each communication cycle, the master station needs to send a control word to the slave and receive a status word from the slave for confirmation. In this project, the state transitions of CiA402 are implemented through the CiA402_StateMachine() function:

At the same time, the master station reads the status word (status word, 0x6041) from the slave to understand the current operating status of the slave. The status word provides detailed information about the slave’s current state and any potential faults or warnings that may have occurred.

The master station sends control commands to the slave through the control word (control word, 0x6040) to change its operating state or trigger specific actions.

CiA402 Object Dictionary Definition

Below is a list of the supported CiA402 object dictionary items in the EtherKit CoE project. Position mode and velocity mode are supported, allowing the master station to set the control word for interaction with the slave’s process data, enabling read and write operations on the controller based on the CoE protocol.

TwinCAT3 Configuration

Before starting TwinCAT3, we need to perform some configuration tasks:

Install ESI File

Before launching TwinCAT, copy the ESI file contained in the release folder to the TwinCAT target location: ..\TwinCAT\3.x\Config\IO\EtherCAT.

Note: The current version of the ESI file is located at: ..\board\ports\ESI_File\Renesas EtherCAT RZN2 CoE CDP.xml.

Create a New TwinCAT Project

Open the TwinCAT software, click on File -> New -> New Project, and select TwinCAT Projects to create a TwinCAT XAR Project (XML format).

Start CoE Application on the Slave

After powering on the EtherKit development board, connect the ETH0 port using an Ethernet cable. EtherCAT will run by default.

Slave Device Scanning

After creating the new project, find Devices in the left navigation pane, right-click, and select Scan Devices. If the slave device is successfully scanned, it will display as Device x [EtherCAT]; if the scan fails, it will show as Device x [EtherCAT Automation Protocol], indicating that the slave initialization has failed.

After clicking OK, a window titled Scan for Boxes will pop up. Confirm it, and then another window titled Activate Free Run will appear. Since this is our first time using CoE and we need to update the EEPROM firmware, we will not activate it at this moment.

Update EEPROM Firmware

Returning to TwinCAT, in the left navigation pane, we can see the master-slave configuration interface now that we have successfully scanned the slave device.

We double-click on Box 1, then in the upper navigation bar of the central interface, click on EtherCAT and select Advanced Settings ….

Here, click on Download from List … as illustrated in the diagram:

We write the ESI firmware to the EEPROM. Since we configured a dual Ethernet port, we select Renesas EtherCAT RZ/N2 COE 2port. If you have configured a triple port, then choose the ESI file with the 3port suffix for downloading.

Once the download is complete, we right-click on Device x (EtherCAT) to remove the device, then re-scan and add the device, and complete the activation process (refer to the earlier section).

EtherCAT COE Testing

First, we need to ensure that the program is successfully downloaded to the project and that the ESI file has been correctly programmed. Below is the information printed in the serial terminal of the development board:

Next, we open the ESC project that we created earlier and scan for devices. At this point, a message will pop up indicating that EtherCAT drive(s) added. We select NC — Configuration, click OK, and then activate the device:

After successfully activating the device, the EtherCAT state machine will transition through Init -> Pre-Op -> Safe-Op, and finally reach Op (Operational State). The EtherKit CoE project defaults to enabling CSP (Cyclic Synchronous Position mode) and also supports CSV (Cyclic Synchronous Velocity mode).

When the system is powered on, the driver automatically completes initialization and enters the STATE_SWITCH_ON_DISABLED state. At this point, you can set the operating mode of the driver, such as switching to CSP or CSV mode. Correspondingly, on the development board, you will see the current state machine information for Axis 1 (CiA402) continuously printed:

CSP Position Mode Control

First, let’s look at the controller in CSP mode: In position mode, we can set the desired target position by writing to the control word (0x607A), and the corresponding status word (0x6064) will provide the actual feedback position information.

If you want to operate in either CSP or CSV mode, you must first change the state to STATE_OPERATION_ENABLED (Operational Mode).

Expand the left navigation pane and click in order: Box 1 (Renesas EtherCAT RZ/N2 CoE 2port) -> Module 1 (CSP — axis) -> Outputs -> Control Word. First, you need to switch to the servo fault-free mode. The master station will write the value 0x0080 (dec: 128) to the control word (0x6040) to change the servo controller to a fault-free state:

At this point, you will notice that the slave’s serial terminal stops printing **State Transition 2** and **State Transition 7**. Next, we write the value 0x000F (dec: 15) to the control word (0x6040):

At this moment, the servo controller switches from the waiting state to enable the servo to the operational state. The slave’s serial terminal will then print **State Transition 2**, **State Transition 3**, and **State Transition 4**. After going through state transitions 2, 3, and 4, the CiA402 state machine enters the **STATE_OPERATION_ENABLED** state, allowing control of the controller.

For example, if we are currently in position mode, we can write a position value to **Index: 0x607A**. Let’s write 100000:

At this moment, click on Box 1 (Renesas EtherCAT RZ/N2 CoE 2port) -> Module 1 (CSP — axis) -> Inputs -> Actual Position to check the actual feedback position. You will find that the value corresponding to Index 0x6064 keeps incrementing until it reaches 100000, at which point it stops.

CSV Velocity Mode Control

First, you need to switch the controller mode from the default CSP mode to CSV mode. Click on Box 1 (Renesas EtherCAT RZ/N2 CoE 2port) in the left navigation pane, then find Slots at the top of the middle page and select Axis 0. On the right, change the preset supported module to CSV and click the ‘<’ icon:

At the same time, we can also observe whether the corresponding module information on the left has been updated and ensure it has switched to CSV mode.

After switching the mode, we need to reload the device. Click on the upper navigation bar of TwinCAT3 and select TwinCAT -> Reload Devices.

Next, the controller needs to enter STATE_OPERATION_ENABLED (Operational Mode, as referenced above). Similarly, write the values to the control word sequentially: first, 0x0080 (to transition to a fault-free state), then 0x000F (to switch from waiting to enable servo to the servo running state).

At this point, check the input status word at 0x6041. If the corresponding value is 0x1237, it indicates that the controller is in operational mode (STATE_OPERATION_ENABLED). If the displayed value is 0x1208, it means that the status is in Fault. In this case, reset the control word to 0x0080 (dec: 128) and repeat the above operations.

Now, we can write the desired value for the Target Velocity to control the actual speed.

At the same time, you can check the actual set speed information in the inputs to see if it is consistent:

--

--

RT-Thread IoT OS
RT-Thread IoT OS

Written by RT-Thread IoT OS

An Open-Source Community-Powered Real-Time Operating System (RTOS) Project! Let’s develop, DIY, create, share, and explore this new IoT World together!

No responses yet