6 variables – Lenze DDS v2.0 User Manual

Page 13

Advertising
background image

Introduction to IEC 61131-3 programming

General language elements

11

l

DDS-IEC61131 EN 2.0

4.6

Variables

IEC 61131-3 defines five different variable classes:

Global variables

Local variables

Input variables

Output variables

Input and output variables

Local variables do not have a connection to the outside, i.e. they can only be addressed from within
a program part; global variables can be addressed from all POUs.

Input, output and input/output variables are related to a program, function or function block. They
can be changed by reading and writing within the assigned POU; outside the POU, the change must
be defined (input, output and input/output).

The variables are declared between the keywords VAR and END_VAR in the source text. In general,
every variable is initialized after a cold restart. The default value is usually 0 or FALSE. A user-specific
initialization with another value is possible with the sign ” :=” in the declaration.

Variable attributes

The following attributes can be used additionally when declaring a variable:

RETAIN

: These variables remain the same even after a power failure. The program continues

with the values saved when being restarted.

CONSTANT

: Variable values cannot be changed.

AT

: Variables have a fixed location in the memory map (fixed address).

Example: Declaration of an output variable with initialization value

VAR_OUTPUT

par_out1 : INT := 10;

(* Output parameter 1 with start value 10

*)
END_VAR

Fixedly addressed variables

Variables can be assigned to a physical memory location (PLC) by means of the keyword AT when
being declared.

The address is indicated as a special character sequence. The character sequence starts with a
percentage sign ” % ” followed by a range prefix and a prefix (data type) for size and ends with a digit
sequence which indicates the memory location.

Range prefixes: I (Input), Q(Output), M(Marker, internal memory range)

Size prefix: X (Single bit), B(Byte, 8 bits), W(Word, 16 bits), D(Double word, 32 bits)

Examples:

%QX1.0.2

Output bit 2

%IW1.0.1

Input bit 1

%MB7

Marker byte 7

%MW1

Marker word 1

%MD3

Marker double word 3

%MX1.2

Third marker bit in marker word 1

Show/Hide Bookmarks

Advertising