Declaration of the variables

In this chapter, you will connect the previous PLC program to the Beckhoff bus terminals. This happens with the TwinCAT System Manager. By means of the System Manager, all input/output interface connections are managed and addressed and are assigned to the I/O data. Each I/O channel can be addressed by a logical name. The TwinCAT System Manager manages several field buses on one common process image

Hardare required

It´s neccessary to have the required hardware. The Demokit for the Lightbus contains the PC interface card for the II/O-Lightbus (FC2001), the bus Coupler BK 2000, Bus Terminals, 2 fibre optic and some documentation.

Without hardware go to the next chapter: Application Samples .

Variable declaration:

The storage locations (addresses) of variables are managed internally by the system. The programmer does not need to bother about memory management. The PLC programs operate with symbolic variable names, thus preventing the occurrence of side effects (overlaps) when using variables. To access the input/output level, it is necessary for the programmer to be able to assign a fixed address to individual variables. This is achieved by means of the key word 'AT', which must always be specified when declaring a variable. The key word 'AT' is followed by several parameters which provide information about the data location (input/output or flag area) and the width of the data (BIT, BYTE, WORD or DWORD). The variable declaration for the above example has the following structure:

VAR_Global
  engine       AT %QX0.0:       BOOL;
  deviceup     AT %QX0.1:       BOOL;
  devicedown   AT %QX0.1:       BOOL;
  timerup:                      TON;
  timerdown:                    TON;
  steps:                        BYTE;
  count:                        UINT := 0;
  devspeed:                     TIME := t#10ms;
  devtimer:                     TP;
  timerup:                      TON;
  switch:                      BOOL;
END_VAR

Where:

 

Data location

Datawidth

Meaning

%

 

 

Start of I/O definition

 

I

 

Input

 

Q

 

Output

 

M

 

Flag

 

 

X

Bit (1bit)

 

 

B

Byte (8 bits)

 

 

W

Word (16 bits)

 

 

D

Double word (32 Bit)

The digits after the data width specify the address of the variable. For bit variables, the address must be specified in the format x.y, or simply x for byte, word and double word. The input and outputsare in different Storage areas , therefor may contain the same address.