Getting Started Using Examples

This chapter details how to get setup and begin using the EtherCAT examples. These instructions use Beckhoff’s TwinCAT as the EtherCAT MainDevice. The EtherCAT software includes the following:

PDI Test Example

  • This example sets up EtherCAT to be allocated to CPU and configures the required EtherCAT GPIOs and clocking. Additionally, the example performs a series of reads and writes to the full range of EtherCAT RAM using the HAL APIs. These can be observed from the CCS memory browser or TwinCAT ESC memory browser.

  • This example is self-checking when performing the reads and writes. The following details the pass and fail signals:

    • Pass Signal – LED D4 (ESC_LED_RUN) is off (not flashing). User LED8 (Green) is on (additional LED configured for PDI test in syscfg).

    • Fail Signal – LED D4 (ESC_LED_RUN) is flashing. User LED7 (Red) is flashing (additional LED configured for PDI test in syscfg).

Note

The intent of this project is to demonstrate the usage of the PDI. Therefore, no EtherCAT stack is included in this demo.

  1. First, TwinCAT must be installed and setup. Refer Setup TwinCAT

  2. Check your external connections.

  3. Open CCS and import the example “pdi_test”

  4. Right click pdi_test project and click Debug. Once program is loaded press then click continue.

    Note

    Important: If another EtherCAT example was loaded previously and the launchpad hasn’t been power cycled since, make sure to power cycle the launchpad before running this example

  5. If this your first time running any EtherCAT code on the launchpad, the LEDs should be indicating a fail signal.

    • This failure is occurring because the minimum required EtherCAT EEPROM locations aren’t programmed yet.

    • Refer Program launchpad EEPROM on how to program the EEPROM

  6. Once EEPROM is programmed or re-programmed for the correct core, reset the CPU and restart the example.

  7. Set a breakpoint on ESC_debugUpdateESCRegLogs() in main.c and the CPU should hit the breakpoint. The pass signal should be indicated by the launchpad LEDs. If not, pause the execution and investigate further.

  8. The ESC_debugUpdateESCRegLogs() will continually update the ESC_escRegs data structure with the EtherCAT register and RAM values added for monitoring as part of ESC_setupPDITestInterface(). This data structure can be viewed using the CCS Expressions window.

  9. You can now restart the example and set various breakpoints within ESC_setupPDITestInterface() to observe the reads/writes from CCS as well as the TwinCAT MainDevice memory window. Additionally, you can change values via either interface to introduce failures in the PDI test. Refer Use TwinCAT Memory Window for information on using the TwinCAT MainDevice memory window.

Echoback Solution Example

  • This example requires application and SubordinateDevice stack files to be generated via the SSC tool before building/running.

  • This example emulates a bank of switches (inputs) and LEDs (outputs). The EtherCAT MainDevice controls the LEDs’ states and the EtherCAT SubordinateDevice loops back the virtual LED signals into the virtual switches so that the MainDevice can read back the LED output state.

Steps to Run the Example

  1. First, TwinCAT must be installed and setup. Refer to Setup TwinCAT.

  2. Install the SSC tool V5.13

    • Important: Only V5.13 is supported. Only download this version.

    • Download at ETG SSC ET9300

  3. Check your external connections: (EXTERNAL_CONNECTIONS)

  4. Open the SSC tool and a New Project dialog box will open. Select Import and locate the am13e232_ssc_config.xml present in mcu_sdk/solutions/networking/ethercat/ssc_configuration. Then click Open.

  5. Use the Custom drop-down menu to select TI AM13E232x Echoback Solution and click OK.

    ../../../../_images/ssc_configuration.jpg

    SSC Configuration Window

  6. Click Yes when the pop up window asks about requiring external files to proceed.

  7. Within SSC tool, go to Project -> Create new Slave Files

    • Change the Save Folder directory to the mcu_sdk/solutions/networking/ethercat/examples/echoback_solution/stack directory.

    • Click Start and then OK.

  8. Import the example from mcu_sdk/solutions/networking/ethercat/examples/echoback_solution into CCS and build it.

  9. Right click the echoback_solution project and click Debug. Once program is loaded press then click continue.

  10. Copy the ESI file (AM13E232x EtherCAT Subordinate Device.xml) generated by the SSC tool into the TwinCAT directory (Default location: C:/TwinCAT/3.1/Config/Io/EtherCAT) If the TwinCAT application is already opened, it must first be closed and re-opened for the ESI file to be discovered.

  11. Refer to Program launchpad EEPROM on how to program the EEPROM.

  12. Once EEPROM is programmed, do the following:

    • Disconnect and power cycle the board

    • Reload the application and press Resume in the CCS debug perspective to start running the code.

    • Reconnect to board to TwinCAT, rescan for devices, and restart TwinCAT in config mode

    ../../../../_images/twincat_restart.jpg

    Twincat Restart in Config Mode

  13. Within TwinCAT, double-click on the discovered EtherCAT box and observe that the EtherCAT SubordinateDevice is running in OP mode.

    ../../../../_images/twincat_box_op.jpg

    EtherCAT SubordinateDevice in OP Mode

  14. Within TwinCAT, expand the explorer to the EtherCAT box and find the various output/input mappings.

    ../../../../_images/twincat_box_inputs_outputs.jpg

    TwinCAT Solution Explorer Inputs and Outputs

  15. Select the LEDS process data mapping in the solution explorer and in the window on the right, you can change the value of any of the virtual LEDs. Switch to the switches process data mapping to see the looped back values. For example, if LED1 is set to 1, then Switch1 should also be 1.

  16. Select the Output mapping 1 in the solution explorer and in the window on the right, you can change the values of the 3 data variables. Once set, the looped back value can be observed from the Input mapping 1 variables.

DC Echoback

  • The dc_echoback_solution project showcases the distributed clocks feature of EtherCAT.

  • This project synchronizes PWMs across EtherCAT subordinate Devices by using the sync1 signal as the sync source for the PWMs. You will need to use at least two subordinate devices for this demo. It is recommended to try the Echoback Solution Example before trying this example

Steps to Run the Example

  1. Set up the hardware by connect the subordinate devices and the main device. P0 should be connected to the main device side of the chain, P1 should be connected towards the downstream subordinate devices.

  2. Follow steps 1-6 from CPU1 Echoback Solution Example to generate ESI file. Copy the ESI file (AM13E232x EtherCAT Subordinate Device.xml) generated by the SSC tool into the TwinCAT directory (Default location: C:/TwinCAT/3.1/Config/Io/EtherCAT). If the TwinCAT application is already opened, it must first be closed and re-opened for the ESI file to be discovered. ( This configuration has DC_Supported enabled by default.)

    ../../../../_images/dc_support.jpg

    DC Support

  3. Within SSC tool, go to Project -> Create new Slave Files

    • Change the Save Folder directory to the C:\ti\mcu_sdk\solutions\networking\ethercat\examples\dc_echoback_solution\stack directory.

    • Click Start and then OK.

  4. Import the dc_echoback_solution project into your CCS workspace.

  5. Within CCS, expand the dc_echoback_solution_am13e232x_lp_m33_nortos_ti_arm_clang project and open AM13E232N9.ccxml.

  6. For each additional device add New connection select Texas Instruments XDS110 USB Debug Probe.

  7. Select the newly created connection and click Add Device. Select your connected device , for example AM13E232N9.

  8. Get serial number for the devices connected by running xdsdfu.exe -e command from C:\ti\ccs2051\ccs\ccs_base\common\uscif\xds110> directory.

    ../../../../_images/xds.jpg

    XDS

  9. Serial number can be changed incase if they share same serial number, follow these steps:

    • run this command to set required device to dfu mode xdsdfu.exe -m -i 0 ( 0 refers to the first device)

    • set the serial number with the following command x -s AL130000 -r where AL130000 is the serial number selected by you

  10. For each device in Debug Probe Selection option , select “Select by serial number” and specify the serial number. Save the changes.

    ../../../../_images/target_config.jpg

    Target Configuration

  11. Right click .ccxml file and click Start Project-less Debug. Right click each device and click Connect Target.

  12. For each device load the program by going to Run->Load->Load Program->Workspace and select the dc_echoback_solution_am13e232x_lp_m33_nortos_ti_arm_clang.out and press ok. Press the continue button to run the program.

  13. Refer Setup TwinCAT on how to create a TwinCAT project

  14. Refer to Program launchpad EEPROM on how to program the EEPROM

  15. Once EEPROM is programmed, do the following:

    • Disconnect and power cycle the board and reload the program.

    • Reconnect board to TwinCAT

    • Right click on existing devices and remove them

    • Rescan for devices, Scan for boxes, do not enable free run mode

  16. At this point, you should see the following under the “Device” menu, though the device # may be different. Clicking on the device # shows the menu for the main device, clicking on each box will bring up a menu for each subordinate device.

    ../../../../_images/devices_twincat.jpg

    Device Menu Display

  17. Expand the SYSTEM Menu, right-click on “Tasks”, select “Add New Item”, then select “TwinCAT task with images”. The new task should look like Task 1.

    ../../../../_images/image-point11.jpg

    TwinCAT Task Creation

  18. Under your new task, right-click on “Outputs”, select “Add new item”, then add 3 new output variables of data type BIT.

    ../../../../_images/image-point12.jpg

    Adding Output Variables

    ../../../../_images/output_variable.jpg

    Output Variables Configuration

  19. Under each Box for your subordinate devices, expand the list “LEDS process data mapping”. Follow these instructions for each box to link one output from the box to an output from your created task: (a) Right click on LED1 (b) Select “change link” © Select one of the outputs from the task

    ../../../../_images/data_map.jpg

    LED Process Data Mapping

  20. Follow these steps for each subordinate device

    • Click on the box #

    • Navigate to DC menu

    • Choose DC-Synchron. Go to Adanced Settings

    • Select Enable SYNC 1

    • Setup your sync1 timings

  21. In the toolbar, click on Activate Configuration

    • Select yes to restart TwinCAT in run mode

    ../../../../_images/image-point15.jpg

    Activate Configuration

    (a) Select yes to restart TwinCAT in run mode

  22. Go to main Device menu by clicking on Device #

    • Go to EtherCAT menu tab

    • Select Advanced Settings

    • Expand the Distributed Clocks dropdown

    • Select Slave Diagnosis

    • Under DC Diagnosis Control, click “Start”

    • Select Yes to enable DC Diagnosis for all frames

    • Select Yes to activate configuration and yes for restart in Run Mode

  23. Observe your synchronized MCPWM Signals on GPIO PC15! (This pin in configured in MCPWM PinMux in syscfg)

    • Alternatively, observe Sync1 signal connected by hardware to GPIO PD5

CiA402 Solution Example

This example requires application and subdevice stack files to be generated via the SSC tool before building/running. This example integrates the sample CiA402 application from Beckhoff.

Steps to Run the Example

  1. First, TwinCAT must be installed and setup. Refer to Setup TwinCAT.

  2. Install the SSC tool V5.13

    • Important: Only V5.13 is supported. Only download this version.

    • Download at ETG SSC ET9300

  3. Check your external connections: (EXTERNAL_CONNECTIONS)

  4. Open the SSC tool and a New Project dialog box will open. Select Import and locate the am13e232_ssc_config.xml. Then click Open.

  5. Use the Custom drop-down menu to select TI AM13E232x Sample and click OK.

    ../../../../_images/ssc_configuration.jpg

    SSC Configuration Window

  6. Click Yes when the pop up window asks about requiring external files to proceed.

  7. In the subdevice Project Navigation, select Application and for the CiA402_DEVICE subdevice setting, set the value to 1.

    ../../../../_images/cia402_ssc_app_enable.jpg

    SSC Application Window

  8. Within SSC tool, go to Project -> Create new Slave Files

    • Change the Save Folder directory to the mcu_sdk\solutions\networking\ethercat\examples\cia402_solution\stack directory.

    • Click Start and then OK.

  9. Import the example from mcu_sdk\solutions\networking\ethercat\examples\cia402_solution into CCS.

  10. Right click the cia402_solution project and click Debug. Once program is loaded press then click continue.

  11. Copy the ESI file (AM13E232x EtherCAT Subordinate Device.xml) generated by the SSC tool into the TwinCAT directory (Default location: C:/TwinCAT/3.1/Config/Io/EtherCAT) If the TwinCAT application is already opened, it must first be closed and re-opened for the ESI file to be discovered.

  12. Refer to Program launchpad EEPROM on how to program the EEPROM (can follow the echoback example steps).

  13. Once EEPROM is programmed, do the following:

    • Disconnect and power cycle the board

    • Reload CPU1 application and press Resume in the CCS debug perspective to start running the code.

    • Reconnect to board to TwinCAT and rescan for devices

    ../../../../_images/twincat_restart.jpg

    Twincat Restart in Config Mode

  14. With the ESI indicating CiA402 support, TwinCAT will ask about how to append the linked axis. Select whichever makes sense for your axis.

    ../../../../_images/cia402_twincat_drives.jpg

    TwinCAT Drives Configuration

  15. Within TwinCAT, double-click on the discovered EtherCAT box and observe that the EtherCAT subdevice is running in OP mode.

    ../../../../_images/twincat_box_op.jpg

    EtherCAT SubordinateDevice in OP Mode

  16. For further details on configuring and running this example as well as details on the CiA402 drive profile objects refer to Chapter 10 in the following Beckhoff document: Application Note ET9300 (EtherCAT subdevice Stack Code)

    • Any questions regarding the CiA402 sample implementation, post on the ETG developer forums: Link

CiA402 Solution FreeRTOS Example

This example requires application and subdevice stack files to be generated via the SSC tool before building/running. This example integrates the sample CiA402 application from Beckhoff.

Steps to Run the Example

  1. First, TwinCAT must be installed and setup. Refer to Setup TwinCAT.

  2. Install the SSC tool V5.13

    • Important: Only V5.13 is supported. Only download this version.

    • Download at ETG SSC ET9300

  3. Check your external connections: (EXTERNAL_CONNECTIONS)

  4. Open the SSC tool and a New Project dialog box will open. Select Import and locate the am13e232_ssc_config.xml. Then click Open.

  5. Use the Custom drop-down menu to select TI AM13E232x Sample and click OK.

    ../../../../_images/ssc_configuration.jpg

    SSC Configuration Window

  6. Click Yes when the pop up window asks about requiring external files to proceed.

  7. In the subdevice Project Navigation, select Application and for the CiA402_DEVICE subdevice setting, set the value to 1. Also select USE_DEFAULT_MAIN and set the value to 0

    ../../../../_images/cia402_freertos_ssc_app_enable.jpg

    SSC Application Window

  8. Within SSC tool, go to Project -> Create new Slave Files

    • Change the Save Folder directory to the mcu_sdk\solutions\networking\ethercat\examples\cia402_solution_freertos\stack directory.

    • Click Start and then OK.

  9. Import the example from mcu_sdk\solutions\networking\ethercat\examples\cia402_solution_freertos into CCS.

  10. Right click the cia402_solution project and click Debug. Once program is loaded press then click continue.

  11. Copy the ESI file (AM13E232x EtherCAT Subordinate Device.xml) generated by the SSC tool into the TwinCAT directory (Default location: C:/TwinCAT/3.1/Config/Io/EtherCAT) If the TwinCAT application is already opened, it must first be closed and re-opened for the ESI file to be discovered.

  12. Refer to Program launchpad EEPROM on how to program the EEPROM (can follow the echoback example steps).

  13. Once EEPROM is programmed, do the following:

    • Disconnect and power cycle the board

    • Reload CPU1 application and press Resume in the CCS debug perspective to start running the code.

    • Reconnect to board to TwinCAT and rescan for devices

    ../../../../_images/twincat_restart.jpg

    Twincat Restart in Config Mode

  14. With the ESI indicating CiA402 support, TwinCAT will ask about how to append the linked axis. Select whichever makes sense for your axis.

    ../../../../_images/cia402_twincat_drives.jpg

    TwinCAT Drives Configuration

  15. Within TwinCAT, double-click on the discovered EtherCAT box and observe that the EtherCAT subdevice is running in OP mode.

    ../../../../_images/twincat_box_op.jpg

    EtherCAT SubordinateDevice in OP Mode

  16. For further details on configuring and running this example as well as details on the CiA402 drive profile objects refer to Chapter 10 in the following Beckhoff document: Application Note ET9300 (EtherCAT subdevice Stack Code)

    • Any questions regarding the CiA402 sample implementation, post on the ETG developer forums: Link