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:
Connect your EtherCAT network to the development computer Ethernet port dedicated to EtherCAT. Turn on the network.
Start Microsoft® Visual Studio® and create a TwinCAT 3 project.
In the TwinCAT menu, start the device scanner.
The scanner reports that new I/O devices have been found.
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.
Scan for EtherCAT boxes on your network.
The scanner reports the EtherCAT devices on your network.
Disable free run mode.
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:
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
. ConfigureTask 1
as a task with an image.In the task list, select
Task 1
and set its cycle ticks value to a value in milliseconds, such as1
for1
millisecond.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:
In TwinCAT 3, under
Term 1
, access the nodesTerm 2
andAI Standard Channel 1
.Drag the
Value
node ofAI Standard Channel 1
to theTask 1
inputs.Configure the
Term 1
inputs as variables.Link the
AI Standard Channel 1
variable toTerm 2
.
Adding a variable to the task you created requires that you:
Add an empty variable to the task with the same type as the PDO variable you want to add.
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:
Left-click on your task Inputs entry and select Add New Item. The Insert Variable dialog opens.
Select the data type. For the EL3102 the AD values is an INT in the list. That is a 2 byte signed integer.
Change the name if needed, but this is not necessary.
Click on OK
A new dialog opens, click on Linked to....
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.
All of the EL3102 transmit (Input to main device stack) variables are now included in the task just by selecting one of them.
Repeat for one receive (Output to subordinate device) variable for that subordinate device.
Configure EtherCAT Task Outputs
To configure the task outputs:
In TwinCAT 3, under
Term 1
, access the nodesTerm 3
andAO Outputs Channel 1
.Drag the
Analog output
node ofAO Outputs Channel 1
to theTask 1
outputs.Configure the
Term 1
analog outputs as variables.Link the
Analog output
variable toTerm 3
.
Configure EtherCAT Distributed Clocks
To configure the Term 3
distributed clock:
In TwinCAT 3, under
Term 3
, access the DC tab.Change the DC operation mode to
DC Synchron
.
There are two main steps to configure distributed clocks:
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.
In the Solution Explorer, select I/O > Devices > Device 1 (EtherCAT)
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.
By default TwinCAT3 has Automatic DC Mode Selection chosen. Deselect that and choose DC in use. Choose the mode you want.
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.
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:
Select the subordinate device in Solution Explorer.
In the dialog, select the DC tab if it is available.
In the Operation Mode drop down menu, there could be several different names given. For instance
DC Latch
orDC 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.Click the Advanced Settings button.
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:
Under the Device 1 (EtherCAT) node, in the EtherCAT tab, execute the command to export the configuration file.
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.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.