Main Content

Configure EtherCAT Network by Using TwinCAT 3

Before you start this procedure, familiarize yourself with TwinCAT® 3 and its documentation.

Before configuring the network, perform the steps in Install EtherCAT Network Tools TwinCAT or EC-Engineer.

Scan EtherCAT Network

This example uses an EtherCAT® network that consists of Beckhoff® EK1100, EL3062, and EL4002 modules connected in that order.

To scan an EtherCAT network by using TwinCAT 3:

  1. Connect your EtherCAT network to the development computer Ethernet port dedicated to EtherCAT. Turn on the network.

  2. Start Microsoft® Visual Studio® and create a TwinCAT 3 project.

  3. In the TwinCAT menu, start the device scanner.

    The scanner reports that new I/O devices have been found.

  4. In the list of Ethernet devices that the scanner detects on the development computer, select the Ethernet device into which you plugged your EtherCAT network.

    If you do not see an Ethernet device identified as an EtherCAT device, check your EtherCAT network configuration and power supply.

  5. Scan for EtherCAT boxes on your network.

    The scanner reports the EtherCAT devices on your network.

  6. Disable free run mode.

  7. In your TwinCAT project, make sure that the scanner downloaded the required information about your EtherCAT devices. If not a Beckhoff device, you could need the EtherCAT SubDevice Information (ESI) file from the device vendor.

Configure EtherCAT Main Device Node Data

Before configuring the main device node of an EtherCAT network, scan the network by using TwinCAT.

Create EtherCAT Task

To create and configure an EtherCAT task:

  1. In TwinCAT 3, add an item to your system task list.

    In the Solution Explorer display tree, open the SYSTEM subtree and use a right-click on the Tasks entry and choose Add New Item. In the new dialog, select TwinCAT Task With Image. This allows you to add variables to the task PDO.

    Provide a name for the task, for example Task 1. Configure Task 1 as a task with an image.

  2. In the task list, select Task 1 and set its cycle ticks value to a value in milliseconds, such as 1 for 1 millisecond.

  3. Record the cycle tick in milliseconds.

    In the Model Configuration Parameters dialog box, use the cycle tick to calculate a value for the Fixed-step size (fundamental sample time) box. To enable Simulink® to calculate the sample time, select Auto.

Configure EtherCAT Task Inputs

To configure the task inputs:

  1. In TwinCAT 3, under Term 1, access the nodes Term 2 and AI Standard Channel 1.

  2. Drag the Value node of AI Standard Channel 1 to the Task 1 inputs.

  3. Configure the Term 1 inputs as variables.

  4. Link the AI Standard Channel 1 variable to Term 2.

Adding a variable to the task you created requires that you:

  1. Add an empty variable to the task with the same type as the PDO variable you want to add.

  2. Link it to the PDO variable that you want to add to the task from that task entry using the Linked to... button.

Adding any one variable from a specific subordinate device adds all PDO variables from that subordinate device to the task. For instance, with the EL3102 Analog Input module:

  1. Left-click on your task Inputs entry and select Add New Item. The Insert Variable dialog opens.

  2. Select the data type. For the EL3102 the AD values is an INT in the list. That is a 2 byte signed integer.

  3. Change the name if needed, but this is not necessary.

  4. Click on OK

  5. A new dialog opens, click on Linked to....

  6. In the new dialog, find the EL3102. Only variables with the data type selected above are visible. Both INT and UINT appear. Select any one of the EL3102 variables. You may need to change with check boxes are active under the Show Variables or Show Variable Types lists.

  7. All of the EL3102 transmit (Input to main device stack) variables are now included in the task just by selecting one of them.

  8. Repeat for one receive (Output to subordinate device) variable for that subordinate device.

Configure EtherCAT Task Outputs

To configure the task outputs:

  1. In TwinCAT 3, under Term 1, access the nodes Term 3 and AO Outputs Channel 1.

  2. Drag the Analog output node of AO Outputs Channel 1 to the Task 1 outputs.

  3. Configure the Term 1 analog outputs as variables.

  4. Link the Analog output variable to Term 3.

Configure EtherCAT Distributed Clocks

To configure the Term 3 distributed clock:

  1. In TwinCAT 3, under Term 3, access the DC tab.

  2. Change the DC operation mode to DC Synchron.

There are two main steps to configure distributed clocks:

  1. Select the synchronization mode, either main device shift or bus shift. TwinCAT refers to these with TwinCAT centric names, not generic main device stack names.

  2. In the Solution Explorer, select I/O > Devices > Device 1 (EtherCAT)

  3. In the dialog in the right side, select the EtherCAT tab. Select the Advanced Settings button. On the left of the new dialog, select Distributed Clocks.

  4. By default TwinCAT3 has Automatic DC Mode Selection chosen. Deselect that and choose DC in use. Choose the mode you want.

  5. Independent DC Time (Main Device Mode) causes the target machine clock to be adjusted to synchronize with the first DC enabled EtherCAT subordinate device. This mode is also known as Main Device Shift DC mode.

  6. DC Time controlled by TwinCAT Time (Subordinate Device Mode) uses the target computer execution time as the reference clock and to adjust the first DC enabled subordinate device to match the target computer. This is also known as Bus Shift mode.

For each DC enabled subordinate device, you need to ensure that it is configured correctly to participate in DC synchronization. For each subordinate device:

  1. Select the subordinate device in Solution Explorer.

  2. In the dialog, select the DC tab if it is available.

  3. In the Operation Mode drop down menu, there could be several different names given. For instance DC Latch or DC Synchron are common and mean that the device synchronizes and uses DC timing. SM synchron is a common listing to mean that IO is not DC synchronized, but occurs on packet arrival (SM), not on DC time.

  4. Click the Advanced Settings button.

  5. Make sure the Enable checkbox is selected. There are additional settings that can be modified, but these are generally advanced options.

Export and Save EtherCAT Configuration by Using TwinCAT 3

The EtherCAT Network Information (ENI) file represents the main device node of an EtherCAT network. To create the ENI file, scan and configure the network by using TwinCAT 3.

To export the ENI file from TwinCAT 3:

  1. Under the Device 1 (EtherCAT) node, in the EtherCAT tab, execute the command to export the configuration file.

  2. In the file save dialog box, enter an XML file name, such as BeckhoffAIOconfig.xml.

    Caution

    The ENI file is formatted as an XML file with the .xml file extension. Building the real-time application produces an XML file with the same name as your model. To avoid a conflict, use an ENI file name that is different from the name of your model.

  3. When you close Microsoft Visual Studio TwinCAT the project file is saved.

To review or modify your configuration, open the project SLN file by using Microsoft Visual Studio. If you modify the configuration, save both the XML and SLN files.

The next task is Install EtherCAT Network for Execution.