EtherCAT Slave  1.04.06
Simple demo in TwinCAT3

EtherCAT Slave Setup with TwinCAT

The project "Simple demo" will be assumed for the steps described below.

TwinCAT

Software Installation

  1. Install TwinCAT3 on your PC. A 7 days free trial license is available for free download from the Beckhoff's software and tools website.
  2. Select the eXtended Automation Engineering (XAE) mode of installation.
  3. Copy from the installed SDK the device description ESI file(s) :

    YOUR_SDK_VERSION_DIRECTORY/source/industrial_comms/ethercat_slave/stack/esi/TI AM243X.R5F Simple

    to the TwinCAT3 directory :

    YOUR_TWINCAT_INSTALL_DIR/TwinCAT/3.1/Config/Io/EtherCAT

    Copy ESI files to the TwinCAT folder

Create TwinCAT Project

  1. Start the TwinCAT XAE Shell application.

    Start the TwinCAT XAE Shell application
  2. Create a new TwinCAT XAE Project (XML format) by going to File -> New -> Project -> TwinCAT Projects.
  3. Set the Name and click on the button OK.

    Creating a new TwinCAT Project Simple Demo

Connect to the PLC

In case you are using a PLC then the TwinCAT shall connect first to it

  1. Click in the Solution Explorer on the SYSTEM
  2. Click on the button Choose Target

  3. Click on Search (Ethernet)..

  4. Type the IP address of the PLC, e.g. 192.168.0.12. And click on the Enter Host Name /IP

    Note: The IP address and the subnet on the PC network adapter must be also properly set.

  5. A detected PLC with the host name will be shown
  6. Select the check box Advanced Settings
  7. Choose the radio button IP Address. And click on the Add Route

  8. Type login data for your PLC and click OK

  9. Click Close on the Add Route Dialog.
  10. Click OK on the Choose Target System.
  11. The PLC is now connected.

Setup a network interface controller (NIC) in the TwinCAT Project

  1. Go to TwinCAT -> Show Real Time Ethernet Compatible Devices and Install TwinCAT RT Ethernet intermediate driver.

    Show Real Time Ethernet Compatible Devices and Install TwinCAT RT Ethernet intermediate driver

    For the best performance, it is recommended to use a compatible NIC card listed in Supported Network Controller by Beckhoff Ethernet Driver .

  2. Select the network device to be connected to the the development board and close the window

    Enable selected real time ethernet compatible device
  3. The ethernet adapter should be listed in the Installed and ready to use devices before attempting to scan the slave.

    Note: If your computer go to sleep and after awake then the TwinCAT may loose a connection with slave(s) and/or may not be able to discover EtherCAT IO devices. You can fix this issue by going in the TwinCAT to your Ethernet adapters, and Disabling / Enabling your NIC.

Scanning the slave

  1. In the Solution Explorer, go to TwinCAT project -> I/O -> Devices. Right click on Devices and select Scan. Press OK in the next dialog to start scanning for EtherCAT devices.

  2. A dialog box with a hint will be shown.

    Read a text and click on the button OK.

  3. Once an EtherCAT compatible device has been detected, the following dialog shows up.

    Note: There is a tick mark next to the adapter to which the target board is connected.

  4. Press OK and confirm to start Scan for boxes.

  5. A new device will be found. Press Yes

    Note: If the related ESI file for a detected slave will not be found than please check again the TwinCAT Software Installation steps

  6. A new detected EtherCAT slave will show up in the Device tree. And a dialog box will be shown to activate a free run.

  7. Press Yes to activate the Free Run. This will put the slave into OP mode.
  8. The EtherCAT device state can be displayed by selecting a Device (Double click on Device) and then selecting the Online tab.

  9. The device should be in the OP state with no Lost Frames or Tx/Rx Errors.
  10. The user can control 4 digital output LEDs using the TwinCAT in the i2c-leds. Each LED can be turned on and off by selecting "Online write 1/2/4/8" and "Online write 0" respectively.

    Above steps test the slave in Free Run Operation Mode. For testing a Distributed Clock (DC) Synchronization mode, refer to the Testing DC Synchronization mode section.

Testing DC Synchronization mode

  1. Click on the Device n (EtherCAT). Select the tab EtherCAT.
  2. With a deactivated distributed clock (DC) these frames are exchanged LRD,LRW, ...

  3. Click on the tab Adapter and set the cycle time. For the PC choose a real time manageable value, e.g. 4ms.

  4. To see a new set cycle time value you need e.g. to go to one available slave and back.

  5. Click on the first slave Box 1 (TI ...
  6. Open the DC tab, and choose DC-Synchron option in Operation Mode. Do this for all slaves in the chain.
  7. Click on the Device n (EtherCAT). And select the tab EtherCAT.
  8. There are now two additional frames at the beginning NOP, ARMW. In the second one is transferred an actual reference time.

  9. In the Solution Explorer, go to the TwinCAT project, select SYSTEM -> Real-Time.
  10. In the Settings tab, choose the desired Base Time. With compatible NIC cards, a base time of as low as 50 us can be chosen.

  11. Right-click on SYSTEM -> Tasks. Click Add New Item on the pop-up menu.

  12. Select TwinCAT Image with Task in the next dialog box. Type a name for the task, and choose OK.

  13. In the "Task" tab for the created task, select Auto Priority Management. Press OK in dialog box saying "Global Priority Management should be turned on".

  14. Choose Auto start for the task. Choose 2 cycle ticks’ frequency for the task.

  15. Add an output variable to the task. Right-click on [Task name] -> Outputs, and choose "Add New Item".

  16. Link the variable to an output for the last slave in the chain. Right-click on [Variable name] and choose Change Link....

  17. Choose an output from the last slave. And click OK
  18. You can launch into Run mode by clicking the Activate Configuration button on the toolbar.

  19. Choose Yes to generate mapping after modifying configuration, click on OK to activate configuration, and Yes to Restart in RUN mode.