Main Content

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, andEL4002modules 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. StartMicrosoft®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 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:

  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 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 exampleTask 1. ConfigureTask 1as a task with an image.

  2. In the task list, selectTask 1and set its cycle ticks value to a value in milliseconds, such as1for1millisecond.

  3. 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, selectAuto.

ConfigureEtherCATTask Inputs

To configure the task inputs:

  1. In TwinCAT 3, underTerm 1, access the nodesTerm 2andAI Standard Channel 1.

  2. Drag theValuenode ofAI Standard Channel 1to theTask 1inputs.

  3. Configure theTerm 1inputs as variables.

  4. Link theAI Standard Channel 1variable toTerm 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 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:

  1. Left-click on your task Inputs entry and selectAdd New Item. TheInsert Variabledialog 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 onLinked 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 theShow VariablesorShow Variable Typeslists.

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

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

ConfigureEtherCATTask Outputs

To configure the task outputs:

  1. In TwinCAT 3, underTerm 1, access the nodesTerm 3andAO Outputs Channel 1.

  2. Drag theAnalog outputnode ofAO Outputs Channel 1to theTask 1outputs.

  3. Configure theTerm 1analog outputs as variables.

  4. Link theAnalog outputvariable toTerm 3.

ConfigureEtherCATDistributed Clocks

To configure theTerm 3distributed clock:

  1. In TwinCAT 3, underTerm 3, access the DC tab.

  2. Change the DC operation mode toDC Synchron.

There are two main steps to configure distributed clocks:

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

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

  3. In the dialog in the right side, select theEtherCATtab. Select theAdvanced Settingsbutton. On the left of the new dialog, selectDistributed Clocks.

  4. By default TwinCAT3 hasAutomatic DC Mode Selectionchosen. Deselect that and chooseDC in use. Choose the mode you want.

  5. 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.

  6. 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:

  1. Select the slave in Solution Explorer.

  2. In the dialog, select theDCtab if it is available.

  3. In the Operation Mode drop down menu, there could be several different names given. For instanceDC LatchorDC Synchronare 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.

  4. Click theAdvanced Settingsbutton.

  5. 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:

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

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

    Caution

    The ENI file is formatted as an XML file with the.xmlfile 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 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.