A detailed explanation of the POINTER data type in STEP7.

 Siemens STEP7 (TIA Portal) programming and development environment provides significant freedom to program designers. The rich set of instructions and data types allows engineers to unleash their ingenuity and write efficient, stable, and powerful code. Today, we will delve into a more advanced aspect of STEP7 programming - the POINTER data type.

The concept of pointers originated in the C language, representing the address of a variable. Pointer variables occupy four bytes (on a 32-bit operating system), enabling programmers to easily read and write to memory, significantly improving program efficiency. C language, known for its pointer support, has been widely used for writing operating systems. The renowned Linux operating system, for instance, is written in C.

In the PLC world, Siemens STEP7 (TIA Portal) has also introduced the concept of pointers. However, the pointer type in STEP7 differs slightly from that in C language, occupying 6 bytes, as illustrated below:



Among these, Byte0 and Byte1 are used to indicate the number of the data block (DB). If the pointed storage area is not a DB block, their values are set to 0. Byte2 represents the Memory Area Code of the accessed storage area. The low 3 bits of Byte3, along with Byte4 and the high 5 bits of Byte5, are used to denote the variable's byte address (highlighted in blue in the diagram). The low 3 bits of Byte5 represent the variable's bit address (highlighted in brown in the diagram). It is evident that the pointer type can clearly express information about the area (Memory Area), byte address, and bit of the data to be pointed to.

In STEP7, pointer variables are identified using the symbol "P#", for example, "P#DB100.DBX1.0" represents a pointer variable pointing to the 0th bit of the 1st byte in DB100. STEP7 supports four types of pointer variables:

  1. Area-internal Pointer: Pointers within the same memory area, for example, P#10.0;

  2. Cross-area Pointer: Pointers pointing to memory area variables, for example, P#M6.0. The memory area can be an Input Memory Area (I), Output Memory Area (Q), or Bit Memory Area (M);

  3. DB Pointer: Pointers pointing to data block variables, for example, DB101.DBX2.0;

  4. Zero Pointer: Used to point to a variable that is currently unused but may be used in the future;

If a function block (FB or FC) parameter is of pointer type, when assigning a value to the parameter, the "P#" symbol can be omitted (you can choose not to omit it if you're not feeling lazy), as STEP7 automatically converts the input value into a pointer type.

After reading this article, do you now have a deeper understanding of pointers?