Anda di halaman 1dari 5

SP Software & Automation Page 1 of 5

Indexed Addressing:

As discussed in the Theory sections, in indirect addressing, the address gets
evaluated at runtime. This also enables indirect addressing to use Index and
effectively use index (or indices) to loop through sections of the code. There
can be 2 types of indirect addressing:

a) Memory Indirect Addressing
b) Register Indirect Addressing


In memory indirect addressing, a Memory Element such as MD20 is used as
a pointer that contains the address of the element addressed. The program
can write different values to this MD20 to generate different addresses at
runtime.

The Register Indirect addressing uses one of the 2 address registers AR1 or
AR2

Examples:

Memory Indirect Addressing: A I[MD20] A I4.0 = Q[MD20]
Register Indirect Addressing: A I[AR1,P#0.0] A I 4.1 = Q[AR1,P#0.0]

Note: As programmers, we should be careful before using Indirect Addresses
as there is a possibility that unintentionally a wrong memory area is accessed
or gets over written.



SP Software & Automation Page 2 of 5
Exercise 7: Indexed Addressing & Analog / Math processing

Purpose: This example shows how to create loops in S7 PLC using STL and
also introduces Pointers and Indirect Addressing.

Problem Description: Consider the pipeline shown in Fig 1.



In Exercise 6, we computed the Flow Rate and stored the result in MD 26.
Every scan the PLC would update the Flow Rate and we get a different value
in MD 24.

In this exercise, we are going to take the average of last 10 values of the Flow
Rate.

Task:

1. Store the values of last 10 Flow Rates starting from MD 26 that is the
1
st
sample is stored in MD26 and 10
th
sample in MD 62.



Input / Output Assignment:

Signal Name Address Data Type
DP (Differential
Pressure)
MW20 INT
K (Multiplication Factor) MD22 REAL
Flow Rates F1 to F10 MD26, MD30, MD34, MD 38, MD42,
MD46, MD50, MD54, MD58, MD62
REAL









Differential Pressure Transmitter
Fig 1: Flow measurement


SP Software & Automation Page 3 of 5

Solution:

Step 1: Create Symbol Table as in Fig 2


Fig 2: Symbol Table


Step 2: OB1 is used as the main calling program. We have created a
simulation program in OB1 using a self resetting timer and a counter. Every
time the timer times out, it pulses the count up input. The counter output is
used as the output from Flow Transmitter and is fed into our FC 11 function.
Whenever the timer times out, a sample_ok signal is generated and a flow
data is made available to the FC 11 block. The FC11 grabs this Flow and
stores in a circular buffer of 10 double words starting from MD 26 and ending
at MD 62. After the 10
th
sample is stored in MD 62, the 11
th
sample is written
on MD 26 and this cycle continues.

The Flow Calculation function FC10 is the same as in Ex 6


SP Software & Automation Page 4 of 5

Fig 3: OB1


Fig4: OB1continued


SP Software & Automation Page 5 of 5


Fig 5: Code for FC11