Indirect addressing

Posted 26 Aug 2018 by Nikolay
Indirect addressing in the plc programming
Indirect addressing in the plc programming

The indirect addressing can be used to save time and effort or simplify and reduce your source code.

If you have a PLC with 40 Analog Inputs you can use the indirect addressing to process the information coming from the Analog Inputs, like scaling, checking of alarm limit values etc., so for example you don’t have to program the alarm limits evaluation for each signal separately.

In a few steps I will show how to do a simple indirect addressing.

Demo 1

Indirect addressing done in Studio 5000

First in the Tags Editor window we have to define one variable of type array, which in this example has twenty elements ARRAY[20]. For your application you can define array of any type, even of user defined type (UDT).

Array of integers Studio 5000

Figure 1. Array of integers in Studio5000.

Sot let’s assume that during the run of my program, event triggered, I want to put information in the array, and each time in the next element.

I am going to declare one additional variable “Index” of type integer.

Defining index variable in Studio 5000

Figure 2. Index variable in Studio5000.

This variable is going to be used like “Place holder” for the actual number of the ARRAY elements - VAR_INTEGER[INDEX]. If the value of variable INDEX is 10, when reading from or writing to VAR_INTEGER[INDEX], we actually  manipulate element number 10 of the array VAR_INTEGER[10].

In the following piece of code, you see that when the variable TRIGGER is activated the value Machine_VALUE is moved once int the corresponding array element and the INDEX variable is incremented by one.

Write machine data in the array elements.

Figure 3. Writing machine data in the array elements.

In the next step we are going to initialize the INDEX after reaching the maximum number of the array elements.

Index initialization in Studio5000

Figure 4. Index initialization in Studio5000.

Demo 2

Indirect addressing done in SIEMENS TIA PORTAL

In the second demo is identical to the first one, just done in TIA portal.  First I generated some PLC variables which are used to control the loop.

PLC variables in TIA Portal

Figure 5. PLC variables in TIA Portal.

After that I generated a Data Block (DB) – DB_Memory and in the DB Array variable (VAR_INTEGER) of type Integer. I this example I have used 20 elements.

Array of Integer.

Figure 6. Array of Integer.

The variable INDEX (of type Integer) is used to address the single elements in the Array variable VAR_INTEGER.

In the data block DB_Memory I placed the variable Machine_VALUE, which is going to be written in the array elements.

Figure 7. Simulated  machine data.

In the final step I have programmed a simple loop. When the variable TRIGGER is activated the Machine_VALUE is going to be moved to the array element corresponding to the value of the variable INDEX. If the value of INDEX is 5 then the Machine_VALUE is going to be moved in array element VAR_INTEGER [5].

I am using ADD function to increment the INDEX variable by one. Add compare function to initialise the INDEX variable after reaching the number of elements in the array variable. In my array there are 20 variables (from 0 to 19), so if the INDEX variable is greater than 19, it receives the value “zero” and the loop is going to be reinitialized.

Write data in array elements. TIA Portal

Figure 8. Write data in array elements. TIA Portal.

The two examples show how to make a simple loop, which for example can be used as shift register to store machine data in array variable.




Join the discussion