F29H85x-SDK  26.00.00
 
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:

Note

Initial setup required for all EtherCAT examples

Make the following changes in the file : C:\ti\f29h85x-sdk_x\examples\device_support\include\device.h

  • Uncomment: #define USE_PLL_SRC_XTAL
  • Comment: #define USE_PLL_SRC_INTOSC

    Note: This change applies to all EtherCAT examples since they share this common header file.

CPU1 PDI HAL Test Example

  • This example sets up EtherCAT to be allocated to CPU1 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 - Both controlCARD LEDs (D1,D2) are on (not flashing)
    • Fail Signal - Both controlCARD LEDs (D1,D2) are flashing
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 f29h85x_cpu1_pdi_hal_test_app
  4. Select the RAM build configuration and build the example
  5. Load the example to the controlCARD and run the application
    Note
    Important: If another EtherCAT example was loaded previously and the controlCARD hasn’t been power cycled since, make sure to power cycle the controlCARD before running this example
  6. If this your first time running any EtherCAT code on the controlCARD, 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 ControlCard EEPROM on how to program the EEPROM
  7. Once EEPROM is programmed or re-programmed for the correct core, reset the CPU and restart the example.
  8. Set a breakpoint on ESC_debugUpdateESCRegLogs() in pdi_test_app.c and the CPU should hit the breakpoint. The pass signal should be indicated by the controlCARD LEDs. If not, pause the execution and investigate further.
  9. 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.
  10. 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.

CPU1 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: (Example External Connections)
  4. Run ethercat_subdevice_ssc_and_demo_setup.exe installer to extract the F29H85x SSC configuration and echoback application files required by the SSC tool. These will be located in the newly created ssc_configuration directory.
  5. Open the SSC tool and a New Project dialog box will open. Select Import and locate the f29x_ssc_config.xml. Then click Open.
  6. Use the Custom drop-down menu to select TI F29H85x CPU1 Echoback Solution and click OK.

    SSC Configuration Window
  7. Click Yes when the pop up window asks about requiring external files to proceed.
  8. Save the SSC project.
  9. Within SSC tool, go to Project -> Create new SubordinateDevice Files
    • Change the Source Folder directory to the ~/examples/f29h85x_cpu1_echoback_solution directory.
    • Leave the ESI file directory location as is.
    • Click Start and then OK.
  10. Import the example from ~/examples/f29h85x_cpu1_echoback_solution into CCS and build it for RAM.
  11. Within CCS, verify to be in the CCS Debug view and connect to CPU1.
  12. Once connected to CPU1, go to Run -> Load -> Load Program and select f29h85x_cpu1_echoback_solution.out. Then click Resume.
  13. Copy the ESI file (F29H85x CPU1 EtherCAT SubDevice.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.
  14. Refer to Program ControlCard EEPROM on how to program the EEPROM.
  15. 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, rescan for devices, and restart TwinCAT in config mode

      Twincat Restart in Config Mode
  16. 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
  17. Within TwinCAT, expand the explorer to the EtherCAT box and find the various output/input mappings.

    TwinCAT Solution Explorer Inputs and Outputs
  18. 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.
  19. 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.

CPU1 EEPROM EMU and DC Demo

  • The f29h85x_cpu1_dc_eepromemu_echoback_solution project showcases the distributed clocks feature of EtherCAT. It also gives an example for EEPROM emulation and writing to PHY registers through the MDIO interface with the F29H85X device.
  • This project synchronizes PWMs across EtherCAT subordinate Devices by using the sync0 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 CPU1 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-8 from CPU1 Echoback Solution Example to generate ESI file. Copy the ESI file (F29H85X CPU1 EtherCAT SubDevice.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.
  3. Within SSC tool, go to Project -> Create new SubordinateDevice Files
    • Change the Source Folder directory to the f29h85x-sdk\examples\communication\Ethercat\examples\f29h85x_cpu1_dc_eepromemu_echoback_solution directory.
    • Leave the ESI file directory location as is.
    • Click Start and then OK.
    • Copy all files from the generated source folder (f29h85x-sdk\examples\communication\Ethercat\examples\f29h85x_cpu1_dc_eepromemu_echoback_solution\Src)in f29h85x-sdk\examples\communication\Ethercat\examples\f29h85x_cpu1_dc_eepromemu_echoback_solution directory.
  4. Import the f29h85x_cpu1_dc_eepromemu_echoback_solution project into your CCS workspace, change build configuration to Flash and change optimization to 0 (Right-click project → Properties → Build → C2000 Compiler → Optimization → Set "0" in Select optimization paradigm/level (-O) → Apply → OK. )
  5. Open ecat_dc_synchronization.syscfg and select the board type F29H85x controlSOM with HSEC180ADAPEVM adapter and deselect Lock Resource Allocation and select confirm and save the file.

    Selecting board type (Step 1).


    Selecting board type (Step 2).
  6. Within CCS, click the debug button, make sure to only select CPU1 for the target core
  7. Refer Setup TwinCAT on how to create a TwinCAT project
  8. Refer to Program ControlCard EEPROM on how to program the EEPROM
  9. Once EEPROM is programmed, do the following
    • Disconnect and power cycle the F29H85X board
    • Reconnect board to TwinCAT
    • Right click on existing devices and remove them
    • Rescan for devices, Scan for boxes, do not enable free run mode
  10. 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
  11. If you have both F29H85x CPU1 EtherCAT Subordinate Device and F28P65x CPU1 EtherCAT SubDevice.xml present in C:/TwinCAT/3.1/Config/Io/EtherCAT directory you may see your F29H85X being shown as F28P65X.To resolve this , Right click on the box-> Change to Compatible Type... ->Select F2985x option and click ok.

    Changing Compatiblity
  12. 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
  1. 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
  2. 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" (c) Select one of the outputs from the task

    LED Process Data Mapping
  3. Follow these steps for each subordinate device
    • Click on the box #
    • Navigate to DC menu
    • Choose DC-Synchron
    • Setup your sync0 timings
  4. 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

  5. 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
  6. Observe your synchronized PWM Signals on GPIO48 (HSEC pin 155)!
    • Alternatively, observe Sync0 signal connected by hardware to GPIO34 (HSEC pin 74).

NOTE: The below snippet enables EEPROM Emulation. If you do not want to use EEPROM emulation, comment out this line, and make sure that the correct pins are being used for ESC I2C.

EEPROM Emulation Note

CPU1 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: (Example External Connections)
  4. Run ethercat_subdevice_ssc_and_demo_setup.exe installer to extract the F29H85x SSC configuration and echoback application files required by the SSC tool. These will be located in the newly created ssc_configuration directory.
  5. Open the SSC tool and a New Project dialog box will open. Select Import and locate the f29h85x_ssc_config.xml. Then click Open.
  6. Use the Custom drop-down menu to select TI F29H85x CPU1 Sample (the one WITHOUT the sample application) and click OK.

    SSC Configuration Window
  7. Click Yes when the pop up window asks about requiring external files to proceed.
  8. In the subdevice Project Navigation, select Application and for the CiA402_DEVICE subdevice setting, set the value to 1.

    SSC Application Window
  9. Save the SSC project.
  10. Within SSC tool, go to Project -> Create new subdevice Files
    • Change the Source Folder directory to the ~/examples/f29h85x_cpu1_cia402_solution directory.
    • Leave the ESI file directory location as is.
    • Click Start and then OK.
  11. Import the example from ~/examples/f29h85x_cpu1_cia402_solution into CCS and build it for RAM
  12. Within CCS, verify to be in the CCS Debug view and connect to the CPU1 core.
  13. Once connected to the CPU1 core, go to Run -> Load -> Load Program and select f29h85x_cpu1_cia402_solution.out. Then click Resume.
  14. Copy the ESI file (F29H85x CPU1 EtherCAT subdevice.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.
  15. Refer to Program ControlCard EEPROM on how to program the EEPROM (can follow the echoback example steps).
  16. 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
  17. 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
  18. 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
  19. 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

CPU1 FoE Download Solution Example

This example requires application and subdevice stack files to be generated via the SSC tool before building/running. This example emulates a transfer of data from the Master to the subdevice using FoE Protocol. Dummy data is sent from the master using TwinCAT, which is received by the subdevice and can be read from the memory using Code Composer Studio.

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: (Example External Connections)
  4. Run ethercat_subdevice_ssc_and_demo_setup.exe installer to extract the F29H85x SSC configuration and echoback application files required by the SSC tool. These will be located in the newly created ssc_configuration directory.
  5. Open the SSC tool and a New Project dialog box will open. Select Import and locate the f29h85x_ssc_config.xml. Then click Open.
  6. Use the Custom drop-down menu to select TI F29H85x CPU1 FoE Download Solution and click OK.

    SSC Configuration Window
  7. Click Yes when the pop up window asks about requiring external files to proceed.
  8. Save the SSC project.
  9. Within SSC tool, go to Project -> Create new subdevice Files
    • Change the Source Folder directory to the ~/examples/f29h85x_cpu1_echoback_solution directory.
    • Leave the ESI file directory location as is.
    • Click Start and then OK.
  10. Import the example from ~/examples/f29h85x_cpu1_foe_download_solution into CCS and build it for RAM or FLASH.
  11. Within CCS, verify to be in the CCS Debug view and connect to CPU1.
  12. Once connected to CPU1, go to Run -> Load -> Load Program and select f29h85x_cpu1_foe_download_solution.out. Then click Resume.
  13. Copy the ESI file (F29H85x CPU1 EtherCAT subdevice (FoE).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.
  14. Refer to Program ControlCard EEPROM on how to program the EEPROM.
  15. 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, rescan for devices, and restart TwinCAT in config mode
    Twincat Restart in Config Mode
  16. 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
  17. Select Bootstrap under the Online tab, to change the EtherCAT subdevice to BOOT mode. (FoE transfer is only possible in BOOT mode)
  18. In order to choose the file to be sent from the master to the subdevice
    • Scroll down on the Online tab and under File Access over EtherCAT, click download.
    • Within C2000ware, browse for the file test.bin from the ~/EtherCAT/f29h85x/ssc_configuration/test directory and click Open.
    • Click OK.
  19. To verify that the file has been transferred, the memory contents can be verified in CCS.
    • In CCS, halt the execution and click on View->Memory Browser
    • In the box next to the field "Data", enter the address of the memory location to be accessed (0x20110000U as set in tiescfoe.c for this example)
    • In the drop-down menu below, select "Packed Char" to directly see the contents of the .bin file stored in the memory.