Sei sulla pagina 1di 19

Indirect Addressing (1)

er
? o int
#P

?
#Ini_Value

?
#Counter

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.1

Contents Page
Objectives ........................................................................................................................................ 2
Addressing Possibilities with STEP 7 ................................................................................................ 3
Direct Addressing of Variables ......................................................................................................... 4
Direct Addressing of Address Identifiers in Data Blocks .................................................................... 5
Analyzing DB Information in the Program ........................................................................................ 6
Memory Indirect Addressing ............................................................................................................. 7
Structure of Pointers with Memory Indirect Addressing ..................................................................... 8
Address Areas for Storing 16-Bit and 32-Bit Pointers ........................................................................ 9
Example of Memory Indirect Addressing ........................................................................................... 10
Testing the Program Execution using Breakpoints (Part 1) ............................................................. 11
Testing the Program Execution using Breakpoints (Part 2) .............................................................. 12
Task 1: Storing Part Weight Values (FC 35) .................................................................................. 13
Exercise 1: Storing Part Weights (FC 35) .................................................................................... 14
Task 2: Displaying Weight Statistics ............................................................................................. 15
Exercise 2: Displaying Weight Statistics (FC36) …......................................................................... 16
If You Want to Know More .............................................................................................................. 17
Area-Internal, Register Indirect Addressing ...................................................................................... 18
Area-Crossing, Register Indirect Addressing .................................................................................... 19

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 1 Indirect Addressing (1)
Objectives

Upon completion of the chapter the participant will ...

... understand the basics of memory indirect addressing


and be able to apply it

… understand and be able to assign parameters of the


ANY type

… be familiar with register indirect addressing

… be able to use the test function "Breakpoint"

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.2

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 2 Indirect Addressing (1)
Addressing Possibilities with STEP 7

Addressing Procedure

Direct Addressing Indirect Addressing

absolute symbolic memory indirect register indirect

32-bit pointer
16-bit pointer 32-bit pointer 32-bit pointer area-
(DB, T, C) area-internal area-internal crossing

Examples:

A I 4.0 A "Mot_on" OPN DB[MW10] A I[MD30] A I[AR1,P#0.0] A [AR1,P#0.0]


L IW10 L #Num SP T["runtime"] L IW["Number"] L ID[AR1,P#5.0] T W[AR1,P#0.0]

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.3

Direct With direct addressing, the memory location is coded in the instruction. That is,
Addressing the address identifier specifies the address value the instruction is to process.

Symbolic In a control program, addresses can have absolute addressing (such as I 1.0)
Addressing or symbolic ("start signal" for example). The symbolic address uses names
instead of the absolute addresses.
A program is easier to read when meaningful names are used. With symbolic
addressing differentiation is made between local symbols (in the declaration part
of a block) and global symbols (symbol table).

Indirect With indirect addressing you are able to address address identifiers whose
Addressing address is determined only at program runtime. With indirect addressing,
program parts, for example, can be scanned repeatedly (loop programming),
whereby the addresses used are assigned different addresses with every scan.
With indirect addressing, differentiation is made between:
• memory indirect addressing: A pointer to the addressed address is found in
a user memory’s memory cell (such as MD30).
With memory indirect addressing, the variables, in the memory in which the
pointer of the addressed address identifier is stored, can also be assigned
symbolic names.
• register indirect addressing: The pointer to the addressed address is loaded
in one of the two address registers (AR1 or AR2) of the S7 processor before
being accessed. (Is dealt with in the Course ST-PRO3).

Caution Since the addresses are only calculated at run-time with indirect addressing,
there is the danger that memory areas are unintentionally overwritten and you
can then have an unexpected PLC reaction.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 3 Indirect Addressing (1)
Direct Addressing of Variables
Memory Additional
Address Meaning
Location (for example) Access Widths
Byte, word,
I 37.4 Inputs
double word
Byte, word,
Q 27.7 Outputs
double word
Byte, word,
PIB 655 Peripheral inputs
double word
Byte, word,
PQB 653 Peripheral outputs
double word
Byte, word,
M 55.0 Bit memories
double word

T 114 -- Timers

C 13 -- Counters

Byte (DBB), word (DBW), Data addressed via


DBX 2001.6
double word (DBD) DB register
Byte (DIB), word (DIW), Data addressed via
DIX 406.1
double word (DID) DI register
Byte (LB), word (LW),
L 88.5 Local data stack
double word (LD)

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.4

Direct Addressing With the help of direct addressing, simple (elementary) variables, that is,
of Variables variables up to a length of a maximum of 4 bytes, can be addressed. Simple
variables consist of:
• an address identifier (such as: "IB" for input byte)
• an exact address (memory location) (byte or bit address) within the memory
area, that is determined by the address identifier.
Global, symbolic names (symbol table) can also address addresses or simple
variables.

Peripherals Unlike S5, it is now necessary to make a distinction between inputs and outputs
when accessing peripherals. However, it is still only possible to have a read-only
access (L PIW) of peripheral inputs and a write-only access (T PQW) of
peripheral outputs.

Local Data With STEP 7 it is also possible to have an absolute access of the local data
stack’s own blocks, for example:
• A L 12.6 (scan local data bit with address 12.6 for signal state = 1)
• L LW 12 (Load local data word in ACCU1)

DBX/DIX You can also access directly simple variables within data blocks:
• A DBX 12.6 (Scan data bit with address 12.6 of a DB for signal state =
1, DB must be opened beforehand).
• L DB5.DBW10 (Load DW10 in DB5)

Complex You can symbolically access local variables that have a complex data type,
Variables such as structures or arrays,.
Absolute access is only possible with components of complex variables that are
elementary data types.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 4 Indirect Addressing (1)
Direct Addressing of Address Identifiers in Data Blocks

Open Load and transfer


data blocks in data blocks

OPN DB 19 L DBB 1 Load data byte 1


OPN "Values" L DBW 2 Load data word 2 (byte 2/3)
L5 Load number 5
T DBW 4 Transfer into word 4
OPN DI 20 L 'A' Load ASCII character A
L DIB28 Load data byte 28

A DBX 0.0 Scan bit 0 from byte 0

Combined instruction L DB19.DBW4 Load data word 4 from DB 19


(contains OPN DB..)
L "Values".Number_1 Symbolic access of
variable Number_1. DB19
has the symbol name
"Values"
A DB10.DBX4.7 Scan bit 7 from byte 4 of DB 10

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.5

Overview The CPU makes two data block registers available for data address processing.
The numbers of the data blocks currently open are found in these registers.
Before you can access a data block, you must first open it using one of the two
data block registers.
You can open a data block using the following instructions:
• OPN DBx or OPN DIx
or by means of a fully-qualified access to a DB variable:
• L DBx.DBWy (L DIx.DIWy is not possible!)
In this case DB number x is also loaded in the DB register.

Addressing Data blocks are organized byte-by-byte in STEP7. For the direct access of
addresses with BIT, BYTE, WORD or DWORD length, the byte address (as for
I/Q/M) is indicated in each case.

Symbolic Access For a symbolic access you enter the data block’s symbol name in the symbol
list. You use the DB Editor to assign symbolic names to the data block’s
individual variables.
Now, a complete symbolic access of a data element is possible with the L
"Values"..Number_1 instruction. DB19 now opens ("Values" is the symbol name
of DB 19) and DW 2 is loaded (Number_1 is the symbol name of DW2).

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 5 Indirect Addressing (1)
Analyzing DB Information in the Program

Instructions with DB Registers:


z CDB: Exchange DB Registers

DB Register 123 24

CDB 123
DI Register 24

before: after:

z Load DB Register in ACCU1


ƒ L DBNO (load opened DB number in ACCU1)
ƒ L DINO (load opened DI number in ACCU1)

z Load length of data blocks


ƒ L DBLG (load the length/bytes of the opened DB in ACCU1)
ƒ L DILG (load the length/bytes of the opened DI in ACCU1)

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.6

DB, DI Registers These registers contain the current valid numbers of the opened data blocks.
You can open two data blocks simultaneously in a call level.
STL prefers to use the first DB register for accessing shared (global) DBs and
the second DB register for accessing instance DBs. These registers are also
called DB register or DI register for this reason .
The CPU treats these registers equally. Every data block can be opened with
one of these two registers (even with both simultaneously).

CDB CDB (Exchange DB registers) exchanges the contents of the DB and DI


registers. The DB register’s contents are transferred into the DI register and vice
versa. This instruction affects neither the contents of ACCU1 nor the status bits.

L DBLG, L DILG: These instructions read out the data length of the currently opened data blocks
in number of bytes. With the help of this information, the user program can test if
a DB has the necessary length before the DB is accessed.

L DBNO, L DINO: These instructions read out the numbers of the currently opened data blocks.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 6 Indirect Addressing (1)
Memory Indirect Addressing

z 16-bit Pointer in Word Format (Addressing of DBs, T, C)


Instruction: executed operation: (examples)

OPN DB [MW 60] OPN DB 11 if [MW60] = 11


OPN DB 25 if [MW60] = 25

z 32-bit Pointer in Double Word Format (Addressing such as for I,


Q, M,)
Instruction: executed operation: (examples)

L IW [MD50] L IW 24 if [MD 50] = P#24.0


L IW 86 if [MD 50] = P#86.0

Instruction Address Access Pointer


ID width (Address)

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.7

Overview With memory indirect addressing, the address of the variable to be accessed
is found in an address (memory location).
Program statements using memory indirect addressing contain:
• an instruction (such as: OPN, A, L, etc.)
• an address identifier (such as DB, C, T, I, QW, MD, etc.)
• and a [variable], that must be enclosed within square brackets.
This variable contains the address (pointer) of the operand that the
instruction accesses.
The instruction will interpret data stored in the specified [variables], as either a
word or double word pointer depending on the address identifier used.

Instructions with You use the 16-bit pointer for addressing timers, counters or blocks (DB, FC,
16-bit Pointers FB).
You can address all timer and counter instructions with indirect addressing. To
address timers, counters or blocks, use area identifiers of the form T, C, DB,
DI, FB, FC. The address (memory location) of the addressed operand is stored
in a word.
A DB or DI register can open a data block. If a zero is found in the pointer
when you indirectly open a data block (DB, DI), then the DB/DI register is
loaded with the value "0". An error is not triggered when you load with "0".
You can use the UC or CC instructions (not CALL) to address the call of logic
blocks indirectly. The blocks, however, may not contain any block parameters
or static variables.
This pointer in word format is interpreted as an integer number (0 to 65,535).
The pointer refers to the number of a timer (T), a counter (C), a data block
(DB, DI) or a logic block (FC, FB).

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 7 Indirect Addressing (1)
Structure of Pointers with Memory Indirect Addressing

z Structure of a 16-bit Pointer:


15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 146
215 27 20
Interpretation as unsigned integer between 0 and 65,535

z Structure of a 32-bit Pointer (area-internal): P#25.3


31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 1 1
215 20 22 20

not analyzed Byte address (unsigned integer) Bit


address

z Loading of 32-bit Pointer Constants (area-internal):


L P#25.3 (P = Pointer, Byte address= 25, Bit address: 3)

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.8

Instructions with Memory indirect addressing using 32-bit pointers can access the following
32-bit Pointers addresses:
• Bits that are addressed by bit logic operations.
I, Q, M, L, DIX or DBX can be used as address identifiers
• Bytes, words and double words that are addressed by load or transfer
instructions. IB, IW, ID, DBB, DBW, DBD, DIB, DIW, DID, PIB, PIW, PID,
can be used as address identifiers.
The address of the addressed operand is interpreted as 32-bit pointer. In this
double word, the least significant bits (bit 0 to bit 2) are interpreted as bit
address. The next 16 bits (bit 3 to bit 18) are interpreted as byte address of the
addressed operand. Memory indirect addressing does not analyze bits 19 to
31.

Note If you want to access an address by means of memory indirect addressing and
use load or transfer instructions, you must make sure the bit address of the
pointer is “0”.
If this is not the case, the CPU triggers a runtime error during execution.

Loading of 32-bit You can use the following syntax to load 32-bit pointer constants into ACCU1:
Pointer Constants
L P#<Byte address>.<Bit address>

Storage Locations for You must store 16-bit and 32-bit pointers for memory indirect addressing in
Pointers one of the following areas:
• M - Bit memory
• L - Local data
• D - Data block (DB or DI)

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 8 Indirect Addressing (1)
Address Areas for Storing 16-Bit and 32-Bit Pointers

Absolute or symbolic addressing (examples):

OPN DB[MW30] OPN DB[#DB_No]


Bit memory A I[MD30] Local data stack A I[LD10]

T QD[“Speed_1“] T QD[#Pointer]

Only addressable absolutely; DB or DI must be opened first (examples):

OPN DB[DBW0] Æ overwrites DB Register !


Global data block A I[DBD10]

T QD[DBD22]

OPN DI[DIW0] Æ overwrites DI Register !


Instance data block A I[DID10]

T QD[DID22]

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.9

Address Areas With memory indirect addressing, the address (memory location) is found in a
for Pointers 16-bit or a 32-bit address. This address can be found in one of the following
areas:
• Bit memory: as an operand addressed absolutely or as variable addressed
symbolically through the symbol table.
• Local data stack: as an operand addressed absolutely or as temporary
variable declared in the block’s declaration section.
• Global (Shared) data block: as an operand addressed absolutely. When
you use global (shared) DBs as the storage location for pointers, make
sure that the DB register (OPN DB n, for example) opens the “correct” data
block before accessing.
• Instance data block: as an operand addressed absolutely. When you use
instance data observe the following points:
• OBs and functions: Within functions or OBs, a pointer stored in an instance
data block can be used exactly as if it were stored in a global (shared) DB.
Just remember that instead of the DB register, the DI register is now used.
• FBs: Within FBs, instance data, that is, parameters or static variables,
cannot generally be used symbolically for memory indirect addressing.
• Absolute access of local data within an FB is, in principle, possible using
the “address” entered in the declaration section. However, when the FB is
used as multi instance, it must be noted that this address is not the
absolute address specified in the instance DB but is actually the
address relative to AR2.

Note When you pass pointers for memory indirect addressing to blocks or you want
to keep the value permanently in static variables, then you must copy the
pointer value from the parameter or static variable into a temporary variable.
Then complete the access using this temporary variable.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 9 Indirect Addressing (1)
Example of Memory Indirect Addressing

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.10

Description This example shows a function that initializes all bytes, that is, all variables of a
data block and overwrites them with the value "0".
In Network 1, the number of the data block passed via the input parameter
#DBNr is first of all copied onto the temp variable #Nr, which then serves to
indirectly open the data block. It is necessary to recopy onto a temp variable
because parameters cannot be used for indirect addressing.
In Network 2, the length [in bytes] of the data block is first of all determined and
assigned to the temp variable #number, which serves as the loop counter in the
subsequent LOOP.
Within the LOOP, the temp variable #Pointer is used for indirect addressing of
the data block byte that is first of all to be overwritten with the value 0. In the first
loop pass this is the DBB 0 because #Pointer was already initialized in Network
1 on the value P#0.0. With each loop pass the #Pointer is increased by the
value P#1.0 using DINT addition so that in the second loop pass #Pointer points
to DBB 1, in the third loop pass to DBB 2 etc..
Since the number of loop passes corresponds exactly to the length of the data
block in bytes, all data block bytes are addressed in ascending order via
#Pointer and overwritten with the value 0.

Note The system function SFC 21 (FILL) can also be used to delete or pre-assign a
memory area.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 10 Indirect Addressing (1)
Testing the Program Execution using Breakpoints (Part 1)

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.11

Breakpoints With the help of this test function, you can test a program you see in STL in
single-step mode and thus follow the sequence of the executed instructions as
well as the associated register contents.
You can set several breakpoints, depending on the CPU. The number of
possible breakpoints depends on the CPU used.

Note In order to carry out these test functions, you must have fulfilled the following
requirements:

• The "Test Operation" mode must be an assigned parameter.


• The block to be tested must be opened online.
• The LAD/STL/FBD Editor must be explicitly set to View Æ STL.
• The block must not be protected (Know_how_protect)

Breakpoint You can choose the breakpoint functions in the Program Editor by selecting the
Functions "Test" menu option or through the Breakpoint Bar.
You can activate the breakpoint bar by selecting the View Æ Breakpoint Bar
menu option in the LAD/STL/FBD Editor.

Attention If the program execution encounters a breakpoint, the CPU switches from RUN
to HOLD mode.
In this mode, the STOP LED lights up and at the same time the RUN LED
flashes. The outputs are deactivated for safety reasons.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 11 Indirect Addressing (1)
Testing the Program Execution using Breakpoints (Part 2)

Break-
point

Next
state-
ment

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.12

Breakpoint Bar
Set/Delete Breakpoint Breakpoints Active (on/off)
Show Next Breakpoint

Execute Call

Delete All Breakpoints Resume Next Statement

Set/Delete Breakpoint With "Set Breakpoint" you determine where the program execution is to be
halted. The breakpoint‘s statement is not executed. With "Delete Breakpoint",
you can once again delete the breakpoint.

Breakpoints Active With "Breakpoints Active" you activate all breakpoints; not only those already set
but also those still to be set.

Show Next With "Show Next Breakpoint", the Editor jumps to the next selected breakpoint,
Breakpoint without executing the program.

Resume With "Resume", the program execution continues at "normal speed" until it
reaches the next active breakpoint.

Next Statement With "(Execute) Next Statement", the program is executed "step by step" in
single-step mode. When a block call is reached, the called block is executed at
"normal speed" with "(Execute) Next Statement" and the single-step mode is
resumed with the statement following the block call.

Execute Call With "Execute Call", when a block call is reached, the called block is opened in
the Editor and the single-step mode is continued. At the end of the block, a jump
is made back to the calling block.
SITRAIN Training for ST-PRO2
Automation and Industrial Solutions Page 12 Indirect Addressing (1)
Task 1: Storing Part Weight Values (FC 35)

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.13

Task In AUTO mode, parts are transported from the light barrier bay to Bays 1 to 3.
Always at the moment when the part reaches the first empty bay or when the
conveyor is stopped (see slide, FC 35 – call condition), the just set weight value
"MW-Weight" (MW36) is to be stored in the data block "DB_Weight".
To manage the part weight values, the data block variables "Max_Number"
(DBB 0) with the maximum number of storable part weight values and
"Act_Number" (DBB 1) with the current number are used.
If the maximum number of storable part weights is reached, they are to be
overwritten with the new weight values starting from the beginning with
PartWeight[1].
An initialization can be triggered via the #Init parameter in which the FC
overwrites the "Act_Number" and all elements of "PartWeight" with 0. So that
"Act_Number" is in line with the total quantity determined in FB18, the
initialization must be triggered under the same conditions as for resetting the
count functions in FB 18:
• when switching on the AUTO mode ("L_AUTO", Q 4.3)
• when FC35 signals via #full that the maximum number of part weight values
has been reached ("Act_Number" = "MaxNumber") and the transport of
another part is started

FC 35 - Interface: Input Parameters:


"Init" is used to trigger the initialization of the DB
"new_Weight" triggers the storing of a new weight
"DeBe" is the number of the data block in which the weight values are stored
"Weight" is the current weight
Output Parameter:
"full" indicates with Status '1' that the maximum number of part weight values
has been reached ("Act_Number" = "MaxNumber")

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 13 Indirect Addressing (1)
Exercise 1: Storing Part Weights (FC 35)

Indirectly open data block via #DeBe

"Act_Number" >= "Max_Number" ?


yes no

#full := '1' #full := '0'

#new_Weight = '1' ?
no yes

#full = '1' ?
yes no

"Act_Number" := 1 "Act_Number" := "Act_Number" + 1


./.
#Point := "Act_Number" * P#2.0

#PartWeight[#Point] := #Weight

#Init = '1' ?
no yes

Overwrite "Act_Number" with 0

LOOP: For #looping = 1 to "Max_Number" do


./.
#PartWeight[#looping] := 0

#Point := #Point + P#2.0

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.14

What to Do 1. Create the data block "DB_Weight" (DB 35) with the variables shown in the
slide.
2. Insert the new block "FC_Weight" (FC 35) and declare the local variables
and parameters shown in the slide.
3. Create the FC 35 program according to the structogram.
4. Program the call of FC 35 in FB 18 as shown before.
5. Download all modified / newly created blocks into the CPU and test your
program. Watch the storing of the individual weight values by monitoring
the DB 35 online.
Tip:
To make it easier to monitor whether the data block really overwrites from
the beginning when the maximum number is reached, set the maximum
number to 5, for example.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 14 Indirect Addressing (1)
Task 2: Displaying Weight Statistics

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.15

Task: The "FC_Weight" (FC35) block stores the weights of the transported parts one
after the other in "DB_Weight" (DB35).
In addition to the total quantity already shown on the panel, the following weight
values are now also to be displayed:
• current weight ("MW_Weight", MW36)
• the total weight of all parts up until now
• the lowest weight up until now
• the highest weight up until now
• the average weight of all parts up until now

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 15 Indirect Addressing (1)
Exercise 2: Displaying Weight Statistics (FC 36)

Indirectly open data block via #DeBe

Initialize all OUT parameters


(#MinWeight, #MaxWeight, #CrossSec, #Sum :=0)

"Act_Number"= '0' ?
yes no
#MinWeight := 500 (largest possible weight)
#looping := "Act_Number"
#Point := P#2.0 (Address of PartWeight[1])

LOOP: For #looping = 1 to "Act_Number" do


#PartWeight[#looping] < #MinWeight ?
yes no

MinWeight := #PartWeight[#looping] ./.


./.
#PartWeight[#looping] > #MaxWeight ?
yes no

MaxWeight := #PartWeight[#looping] ./.

#Sum := Sum + #PartWeight[#looping]

#Point := #Point + P#2.0

#CrossSec := #Sum / #Act_Number

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.16

What to Do 1. Insert the new block "FC_WeightStat" (FC 36) and declare the local
variables and parameters shown in the slide.
2. Create the FC 36 program according to the structogram.
3. Program the call of FC 36 in FB 18 as shown before.
4. Download all modified / newly created blocks into the CPU and test your
program.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 16 Indirect Addressing (1)
If You Want to Know More

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.17

Note The following pages contain either further information or are for reference to
complete a topic.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 17 Indirect Addressing (1)
Area-Internal, Register Indirect Addressing

z Area-internal Pointer in AR 1 or AR2:


31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 0 0 0 0 0 0 0 0 0 0 0 0 B B B B B B B B B B B B B B B B X X X
215 20 22 20

not analyzed Byte address (unsigned integer) Bit


address

z Command Syntax:
LAR1 P#10.0 // Presetting of AR1: 00000000 0000 0000 0000 0000 0101 0000

+ 200
L M W [AR1, P#200.0]

Area Access Address Constant Executed: L MW 210


width register offset Instruction

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.18

Overview With register indirect, area-internal addressing, the address (memory location)
of the operand to be accessed is found in one of the two address registers (AR1,
AR2).
The address registers’ contents are, in this case, an area-internal 32-bit pointer
with the same configuration and the same meaning as with memory indirect
addressing.

Syntax With register indirect, area-internal addressing, the entire instruction consists of:
• an instruction (such as: A, L, T, etc.)
• an address identifier (such as I, MB, QD, etc.), that is the combination of an
area identifier (I, Q, M, DB, DI, etc.) and an identifier for the access width
(B=Byte, W=WORD, D=DWORD).
• and the declaration of an address register, which together with a constant
offset must be enclosed within square brackets. This offset is added to the
contents of the specified address register before the instruction is executed.
The address register’s contents and the offset have the format of area-
internal pointers consisting of byte address and bit address.
The offset’s declaration (even P#0.0) in the command syntax is imperative.

Notes • With indirectly addressed byte, word or double word addresses, the entire
offset must have the bit address "0". Otherwise the CPU triggers a runtime
error during execution of the instruction.
• If the AR1 or AR2 address register specified in the register indirect, area-
internal addressing contains an area-crossing pointer (see next page), then
the pointer’s area identifier is not evaluated during execution of the
instruction.
The area identifier in the address identifier is valid.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 18 Indirect Addressing (1)
Area-Crossing, Register Indirect Addressing

z Area-crossing Pointer in AR 1 or AR2:


31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

1 0 0 0 0 R R R 0 0 0 0 0 B B B B B B B B B B B B B B B B X X X

Area identifier Byte address (unsigned integer) Bit


address
Bit 31=0: area-internal
Bit 31=1: area-crossing

z Area Identifiers: 000 I/O 001 Inputs (PII)


010 Outputs (PIQ) 011 Bit memories
100 Data in DB Register 101 Data in DB Register 2 (DI)
110 own local data 111 LD of calling block

z Command Syntax:
LAR1 P#E10.0 // Presetting of AR1: 10000001 0000 0000 0000 0000 0101 0000

L W [AR1, P#200.0] + 200

Access Address Constant Executed: L IW 210


width register offset Instruction

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_07E.19

Overview With register indirect, area-crossing addressing, the area identifier (such as I, Q,
M, etc.) and the address (memory location) (byte.bit address) of the operand to
be accessed is found as area-crossing pointer in one of the two address
registers (AR1, AR2).

Syntax With register indirect, area-crossing addressing, the entire instruction consists
of:
• an instruction (such as: A, L, T, etc.)
• an identifier for the access width (B=BYTE, W=WORD, D=DWORD).
• and the declaration of an address register, which together with a constant
offset must be enclosed within square brackets.
The address register’s contents must be an area-crossing pointer with an
area identifier and a byte.bit address in this case.
The offset has the format of an area-internal pointer consisting of a byte and
bit address that is added to the pointer’s byte.bit address in the declared
address register before the instruction is executed.
The offset’s declaration (even P#0.0) in the command syntax is imperative.

Notes • With indirectly addressed byte, word or double word addresses, the entire
offset must have the bit address "0". Otherwise the CPU triggers a runtime
error during execution of the instruction.
• For CPUs that have older firmware versions, access to their own local data
(identifier: 110) is not possible with indirect area-crossing addressing.
In these cases, the runtime error "unknown area identifier" is triggered.
Access to their own local data is then only possible with area-internal
addressing.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 19 Indirect Addressing (1)

Potrebbero piacerti anche