EtherCAT Slave  1.06.01
CiA 402 Example

Scope

This example covers how to load an ESI File to the SDK and how to enable the CiA 402 device profile.

Related Files

ecSlvCiA402.c
ecSlvCiA402.h
ESL_cia402Demo.c
ESL_cia402Demo.h
ESL_cia402Obd.c
ESL_cia402Obd.h
EtherCAT_Slave_CiA402.c

CiA 402 Example

This example configures a 3 axes motor control application. If the device or the ESI file (EtherCAT Slave Information) does not support the CiA 402 device profile, the subsequent registration calls should be disabled. The following functions are implemented in ESL_cia402Demo.c.

EC_SLV_APP_motionControl

Motion control is done in this function. The control of modes CSP, CSV or CST is shown.

EC_SLV_APP_cia402Application

The function contains an implementation of the CiA 402 State Machine (although an external one can be registered). This state machine works alongside the CiA 402 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.

EC_SLV_APP_cia402LocalError

If the CiA 402 State machine changes to an error state this function is called. It is used to notify the error, not to take any action.

Basic Setup

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_Slave_ESI_Parser.c.

Hardware Setup

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 ecSlvESI.c.

Next PHY parameters, such as address, polarity and RX link are configured in EC_SLV_APP_registerStacklessBoardFunctions. The KUNBUS EtherCAT SDK supports Texas Instruments TLK105, TLK110 and Microchip KSZ8041NL PHYs by default. Alternative PHYs may be used. In this case the SDK user has to implement and register the functions to handle the new PHYs. Use the ESL_phyLibTlk110 sources as reference to implement your own PHY driver.

Program flow of the EtherCAT Slave ESI Parser Example Application

Initialization of Stack, PRU, and Device Identification

Before entering the main stack loop, the example application itself is initialized in EC_SLV_APP_applicationInit. This function creates a new EtherCAT Slave device instance, registers a board status LED callback, sets vendor ID, product code and name, revision number, etc.

Program flow of the EtherCAT Slave ESI Parser Example Application

After the basic initialization, EC_SLV_APP_applicationInit contiues with the setup of the CiA 402 example drives and motion control example.

CiA 402 Example

This example configures a 3 axes motor control application. If the device or the ESI file (EtherCAT Slave Information) does not support the CiA 402 device profile, the subsequent registration calls should be disabled. The following functions are implemented in ESL_cia402Demo.c.

EC_SLV_APP_motionControl

If the ESI parser is used (see below), then the Object Dictionary is generated and configured based on the information contained in the EtherCAT Slave Information file. However, if the parser is not used or the ESI file does not contain information, use this function to set the data of the CiA 402 objects.

EC_SLV_APP_cia402Application

Application example from the Beckhoff EtherCAT Slave Code. The function contains an implementation of the CiA 402 State Machine (although an external one can be registered). This state machine works alongside the CiA 402 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.

EC_SLV_APP_cia402LocalError

If the CiA 402 State machine changes to an error state this function is called. It is used to notify the error, not to take any action.

EC_SLV_APP_usrStartInputHandler

Register a callback function that may be used to prevent the transition from PREOP to SAFEOP in the EtherCAT State Machine (ESM).

Here used to read the Distributed Clock registers to retrieve the Sync0 synchronization cycle time.

EC_API_SLV_parseEsiFile

EtherCAT Slave Information files (ESI) describe EtherCAT specific as well as application specific features of the slave. Every slave shall be devlivered with an EtherCAT Slave Information file. The EC_API_SLV_parseEsiFile() function parses the slave ESI file and generates automatically the EtherCAT configuration. Therefore, as the slave configuration is read from the ESI file, it is no longer required to use the device identification and basic configuration functions, Object Dictionary functions, or the Process Data mapping functions for example.

EC_SLV_APP_SetSupportedDriveModes

Defines which supported drive modes are available. See ETG6010 Chapter 6.8.1 for more information.

CiA402_TransitionAction

Called by the CiA402 Application. This function shall calculate the desired axis input values to move on a predefined ramp.

CiA402_DummyMotionControl

Simulates a drive. It updates the CiA402 Object Dictionary data.

Initialization and starting the Stacks

The EC_API_SLV_init() function initializes the SDK Stack and validates whether the user defined configuration is valid or not. If the EtherCAT configuration is valid, then object content can be written and finally, the EC_API_SLV_run() function starts the Beckhoff Stack.