Skip to main content

Getting Started

A sample project with the CODESYS Safety for EtherCAT Safety Module add-on will be created here. The completed ECAT.projectarchive project can also be found in the CODESYS installation directory in the Projects\Applications subfolder.

Procedure

  1. Creating a new project

    Create a new standard project as usual, as described in Create standard project.

    1. Click New Project.

    2. Select the Standard Project template.

    3. Specify a name and a storage location.

      Dialog: New Project

      EL6900_Example_new_project.png
    4. Click OK to close the dialog.

      The Standard Project dialog opens.

    5. Select CODESYS Control Win as the controller.

    6. Select Structured Text as the language for the PLC_PRG POU.

      Dialog: Standard Project

      EL6900_Example_standard_project.png
    7. Click OK to confirm your settings.

      The project has been created. All standard objects are displayed in the device tree.

  2. Adapting the communication settings of the controller

    1. In the device tree, double-click the device.

      The device editor opens on the right side.

    2. Select the desired controller.

      Communication settings of the device editor

      EL6900_Example_communication_settings.png
  3. Adding an EtherCAT Master to the device tree

    1. Right-click the controller to open its context menu and click Add Device.

      The Add Device dialog opens.

    2. Select the EtherCAT Master device and click Add Device.

      The device is added.

      EL6900_Example_add_ethercat_master.png
  4. Configuring the EtherCAT Master

    1. Double-click the object to open the configurator of the EtherCAT Master.

    2. In the Select Network Adapter dialog, click the Select button and specify the desired adapter.

      The EtherCAT Master is configured. The communication settings have been configured.

      EL6900_Example_ethercat_settings.png
  5. Login and download

    1. Click Online → Login.

      The application on the controller is overwritten.

    2. Log back out.

  6. Scanning detected hardware

    1. Click Scan For Devices.

      EL6900_Example_search_device.png

      The devices available in the network are listed.

    2. Click the Copy all devices to project button.

      EL6900_Example_copy_to_project.png

      The hardware found is automatically transferred to the project and displayed in the device tree.

  7. Setting the parameters of the logical I/O modules

    1. Open the device editor of the EL1904 module and set the FSoE address (example: 2). This is the address which is also set on the device via DIP switches.

    2. Open the device editor of the EL2904 module and set the FSoE address (example: 3). This is the address which is also set on the device via DIP switches.

      Logical I/Os – Settings

      EL6900_Example_logicIO_settings1.png

      Note

      The connection ID must be parameterized in such a way that every logical I/O module has its own unique address.

      This makes sure that the safe I/O module can detect errors caused by the incorrect forwarding of a FSoE telegram. The connection ID is therefore checked in the safe IO module.

      The uniqueness is not checked by CODESYS.

  8. Defining the I/O mapping of the logical devices

    1. Open the I/O Mapping tab.

    2. Assign variables to the individual channels of the module.

      EL1904 logical I/O mapping

      EL6900_Example_logicIO_IOMapping1.png

      EL2904 logical I/Os – I/O mapping

      EL6900_Example_logicIO_IOMapping2.png
  9. Programming a POU (program)

    1. Click Project → Add Object → POU (EtherCAT Safety).

      The POU has been added.

      EL6900_Example_add_POU.png
    2. Open the POU and drag the FB_TWOHAND function block into the programming area of the editor. Pay attention to the Start here message.

    3. Connect the inputs and outputs of the function block to the variables as shown.

      Programming area with the FB_TWOHAND function block

      EL6900_Example_add_FB.png
  10. Setting of variables on the Group IOs tab of the POU program

    These variables control the state of the POU and can signal errors.

    1. Open the properties of the recently created POU (right-click the POU in the device tree Properties) and configure the settings under Group IOs as shown.

      POU – Properties

      EL6900_Example_POU_properties.png
  11. Adding logical devices for data exchange

    1. Open the Add Logical Device dialog (context menu of Logical I/Os → Add Object → Logical Device).

      EL6900_Example_add_logicIO1.png
    2. In the dialog, select the Exchange 8 bits from EtherCAT Safety Module to PLC device. Give it the name ESM_To_PLC .

      Logical device – Exchange device

      EL6900_Example_add_logicIO2.png
    3. Add the Exchange 8 bits from the PLC to EtherCAT Safety Module logical device. Give it the name ESM_From_PLC.

  12. Defining the variables of exchange objects

    1. Double-click the newly added logical devices to open the respective editor. Map the variables as shown below.

      Logical device ESM_to_PLC: Variable definition

      EL6900_Example_add_logicIO3.png

      Logical device ESM_from_PLC: Variable definition

      EL6900_Example_add_logicIO4.png
  13. Adding global variable lists for logical exchange

    1. Add GVLs for logical exchange to the device tree (context menu of the application → Add Object → Logical Exchange GVL).

      Adding a logical exchange GVL

      EL6900_Example_add_GVL.png
    2. In the Add Logical Exchange GVL dialog, specify the name FromESM.

      The new GVL is added to the device tree.

    3. Double-click to open the editors.

      The variables of the logical device ESM_To_PLC are now mapped to this GVL in the lower area of the editor.

      GVL – Assignment of the logical I/Os

      EL6900_Example_add_GVL_mapping.png
    4. In a similar way, create the GVL ToESM and connect it to the logical I/Os of ESM_From_PLC.

  14. PLC_PRG program

    Creating the PLC_PRG program

    The PLC_PRG program is used to read and write the variables of the safety application. The FbErr, ComErr, and OutErr variables have been added so that the states can be monitored. If bAutostart is set, then the ErrAck flag is set for one cycle in the case of an error in the safety block (detected by ComErr) so that the error is acknowledged in the EtherCAT Safety Module.

    EL6900_Example_PLCPRG_code.png
  15. Transferring the standard application to controller

    Finally, log in to the standard controller, transfer (download) the application, and start it.

    The states of the variables can now be monitored in the online view.

    EL6900_Example_Login_Device.png
  16. Downloading the safety program

    Now load the safety program to the EtherCAT Safety Module. To do this, open the module in the editor and click the Download Project button.

    The login dialog opens.

    EL6900_Example_Project_Download.png

    In this dialog, specify the name and password of a user which is entered in the user administration of the EtherCAT Safety Module, as well as the serial number of the EtherCAT Safety Module.

    The default password is "TwinSAFE".

  17. Starting the program on the EtherCAT Safety Module

    After the project comparison, specify the user name, password, and serial number of the EtherCAT Safety Module again in order to start the project.

    After clicking OK to confirm, the safety program runs on the EtherCAT Safety Module.

    Login

    EL6900_StartProjectDialog.png

    Now the POU can be opened in the editor and the inputs monitored.