PLC MEMORY ADDRESSING

The direct display of individual memory locations is done through the use of special character sequences. These sequences are a concatenation of the percent sign “%”, a range prefix, a prefix for the size and one or more natural numbers separated by blank spaces. The following range prefixes are supported:

PrefixDescription
IInput
QOutput
MMemory location

The following size prefixes are supported:

PrefixDescription
XSingle bit
BByte (8 Bit)
WWord (16 Bit)
DDouble word (32 Bit)
*Config variables (VAR_CONFIG)
Examples:
%QX75.1  (*Bit 1 of output byte 75*)
%IW215 (*Input word 215*)
%QB7 (*Output byte 7*)
%MD48 (*Double word in memory position 48 in the memory location*)

Boolean values will be allocated byte wise, if no explicit single-bit address is specified

Example: A change in the value of varbool1 AT %QW0 affects the range from QX0.0 to QX0.7.


Memory location

You can use any supported size to access the memory location, however the addressing is always byte wise. For example, the address %MD48 would address bytes numbers 48, 49, 50, and 51 in the memory location area because the size of a DWORD is 4 bytes. You can access words, bytes and bits in the same way: the address %MX5.0 allows you to access the first bit in the fifth byte.


Two methods are available as alternatives for addressing each variable:

1) Index method

Addressing is realised by specifying an index value (var[?].index). Each index comprises a memory of 24 bytes. If the chosen index "distance" between two successive variables is too small, memory overlapping occurs. Consequence: the memory of the following variable is overwritten. The CNC does not issue an error message because it assumes that this addressing was chosen deliberately.

2) AutoMem method

With this method, the CNC assumes memory management. The V.E. variables are entered in the memory successively in a non-overlapping fashion. When using this method, users do not need to both about correct memory assignment. An identifying feature of the AutoMem method is that declaration of the var[?].index attribute is not used in any of the variables!

The user decides according to which the methods the two memories for CHANNEL and GLOBAL are each organised.

If an address is specified, the position in the memory and the size are expressed via special strings.

Syntax: %<memory area prefix><size prefix><number|.number|.number….>

The following memory range prefixes are supported:

IInput memory area (“Inputs”, physical inputs via input drivers, “Sensors”)
QOutput memory area (“Outputs”, physical outputs via output drivers, “Actuators”)
MFlag memory area

The following size prefixes are supported:

XSingle bit
BByte (8 bits)
WWord (16 bits)
DDouble word (32 bits)

Examples:

%QX7.5%Q7.5Output bit 7.5
%IW215Input word 215
%QB7Output byte 7
%MD48Double word at memory location 48 in the flag area.
%IW2.5.7.1The interpretation depends on the current controller configuration (see below)
nVar AT %IW0: WORD;Example of a variable declaration with address specificationAT declaration

NOTE: The memory size for input, output, and memory data (declarations with AT %I, %Q and %M) is predefined by the target device and can be overwritten in the properties of an application object for PacDrive controllers (PacDrive LMC Eco, PacDrive LMC Pro/Pro2).

In order to assign a valid address in a PLC project, you must know the desired position in the process image. For this, you first have to define the memory area and the required size. In selecting the memory position, the assignment of the different sizes in the memory as illustrated in the table below must be observed so that you can rule out memory area overlaps.

DWordWordByteBit
D0W0B0X0.0
  B1X1.0
 W1B2X2.0
  B3X3.0
D1W2B4X4.0
  B5X5.0
 W3B6X6.0
  B7X7.0
D2W4B8X8.0

Examples: Memory area overlap

1. W0 contains B0 and B1. If you place a Word variable at W0 and a Boolean variable at B1, the memory areas would overlap.

2. W3 contains B6 and B7. If you place a Word variable at W3 and a Boolean variable at B6, the memory areas would overlap.

Byte Addressing Mode and Word Addressing Mode

Devices either use byte addressing mode or word addressing mode.

Examples

ModeExample
Byte addressingADR(%IW1) = ADR(%IB1)
Word addressingADR(%IW1) = ADR(%IB2)

The range for the second element of the bit address that is the number following the dot, is as follows:

obyte addressing mode: 0…7

oword addressing mode: 0…15

Also for the handling of bit addresses, you can configure the devices differently. They are then interpreted correspondingly by the EcoStruxure Machine Expert compiler.

Example: In a byte-addressing device, the bit address %IX2.5 addresses byte 2 (IB2). In a word-addressing device, however, it addresses word 2, which refers to a different location within the memory.

NOTE: Boolean values are allocated bytewise if no explicit single-bit address is specified. Example: A change in the value of varbool1 AT %QB7 affects the range from QX0.0 to QX0.7.

Posted in PLC