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.
First, TwinCAT must be installed and setup. Refer Setup TwinCAT
Check your external connections.
Open CCS and import the example “pdi_test”
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
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
Once EEPROM is programmed or re-programmed for the correct core, reset the CPU and restart the example.
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.
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.
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
First, TwinCAT must be installed and setup. Refer to Setup TwinCAT.
Install the SSC tool V5.13
Important: Only V5.13 is supported. Only download this version.
Download at ETG SSC ET9300
Check your external connections: (EXTERNAL_CONNECTIONS)
Open the SSC tool and a New Project dialog box will open. Select Import and locate the
am13e232_ssc_config.xmlpresent inmcu_sdk/solutions/networking/ethercat/ssc_configuration. Then click Open.Use the Custom drop-down menu to select TI AM13E232x Echoback Solution and click OK.
SSC Configuration Window
Click Yes when the pop up window asks about requiring external files to proceed.
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/stackdirectory.Click Start and then OK.
Import the example from
mcu_sdk/solutions/networking/ethercat/examples/echoback_solutioninto CCS and build it.Right click the echoback_solution project and click Debug. Once program is loaded press then click continue.
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.Refer to Program launchpad EEPROM on how to program the EEPROM.
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
Twincat Restart in Config Mode
Within TwinCAT, double-click on the discovered EtherCAT box and observe that the EtherCAT SubordinateDevice is running in OP mode.
EtherCAT SubordinateDevice in OP Mode
Within TwinCAT, expand the explorer to the EtherCAT box and find the various output/input mappings.
TwinCAT Solution Explorer Inputs and Outputs
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.
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
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.
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.)
DC Support
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\stackdirectory.Click Start and then OK.
Import the dc_echoback_solution project into your CCS workspace.
Within CCS, expand the
dc_echoback_solution_am13e232x_lp_m33_nortos_ti_arm_clangproject and open AM13E232N9.ccxml.For each additional device add New connection select
Texas Instruments XDS110 USB Debug Probe.Select the newly created connection and click Add Device. Select your connected device , for example
AM13E232N9.Get serial number for the devices connected by running
xdsdfu.exe -ecommand fromC:\ti\ccs2051\ccs\ccs_base\common\uscif\xds110>directory.
XDS
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 -rwhere AL130000 is the serial number selected by you
For each device in Debug Probe Selection option , select “Select by serial number” and specify the serial number. Save the changes.
Target Configuration
Right click .ccxml file and click
Start Project-less Debug. Right click each device and clickConnect Target.For each device load the program by going to
Run->Load->Load Program->Workspaceand select thedc_echoback_solution_am13e232x_lp_m33_nortos_ti_arm_clang.outand press ok. Press the continue button to run the program.Refer Setup TwinCAT on how to create a TwinCAT project
Refer to Program launchpad EEPROM on how to program the EEPROM
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
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.
Device Menu Display
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.
TwinCAT Task Creation
Under your new task, right-click on “Outputs”, select “Add new item”, then add 3 new output variables of data type BIT.
Adding Output Variables
Output Variables Configuration
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
LED Process Data Mapping
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 1Setup your sync1 timings
In the toolbar, click on Activate Configuration
Select yes to restart TwinCAT in run mode
Activate Configuration
(a) Select yes to restart TwinCAT in run mode
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
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
First, TwinCAT must be installed and setup. Refer to Setup TwinCAT.
Install the SSC tool V5.13
Important: Only V5.13 is supported. Only download this version.
Download at ETG SSC ET9300
Check your external connections: (EXTERNAL_CONNECTIONS)
Open the SSC tool and a New Project dialog box will open. Select Import and locate the
am13e232_ssc_config.xml. Then click Open.Use the Custom drop-down menu to select TI AM13E232x Sample and click OK.
SSC Configuration Window
Click Yes when the pop up window asks about requiring external files to proceed.
In the subdevice Project Navigation, select Application and for the CiA402_DEVICE subdevice setting, set the value to 1.
SSC Application Window
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\stackdirectory.Click Start and then OK.
Import the example from
mcu_sdk\solutions\networking\ethercat\examples\cia402_solutioninto CCS.Right click the cia402_solution project and click Debug. Once program is loaded press then click continue.
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.Refer to Program launchpad EEPROM on how to program the EEPROM (can follow the echoback example steps).
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
Twincat Restart in Config Mode
With the ESI indicating CiA402 support, TwinCAT will ask about how to append the linked axis. Select whichever makes sense for your axis.
TwinCAT Drives Configuration
Within TwinCAT, double-click on the discovered EtherCAT box and observe that the EtherCAT subdevice is running in OP mode.
EtherCAT SubordinateDevice in OP Mode
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
First, TwinCAT must be installed and setup. Refer to Setup TwinCAT.
Install the SSC tool V5.13
Important: Only V5.13 is supported. Only download this version.
Download at ETG SSC ET9300
Check your external connections: (EXTERNAL_CONNECTIONS)
Open the SSC tool and a New Project dialog box will open. Select Import and locate the
am13e232_ssc_config.xml. Then click Open.Use the Custom drop-down menu to select TI AM13E232x Sample and click OK.
SSC Configuration Window
Click Yes when the pop up window asks about requiring external files to proceed.
In the subdevice Project Navigation, select Application and for the CiA402_DEVICE subdevice setting, set the value to 1. Also select
USE_DEFAULT_MAINand set the value to 0
SSC Application Window
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\stackdirectory.Click Start and then OK.
Import the example from
mcu_sdk\solutions\networking\ethercat\examples\cia402_solution_freertosinto CCS.Right click the cia402_solution project and click Debug. Once program is loaded press then click continue.
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.Refer to Program launchpad EEPROM on how to program the EEPROM (can follow the echoback example steps).
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
Twincat Restart in Config Mode
With the ESI indicating CiA402 support, TwinCAT will ask about how to append the linked axis. Select whichever makes sense for your axis.
TwinCAT Drives Configuration
Within TwinCAT, double-click on the discovered EtherCAT box and observe that the EtherCAT subdevice is running in OP mode.
EtherCAT SubordinateDevice in OP Mode
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