Creating variables

The EtherCAT slave has a simple structure and consists of inputs, outputs and InfoData. In TwinCAT you can add process data to the inputs or outputs, which can later be linked to variables from the PLC program. This section describes how to create such data.

Prerequisites for this step:

Create the process data as follows:

1. In the tree view, right-click on the inputs or outputs.
Creating variables 1:
2. Click on Add New Item in the context menu.
Creating variables 2:
The Insert Variable window appears.
3. Find the required variable type and click OK.
Creating variables 3:
You have successfully created process data. The new variable is shown in the tree view on the left. In this way you can add further process data or variables for the EtherCAT slave.

Process data with structures

In order to save a large number of links it is a good idea to use a data structure to save data that you wish to exchange. Note that data structures with different variables are processed differently on an x86 system and an ARM processor. An ARM processor always associates WORD (2 byte) variables with an even address and DWORD (4 byte) variables with an address that is divisible by 4.

Data structure sample
byTest: BYTE;
udTest: UDINT;

ARM address

ARM variable

Address x86

ARM variable

Byte Offset 0

Byte

Byte Offset 0

BYTE

Byte Offset 4

UDINT

Byte Offset 1

UDINT

Sum: 8 byte

Sum: 5 byte

You can determine the length of a data structure on both systems using the command SIZEOF. If there is a difference here, this indicates that something is wrong with the data structure.

This problem can be solved by more skillful arrangement of the variables or by working with filler or dummy variables.

ARM address

ARM variable

Address x86

ARM variable

Byte Offset 0

Byte

Byte Offset 0

BYTE

Byte Offset 1

BYTE (Dummy1)

Byte Offset 2

BYTE (Dummy2)

Byte Offset 3

BYTE (Dummy3)

Byte Offset 4

UDINT

Byte Offset 4

UDINT

Sum: 8 byte

Sum: 8 byte

Filler or dummy variables can be used to adjust the length of the data structure, in order to avoid problems caused by potential differences.