This example covers how to enable the CiA402 device profile.
ecSubDeviceCiA402.c
ecSubDeviceCiA402.h
ESL_cia402Demo.c
ESL_cia402Demo.h
ESL_cia402Obd.c
ESL_cia402Obd.h
EtherCAT_SubDevice_CiA402.c
This example configures a 3 axis motor control application. If the device or the ESI file (EtherCAT SubDevice Information) does not support the CiA402 device profile, the subsequent registration calls should be disabled. The following functions are implemented in ESL_cia402Demo.c.
Motion control is done in this function. The control of modes CSP, CSV or CST is shown.
This CiA402 application function is synchronized to Sync0 ISR in DC synchronous mode and to Pdi ISR in SM synchronous mode. This function is registered using EC_API_SLV_CiA402_registerApplication(). This function calls EC_API_SLV_preSeqInputPDBuffer() and EC_API_SLV_preSeqOutputPDBuffer() to acquire the input and output process data buffers and calls EC_API_SLV_postSeqInputPDBuffer() and EC_API_SLV_postSeqOutputPDBuffer() to release the acquired buffers. The output process data buffer is being updated by the PDO_OutputMapping(), which is called in Sync0 ISR in DC mode and in Pdi ISR in SM mode. Similarly, input process data from the application is accessed by the PDO_InputMapping(), which is called in Sync0 ISR in DC mode and in Pdi ISR in SM mode.
The sequence of tasks performed in Sync0 ISR in DC mode is given below.
The function contains an implementation of the CiA402 State Machine (although an external one can be registered). This state machine works alongside the CiA402 application. The application reads the control object (0x6040) and writes the status object (0x6041). The application activates the axis and checks if there is any error pending. If an error is pending then it calls to transition actions to resolve the error and clears the error status if required.
If the CiA402 State machine changes to an error state this function is called. It is used to notify the error, not to take any action.
The example starts by initializing operating system (OSAL) and hardware abstraction layers (HWAL). The EtherCAT functionality itself is implemented within the EC_SLV_APP_loopTask that is started from the main application entry point, both are implemented in EtherCAT_SubDevice_CiA402.c.
EC_SLV_APP_loopTask starts with the initialization of the GPIO driver and the configuration of the PHY and LED pins in the function EC_SLV_APP_initBoardFunctions in ecSubDeviceCiA402.c.
Next PHY parameters, such as address, polarity and RX link are configured in EC_SLV_APP_registerStacklessBoardFunctions.
Before entering the main stack loop, the example application itself is initialized in EC_SLV_APP_CIA_applicationInit. This function creates a new EtherCAT SubDevice instance, registers a board status LED callback, sets vendor ID, product code and name, revision number, etc.
After the basic initialization, EC_SLV_APP_CIA_applicationInit continues with the setup of the CiA402 example drives and motion control example.
In CiA402 profile, for multiple axis SubDevices the objects range from 0x6000 to 0x67FF shall be shifted by 0x800 per axis. The below table describes the object index range for 3 axis.
| Axis | Range |
|---|---|
| Axis 1 | 0x6000 to 0x67FF |
| Axis 2 | 0x6800 to 0x6FFF |
| Axis 3 | 0x7000 to 0x77FF |
For a 3-axis setup, the CiA402 objects is allocated as follows.
| Objects | Axis 1 | Axis 2 | Axis 3 |
|---|---|---|---|
| Controlword | 0x6040 | 0x6840 | 0x7040 |
| Statusword | 0x6041 | 0x6841 | 0x7041 |
| Modes of operation | 0x6060 | 0x6860 | 0x7060 |
| Modes of operation display | 0x6061 | 0x6861 | 0x7061 |
| Target position | 0x607A | 0x687A | 0x707A |
| Target velocity | 0x60FF | 0x68FF | 0x70FF |
| Target torque | 0x6071 | 0x6871 | 0x7071 |
| Position actual value | 0x6064 | 0x6864 | 0x7064 |
| Velocity actual value | 0x606C | 0x686C | 0x706C |
| Torque actual value | 0x6077 | 0x6877 | 0x7077 |
CiA402 State Machine or Finite State Automation (FSA) is independent to the EtherCAT State Machine (ESM) and defines internal and external behavior for each state. The state of the drive determines which commands are accepted and whether high power is applied. States are changed when a controlword from the host-controller is received. They can also be changed due to internal events. The current state is indicated by the statusword. The controlword and different command values (e.g. velocity) are mapped into default RxPDOs (receive process data objects). The statusword and different actual values (e.g. position) are mapped into TxPDOs.
For a detailed description of the state machine transition please refer to the chapter 5.1 of the ETG6010 CiA402 implementation directive.
When the EtherCAT SubDevice has reached the OP state, there shall be an automatic state transition from Not ready to switch on state to Switch on disabled state in the CiA402 state machine. The states in bold letters are stable states in the drive, and transition can be requested only from the control device/MainDevice. Below is the list of controlword commands for the corresponding state transitions in the CiA402 state machine.
| Controlword | CiA402 State Transitions |
|---|---|
| 0x06 | Switch on disabled -> Ready to switch on |
| 0x07 | Ready to switch on -> Switched on |
| 0x0F | Switched on -> Operation enabled |
The controlword object 0x6040 is used to request state changes on the CiA402 state machine for Axis 1. The control commands are coded by bits.
| Bit | Description |
|---|---|
| 0 | Switch on |
| 1 | Enable voltage |
| 2 | Quick Stop |
| 3 | Enable Operation |
| 4-6 | Operation mode specific |
| 7 | Fault reset |
These defines are available to transition between different states.
| Define | Value | Description |
|---|---|---|
| CONTROLWORD_COMMAND_SHUTDOWN | 0x0006 | Shutdown command |
| CONTROLWORD_COMMAND_SWITCHON | 0x0007 | Switch on command |
| CONTROLWORD_COMMAND_SWITCHON_ENABLEOPERATION | 0x000F | Switch on and enable command |
| CONTROLWORD_COMMAND_DISABLEVOLTAGE | 0x0000 | Disable voltage command |
| CONTROLWORD_COMMAND_QUICKSTOP | 0x0002 | Quickstop command |
| CONTROLWORD_COMMAND_DISABLEOPERATION | 0x0007 | Disable operation command |
| CONTROLWORD_COMMAND_ENABLEOPERATION | 0x000F | Enable operation command |
| CONTROLWORD_COMMAND_FAULTRESET | 0x0080 | Fault reset command |
The statusword object 0x6041 is used to get the current state of the CiA402 state machine for Axis 1.
| Bit | Description |
|---|---|
| 0 | Ready to switch on |
| 1 | Switched on |
| 2 | Operation enabled |
| 3 | Fault |
| 4 | Voltage enabled |
| 5 | Quick Stop |
| 6 | Switch on disabled |
These defines are available to interpret the FSA states.
| Define | Value | Description |
|---|---|---|
| STATUSWORD_STATE_NOTREADYTOSWITCHON | 0x0000 | Not ready to switch on |
| STATUSWORD_STATE_SWITCHEDONDISABLED | 0x0040 | Switched on but disabled |
| STATUSWORD_STATE_READYTOSWITCHON | 0x0021 | Ready to switch on |
| STATUSWORD_STATE_SWITCHEDON | 0x0023 | Switched on |
| STATUSWORD_STATE_OPERATIONENABLED | 0x0027 | Operation enabled |
| STATUSWORD_STATE_QUICKSTOPACTIVE | 0x0007 | Quickstop active |
| STATUSWORD_STATE_FAULTREACTIONACTIVE | 0x000F | Fault reaction active |
| STATUSWORD_STATE_FAULT | 0x0008 | Fault state |
These modes are recommended to be supported by the drives:
| Operation mode | Code |
|---|---|
| Profile position mode | 1 |
| Velocity mode | 2 |
| Profile velocity mode | 3 |
| Torque profile mode | 4 |
| Homing mode | 6 |
| Interpolated position mode | 7 |
| Cyclic synchronous position mode | 8 |
| Cyclic synchronous velocity mode | 9 |
| Cyclic synchronous torque mode | 10 |
| Cyclic synchronous torque mode with commutation angle | 11 |
The mode of operation object 0x6060 is used to request an operation mode for Axis 1.
The mode of operation display object 0x6061 is used to get the current operation mode for Axis 1.
The target position object 0x607A is used to request the target position for Axis 1.
The position actual value object 0x6064 gets the drive's current position for Axis 1.
The target velocity object 0x60FF is used to request the target velocity for Axis 1.
The velocity actual value object 0x606C gets the drive's current velocity for Axis 1.
The target torque object 0x6071 is used to request the target torque for Axis 1.
The torque actual value object 0x6077 gets the drive's current torque for Axis 1.
These are the objects that must be written to the drive to command a specific operation.
| Index | Description |
|---|---|
| 0x6040 | Controlword |
| 0x6060 | Operation mode |
| 0x607A | Target position |
| 0x60FF | Target velocity |
| 0x6071 | Target torque |
These are the objects that must be read to get the current status of the drive.
| Index | Description |
|---|---|
| 0x6041 | Statusword |
| 0x6061 | Operation mode display |
| 0x6064 | Position actual value |
| 0x606C | Velocity actual value |
| 0x6077 | Torque actual value |
The rest of the axis and other operation modes can be configured following the same steps described above. Furthermore, there are more objects used for the drive application but this example covers only the basic configuration. Please refer to the ETG6010 document for a detailed description of the CiA402 directive.
To test the Cyclic Synchronous Position (CSP) mode in TwinCAT NC:Online configurations, please follow the below steps.
Below are the steps to test the Cyclic Synchronous Velocity (CSV) mode in TwinCAT NC:Online configurations.
Below are the steps to be followed to extend the CiA402 example to 6-axis motor control application.
Each additional axis needs 27952 bytes of heap memory for creating the objects such as controlword, statusword, quick stop, shutdown, mode of operation, position actual value, velocity actual value and more. Also, RxPDOs/TxPDOs, CoE object dictionary consumes some memory. Hence it is required to increase the heap memory size. For 6-axis control, the minimum heap size required would be 229376 bytes.
Similarly, the CiA402 example can be extended to 9-axis motor control application. For 9-axis control, the minimum heap size required would be 327680 bytes. Make sure that the size of MSRAM memory region is increased.
Below are the steps to be followed to register your custom CiA402 state machine.
The first step is to create a custom CiA402 state machine to be registered later by following the instructions at Register Custom CiA402 State Machine.
The custom CiA402 state machine function should be created as per the below function prototype defined in ind_comms_sdk_am64x_2025_00_XX/source/industrial_comms/ethercat_subdevice/stack/inc/ecSlvApi_types.h file.
Create a custom CiA402 state machine function in ind_comms_sdk_am64x_2025_00_XX/examples/industrial_comms/ethercat_subdevice_demo/device_profiles/402_cia/ESL_cia402Demo.c file.
Below code snippet serves as a 'sample' custom CiA402 state machine function implementation in ind_comms_sdk_am64x_2025_00_XX/examples/industrial_comms/ethercat_subdevice_demo/device_profiles/402_cia/ESL_cia402Demo.c file for your reference.
⚠️ This 'sample' CiA402 state machine function is not implemented in ESL_cia402Demo.c file available in ind_comms_sdk_am64x_2025_00_XX. By default, the EtherCAT stack internal CiA402 state machine shall be active.
Once the custom CiA402 state machine is created, you can register and activate it by following the below instructions.
Use the below API available in the ind_comms_sdk_am64x_2025_00_XX/source/industrial_comms/ethercat_subdevice/stack/inc/profiles/ecSlvApi_CiA402.h to register your custom CiA402 state machine function.
Call this API in EC_SLV_APP_populateCiA402Functions() in ind_comms_sdk_am64x_2025_00_XX/examples/industrial_comms/ethercat_subdevice_demo/device_profiles/402_cia/ecSubDeviceCiA402.c file, to register your custom CiA402 state machine function.
⚠️ When a custom CiA402 state machine is registered, the default EtherCAT stack internal CiA402 state machine shall be deactivated.