indirect addressing s5 s7

Download Indirect Addressing S5 S7

Post on 30-Nov-2015

173 views

Category:

Documents

10 download

Embed Size (px)

DESCRIPTION

S7 programming reference

TRANSCRIPT

  • STEP 7 -- Creating S7 programs -- Indirect Addressing

    Entry ID:24519683 Date:2011-08-09

    STEP 7 -- Creating S7 programs -- Indirect Addressing Why are the bit and byte addresses changed when indirectly addressing a program converted from S5 to S7? How can you open data blocks indirectly and do an indexed call, start and evaluation of timers? Information on the topic of "Indirect addressing" What is the difference between STEP 7 and STEP 5 with regard to the operations for indirect addressing? How do access the I/O address area indirectly and what should you watch out for when copying with the SFC20? How can you access an element indirectly in STL in a two-dimensional array (e.g. a value in line 2 and column 5)? In the case of a function, how is the address of the ANY pointer for the elementary IN, OUT and IN-OUT parameters loaded into the address register AR1? How can you calculate an offset for an ANY pointer or change the pointer? How can you use "CHAR"-type variables for FC1 (DP_SEND)? How do you parameterize blocks, which have "ANY"-type or "Pointer" type parameters? Why are indirect calls using AR2 replaced by static local variables after saving the block? In which operations does STEP 7 overwrite ACCU or register contents?

    Why are the bit and byte addresses changed when indirectly addressing a program converted from S5 to S7?

    Description: When calculating the address in STEP 5, bits 12 to 15 are used for the interim results. But these bits are not needed for indirect addressing in STEP 5. Unlike DO instructions (e.g. "B MW") in STEP 5, in STEP 7 addressing is via double-words, because of the extended address area. With the instruction in STEP 7, an area (E, A, M), an access range (bit, byte, word and double-word) and an address are specified. The address contains the byte number.

    The structure of the address register must be observed when an address is preset via the Accu:

    RRR: area identifier B...B: byte address XXX: bit address

    Fig. 01

    If the program is now converted to STEP 7, then when bits 12 to 15 are used by STEP 7 the system changes the addresses.

    Fig. 01 shows an example of a bit pattern "W#16#221". After conversion, the address "33.2" is calculated.

    http://support.automation.siemens.com/US/view/99/24519683

    Page 1 of 35 2/24/2012 3:06:40 PM

  • Fig. 02

    Fig. 02 shows the same program, but with the bit pattern"W#16#1221". The leading "1" is not evaluated by STEP 5. After conversion, however, the address "35.2" is calculated by STEP 7. The reason for this is that the leading "1" at the bit point is placed by the system in the byte address with value 2.

    Fig. 03

    Remedy: If you can't ensure that bits 12 to 15 are not used, then change the two move commands as follows.

    SLW 5 to SLW 12. SRW 5 to SRW 12.

    After conversion, however, the correct address "33.2" is calculated in STEP 7.

    Fig. 04

    Keywords: S5/S7 converter

    Fig. 01

    http://support.automation.siemens.com/US/view/99/24519683

    Page 2 of 35 2/24/2012 3:06:40 PM

  • Fig. 02

    Fig. 03

    http://support.automation.siemens.com/US/view/99/24519683

    Page 3 of 35 2/24/2012 3:06:40 PM

  • Fig. 04

    How can you open data blocks indirectly and do an indexed call, start and evaluation of timers?

    Instructions You have the following options for opening a data block indirectly:

    By programming with a formal parameter of the "BLOCK_DB" parameter type (Example 1). By way of a local data word (temporary block variables) (Example 2). Through indirect memory addressing (Example 3).

    Fig. 01 shows three examples of indirect opening of a data block in STL.

    http://support.automation.siemens.com/US/view/99/24519683

    Page 4 of 35 2/24/2012 3:06:40 PM

  • Fig. 01

    Example 1 In this case, input parameter "Data2" is given a formal parameter of the "BLOCK_DB" type. The content of "Data2" corresponds to the number of the data block to be opened.

    Example 2 Input parameter "InWord" of the "WORD" type is given to the temporary variable "Data1". The number in the temporary variable "Data1" of the "WORD" type is the number of the global data block. The global data block is then opened with AUF DB[Data1].

    Example 3 With indirect memory addressing, here, for example, DB number 10 is saved in marker word MW20. The instruction AUF DB[MW20] opens the global data block whose number is contained in marker word MW20. AUF DB[MW20] thus corresponds to AUF DB10.

    Further methods for opening data blocks with indirect memory addressing are possible with AUF DB[DBW ] and AUF DB[DIW ].

    If no FBs are used, both DB registers may be used freely, i.e. all variants can also be opened with AUF DI ....

    Note For more information see the STEP 7 Online Help under keyword "Legal data types in the transfer of parameters".

    Indexed call, start and evaluation of TIMER You can make an indexed call of a timer by way of a tag of the WORD data type. This tag can be

    A global tag [MW] A local tag in a DB [DBW]

    http://support.automation.siemens.com/US/view/99/24519683

    Page 5 of 35 2/24/2012 3:06:40 PM

  • A temporary tag in a block

    Access is as follows (example):

    Keywords: Indirect addressing, DB call

    SI T[MW2] //The timer number is in marker word 2, hex coded.SI T[DBW2] //The timer number is in data block word 2, hex coded. The DB must be opened

    explicitly beforehand.SI T[#time_x] //The "#time_x" tag is a temporary tag of the WORD data type.

    Information on the topic of "Indirect addressing"

    Instructions Information on the topic of "Indirect addressing" is available in the following manuals and chapters / sections and in the Online Help.

    Document Version Chapter / section Entry IDManual on "Programming with STEP 7"

    05/2010 27.3.4 Parameter Types 45531107

    STEP 7 Online Help V5.5 Format of the parameter type ANY Format of the parameter type POINTER

    What is the difference between STEP 7 and STEP 5 with regard to the operations for indirect addressing?

    Instructions: For indirect addressing in STEP 7 a difference is made between

    1. Memory indirect addressing with a number: for addressing timers, counters and blocks.

    2. Register indirect addressing with an area pointer: for addressing memory areas: I/O, inputs, outputs, markers, global data (DBX), instance data (DIX) and local data.

    Memory indirect addressing with a number:

    Examples:

    STEP 7 Equivalent in STEP 5

    L 2 Load number L KF+2 Load number

    T MW 33 Save in bit memory word 33

    T FW 33 Save in flag word 33

    L T [MW33] Load current time value of Timer 2

    DO FW33 Process flag word 33

    L T0 Load current time value of Timer 2

    ....... ....... ....... .......

    http://support.automation.siemens.com/US/view/99/24519683

    Page 6 of 35 2/24/2012 3:06:40 PM

  • The address operand, in which the number is stored (here MW33), can be in the following areas: marker, global data (DBX), instance data (DIX) and local data. In function blocks (FBs) it is only possible to use the area instance data (DIX) for the address operand in CODE_VERSION1 (non-multi-instance-compatible FB).

    Register indirect addressing with area pointer

    Example for an internal area pointer

    Example for cross-area pointer:

    Pointer calculations

    A decisive property of the area pointer is that pointer calculations can be made with the normal fixed-point operations. So for any pointer the following holds:

    Addition of 1: increase pointer to next bit. Addition of 8: increase pointer to next byte, leave bit number unchanged.

    Examples:

    OPN DB[MW33] Open DB2 B MW33 DO marker word 33 C DB0 Open DB2

    ....... ....... ....... .......

    CC FC[MW33] Call FC2 if RLO=1: DO FW33 Process flag word 33 works only

    if FC2 has no parameters

    JC FC0 Call FC2 if RLO=1: works only if FC2 has no parameters

    STEP 7 Equivalent in STEP 5

    L P#4.5 Load pointer for byte 4, bit 5

    L KF +4 Load byte number

    L KF +5 Load bit number

    SLW 8 Move bit number in high byte

    OW Bit in high byte, byte in low byte

    STEP 7 Equivalent in STEP 5

    L P#M 2.3 Load pointer for M2.3

    STEP 7 Equivalent in STEP 5

    L P#M 2.3 Load pointer for M2.3

    L P#4.5 Load pointer for byte 4, ....... .......

    http://support.automation.siemens.com/US/view/99/24519683

    Page 7 of 35 2/24/2012 3:06:40 PM

  • In calculations with area pointers, you can only use one pointer with area identifier (not equal to zero). Otherwise the points of the area identifier are "added" or "subtracted" and this results in an invalid identifier.

    Memory indirect addressing with area pointer

    Examples:

    bit 5

    +D Result: pointer for M7.0, i.e. all 3 instructions are equivalent to: L P#M7.0

    ....... ....... ....... .......

    L P#DBX 2.3 Load pointer for global data bit 2.3

    L 16 Load 16 .......

    -D Decreases pointer by 16 bits, i.e. all 3 instructions are equivalent to: L P#DBX0.3

    STEP 7 Equivalent in STEP 5

    L P#2.0 Load pointer for byte 2, bit 0

    L KF+2 Load byte number

    T MD44 Save in bit memory double-word 44

    L KF +0 Load bit number

    A I [MD44] Query of input 2.0 for signal status 1

    SLW 8 Move bit number in high byte

    OW Bit in high byte, byte in low byte

    T FW44 Save in flag word 44

    DO FW44 Process flag word 44

    A I 0.0 Query of input 2.0 for signal status 1

    ......... .......... ....... .......

    L 123 Lo

Recommended

View more >