AT Declaration Permalink

Using a clear configuration editor for I/O mapping

Using a clear configuration editor for I/O mapping

We advise against assigning memory addresses as described here, because this can lead to a loss of clarity.

We recommend assigning memory addresses to variables in the configuration editor Edit IO mapping of the device.

The ‎AT‎ keyword in the variables declaration, assigns to a project variable a specific input address, output address, or memory address of the PLC that is configured in the device tree. The AT declaration makes it possible to give an address a meaningful name.

You can make any necessary changes for the input or output signals at just one location (for example, in the declaration).

Syntax

<variable name> AT % <address> : <data type>;

<variable name>

Required

% <address>

Required

Address in the memory area

% <memory area prefix> <size prefix> <memory position>

<memory area prefix>

Required

  • I: Input memory area

    Memory area for input signals and inputs

    For physical inputs via input drivers and sensors

  • Q: Output memory area

    Memory area for output signals and outputs

    For physical outputs via output drivers and actuators

  • M: Flag memory area

<size prefix>

Optional

  • No size prefix: bit

    Single bit

  • X: Bit

    Single bit

  • B: Byte

    8-bit data width

  • W: Word

    16-bit data width

  • D: Dword

    32-bit data width

<memory position>

<position number> . <bit position number>

Example: %IB2.4 stands for the 5th bit of the 3rd byte

<position number>

Required

The numbering depends on the target system and starts at 0.

. <bit position number>

Optional

0..7 for one byte

<data type>

Optional

The data type should match the size prefix.

Examples

‎VAR wInput AT %IW0 : WORD; END_VAR‎

Variable declaration with address information of an input word

‎VAR xActuator AT %QW0 : BOOL; END_VAR‎

Boolean variable declaration

Note: For Boolean variables, one byte is allocated internally if a single bit address is not specified. A change in the value of ‎xActuator‎ affects the range from ‎QX0.0‎ to ‎QX0.7‎.

‎VAR xSensor AT IX7.5 : BOOL; END_VAR‎

Boolean variable declaration with explicit specification of a single bit address

On access, only the input bit 7.5 is read.

‎VAR xSensor AT IX* : BOOL; END_VAR‎

For the address specification, the placeholder ‎*‎ is given instead of the memory position. The final address specification is done in the variable configuration.

Note: This is possible in function blocks.

Helpful hints

If you do not specify a single bit address explicitly, then Boolean variables are allocated byte-by-byte.

Individual bit addresses which are mapped to Boolean variables have restrictions. It is not possible to use these variables with VAR_IN_OUT, REFERENCE TO, or the ADR operator.

When you assign a variable to an address, note the following:

  • You cannot write to variables that are placed at inputs. This will cause a compiler error.

  • You can perform AT declarations only for local and global variables, not for input/output variables of POUs.

  • Furthermore, AT declarations cannot be used in persistent variable lists.

  • If you use AT declarations for structure components or function block variables, then all instances use the same memory. This corresponds to the use of "static variables" in classic programming languages such as "C".

  • The memory layout of structures also depends on the target system.

Example

PROGRAM PLC_PRG
VAR
        xVar AT %QW0 : BOOL;
END_VAR

xVar := TRUE;

When the variable ‎xVar‎ is written, the output memory range from ‎QX0.0‎ to ‎QX0.7‎ is affected.