EtherCAT Slave  1.06.01
KUNBUS Revolution Pi

CODESYS Installation

The CODESYS development system is after registration available for download free of charge from the CODESYS Store.
Please consult the system requirements in the CODESYS store for the development PC.
It is recommended to install the full package. For the CODESYS runtime on the KUNBUS RevPi hardware, the CODESYS Control for Raspberry Pi MC SL is required.
Without a valid license, the CODESYS runtime including the fieldbus functionality will execute for one hour and then exit.
To install the runtime package, the CODESYS development system must be started as administrator.
Installation is performed from within the CODESYS Package Manager. It is recommended to install the multi-core version.

After the package is installed, the CODESYS runtime system must be installed on the RevPi hardware. From the menu system select Tools → Update Raspberry Pi

Creating a CODESYS Project

Start the CODESYS development system and create a new standard project

Select CODESYS Control for Raspberry Pi MC SL (3S - Smart Software Solutions GmbH) as a device and the programming language of your choice.

The development system creates the project structure and populates the structure of the device tree.

Before configuring the EtherCAT network, the matching device description file must be installed to the CODESYS device repository.
Navigate to Tools → Device Repository in the menu system and install the file TI AM64X.R5F Simple.xmlwhich is part of the distribution.

Setup an EtherCAT Network

Scan for a Gateway Device and select connected RevPi.

Continue to add the EtherCAT Master.

Select the MAC Address of the Ethernet Interface used by EtherCAT Network Communication.
Once complete you can enter Online mode and start your application.
This only starts the EtherCAT Master from where it is possible to scan for connected Slave devices.

Scan for Device and add to Project

Provided that device description has been installed already, the scan process will identify the EtherCAT Slave device, which can then be copied to the project.

Exit Online mode, re-enter Online mode to download the new project structure, and start the application.

Open the Device General Settings tab and select the Expert settings .

Navigate to the "Expert Process Data" tab, which will be displayed after Expert settings is selected, and select "Load PDO Info from Device"

Finally exit Online mode, re-enter Online mode to download the new project structure, and start the application.

All devices should now be running.
Now you are free to implement your program.

Start your PLC program in Structured Text

In CODESYS you can define your PLC application program in PLC_PRG.
In order to access the EtherCAT device objects, you first need to map variables to the PDOs defined in the device application.
This can be done by opening the PLC_PRG in Application and defining the Variables - for example:

PROGRAM {PROGRAM_NAME}
VAR
{VARIABLE_NAME} AT {IOMAPPING_REFERENCE} : {TYPE} := {INITIAL_VALUE};
END_VAR

The IOMAPPING_REFERENCE you can find in the "EtherCAT I/O Mapping" Tab of the Device Settings.

EtherCAT Slave Simple Example I/O Mapping

The EtherCAT Slave Simple Example is providing listed PDOs and objects:

TXPDO at Index 1A00h SubIndex2 at Index 2002h Subindex 2
SubIndex4 at Index 2002h Subindex 4
SubIndex3 at Index 2002h Subindex 3
TXPDO2 at Index 1A01h SubIndex1 at Index 2002h Subindex 1
RXPDO at Index 1600h i2c-leds at Index 2000h Subindex 2
SubIndex3 at Index 2000h Subindex 3
SubIndex4 at Index 2000h Subindex 4
RXPDO2 at Index 1601h SubIndex1 at Index 2000h Subindex 1

EtherCAT CiA402 Example I/O Mapping

The EtherCAT CiA402 Example is providing the specified mandatory objects in TX- and RXPDOs for a total number of 3 axes:

TXPDO at Index 1A00hStatusword at Index 6041h Subindex 0
Modes of Operation Display at Index 6061h Subindex 0
Position actual Value at Index 6064h Subindex 0
Velocity actual Value at Index 606Ch Subindex 0
Torque actual Value at Index 6077h Subindex 0
RXPDO at Index 1600hControlword at Index 6040h Subindex 0
Modes of Operation at Index 6060h Subindex 0
Target position at Index 607Ah Subindex 0
Target velocity at Index 60FFh Subindex 0
Target torque at Index 6071h Subindex 0

The objects defined for Axes 2 and 3 are adding an offset of 800h and 1000h to objects described above.

Please find the EtherCAT IO Mapping for CiA402 Example.

Find also a reference on how one can set variables for CiA402 Example project.

Address Process Data LEDs in EtherCAT Slave Simple

The EtherCAT Process Data LEDs can be addressed by mapping the first 8 bits in Process Output Image to boolean variables in your Structured Text Program.

PROGRAM {PROGRAM_NAME}
VAR
i2c_led1 AT %QX0.0 : BOOL :=0;
i2c_led2 AT %QX0.1 : BOOL :=0;
i2c_led3 AT %QX0.2 : BOOL :=0;
i2c_led4 AT %QX0.3 : BOOL :=0;
i2c_led5 AT %QX0.4 : BOOL :=0;
i2c_led6 AT %QX0.5 : BOOL :=0;
i2c_led7 AT %QX0.6 : BOOL :=0;
i2c_led8 AT %QX0.7 : BOOL :=0;
END_VAR

After the mapping is done, you can assign/manipulate the variables in your program. For Example you can assign them within your program visualization.