ConfigureEtherCATNetwork by UsingTwinCAT3
Before you start this procedure, familiarize yourself with TwinCAT®3 and its documentation.
Before configuring the network, perform the steps inInstall EtherCAT Network Tools TwinCAT or EC-Engineer.
ScanEtherCATNetwork
This example uses an EtherCAT®network that consists of Beckhoff®EK1100
,EL3062
, andEL4002
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.
StartMicrosoft®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.
ConfigureEtherCATMaster Node Data
Before configuring the master node of an EtherCAT network, scan the network by using TwinCAT.
CreateEtherCATTask
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 chooseAdd New Item. In the new dialog, selectTwinCAT 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 theFixed-step size (fundamental sample time)box. To enable Simulink®to calculate the sample time, select
Auto
.
ConfigureEtherCATTask 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 theLinked 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 selectAdd New Item. TheInsert Variabledialog 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 onLinked 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 theShow VariablesorShow Variable Typeslists.
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.
ConfigureEtherCATTask 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
.
ConfigureEtherCATDistributed Clocks
To configure theTerm 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, selectI/O>Devices>Device 1 (EtherCAT)
In the dialog in the right side, select theEtherCATtab. Select theAdvanced Settingsbutton. On the left of the new dialog, selectDistributed Clocks.
By default TwinCAT3 hasAutomatic DC Mode Selectionchosen. Deselect that and chooseDC 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 theDCtab 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
是一种常见的清单意味着IO不是直流同步hronized, but occurs on packet arrival (SM), not on DC time.Click theAdvanced Settingsbutton.
Make sure theEnablecheckbox is selected. There are additional settings that can be modified, but these are generally advanced options.
Export and SaveEtherCATConfiguration by UsingTwinCAT3
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 theDevice 1 (EtherCAT)node, in theEtherCATtab, 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 closeMicrosoft Visual StudioTwinCAT the project file is saved.
To review or modify your configuration, open the project SLN file by usingMicrosoft Visual Studio. If you modify the configuration, save both the XML and SLN files.
The next task isInstall EtherCAT Network for Execution.