Skip to main content

Addresses

Caution

If you use pointers to addresses, then the contents of addresses can be moved during an online change. If you use absolute addresses, then the contents of addresses does not change during an online change.

Syntax:

% <memory area number> <size prefix> <position number> .<bit position number>

% <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

When defining an address, you use specific strings to express the memory position and size. An address comprises the percent sign (%), followed by the memory area prefix, the optional size prefix, and the memory area position. The numbering which you use for addressing the memory position depends on the target system.

Example 202. Examples

%QX7.5

%Q7.5

Single bit address of the output bit 7.5

%IW215

Word address of the input word 215

%QB7

Byte address of the output byte 7

%MD48

Address of a double word at memory position 48 in flag memory

%IW2.5.7.1

Word address of an input word; interpretation dependent on the current controller configuration

VAR 
    wVar 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: In the case of Boolean variables, one byte is allocated internally when 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

When accessed, only the input bit 7.5 is read.



Memory position

Make sure that the address is valid as follows:

To map a valid address in an application, you first need to know the required position in the process image. This means the applicable memory area: input memory area (I), output memory area (Q), or flag memory area (M) (see above). Furthermore, you need to specify the required size prefix: bit, BYTE, WORD, DWORD (see above: X, B, W, D)

The currently used device configuration and device settings (hardware structure, device description, I/O settings) play a decisive part.

Pay special attention to the differences in the interpretation of bit addresses between devices with byte addressing and devices with word-oriented IEC addressing.

In the case of the bit address %IX5.5, the number before the dot addresses byte 5 in a byte-addressed device and word 5 in a word-addressed device.

In contrast, addressing with a word or byte address is independent of the device type: with %IW5, word 5 is always addressed, and with byte address %IB5 always byte 5. Depending on the size and addressing mode, you can therefore address different memory cells with the same address information.

The following table shows the comparison of byte addressing and word-oriented IEC addressing for bits, bytes, words, and double words. It also shows the overlapping memory areas for byte addressing. See the example at the end of the table.

Concerning syntax, note that the IEC addressing is always word-oriented. The word number is located before the dot, and the bit number after the dot.

_cds_img_memorycells.png

n = byte number

Example 203. Example of overlapping memory areas for byte addressing

D0 contains B0 - B3. W0 contains B0 and B1. W1 contains B2 and B3. W2 contains B4 and B5.

W1, but also D1, D2, and D3 must not be used for addressing. This avoids overlapping.