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.
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 Slave Information (ESI) file from the device vendor.
Before configuring the master node of an EtherCAT network, scan the network by using TwinCAT.
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.
Configure Task 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 as 1 for
1 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.
To configure the task inputs:
In TwinCAT 3, under Term 1, access the nodes
Term 2 and AI Standard Channel
1.
Drag the Value node of AI Standard Channel
1 to the Task 1 inputs.
Configure the Term 1 inputs as variables.
Link the AI Standard Channel 1 variable to
Term 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 slave device adds all PDO variables from that slave 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 master stack) variables are now included in the task just by selecting one of them.
Repeat for one receive (Output to slave) variable for that slave.
To configure the task outputs:
In TwinCAT 3, under Term 1, access the nodes
Term 3 and AO Outputs Channel
1.
Drag the Analog output node of AO Outputs
Channel 1 to the Task 1 outputs.
Configure the Term 1 analog outputs as
variables.
Link the Analog output variable to Term
3.
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 Master shift or bus shift. TwinCAT refers to these with TwinCAT centric names, not generic master 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 (Master Mode) causes the target machine clock to be adjusted to synchronize with the first DC enabled EtherCAT slave device. This mode is also known as Master Shift DC mode.
DC Time controlled by TwinCAT Time (Slave Mode) uses the target computer execution time as the reference clock and to adjust the first DC enabled slave to match the target computer. This is also known as Bus Shift mode.
For each DC enabled slave device, you need to ensure that it is configured correctly to participate in DC synchronization. For each slave:
Select the slave 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 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.
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.
The EtherCAT Network Information (ENI) file represents the master 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.