SiemensPLC#S7300_400 Pointer in STL

This topic I would like to explain some details about ”indirect addressing” for S7-300_400.In Mitsubishi PLC, there are  Zindex(Indexed addressing) to access other devices by  change the values of Z. In Omron, there is ”*” (indirect addressing) to define where you want to access.But unfortunately it seems no method to use indirect addressing in Ladder(From internet this function may be possible TIA V13 SP2…)So,Now You have 2 methods :

  1. STL
  2. SCL

Only this two ways.OK, we will learn and meet new things every day so do not need to afraid it ;)!

From Wiki

Instruction List (IL) is one of the 5 languages supported by the IEC 61131-3 standard. It is designed for programmable logic controllers (PLCs). It is a low level language and resembles assembly. All of the languages share IEC61131 Common Elements. The variables and function call are defined by the common elements so different languages can be used in the same program.Program control (control flow) is achieved by jump instructions and function calls (subroutines with optional parameters).

//Example of STL
LD 5//Load 5 to AC1
T MW202//Transfer to MW202
LD 20//Load 20 to AC1
T MW220//Transfer to MW220

Pointer and ANY DATA TYPE

You need to define a pointer data type while you are using indirect addressing.It is defined by P# and has 3 types of format showed below:

P#2.0//P#Byte Bit
P#M50.0//P#Area Byte Bit
P#DB19.DBX3.0 BYTE 14//P#Area Byte Bit Length

IF you need to access DB, instruction ”OPN” is necessary.

Refer to the Manual…

OPN<data block>
opens a data block as a shared data block or as an instance data
block. One shared data block and one instance data block can be open at the same time.

OPN DB10//Open DB10 as shared Data Block
L DBW20//Load DBWord 20 to ACC1
T MW200//Save it to MW200
OPN DI11//Open DB11 as Instance Data Block
L DBW50//Load DBWord 50 to ACC1
T MW202//Save it to MW202

And it is safely to  make sure that you are opening a correct DB and that DB has enough Data length by using these instruction below..

//save the Shared DB that opened into ACCU1
//save the Length of Shared DB that Opened into ACCU1

//save the Instance DB that opened into ACCU1
//save the Length of Instance DB that Opened into ACCU1

L MD30 // Devices that save the compare length
‘&amp;amp;amp;amp;amp;gt;’D // if the size of DB is Smaller than
JC ERR // jump to ERR

Memory Indirect Addressing

Using Memory indirect addressing can let you access different devices by only change the contents of ”Index”(Just like Zindex in Mitsubishi) .
The Pointer format must be defined to 16 bit word while you need to access T、C、DB、DI、FB or FC.

L 20 //Load 20 to ACCU1 as a Pointer
T MW10//Save it to MW10
L T[MW10]//Load the current value of T20 to ACCU1
OPN DB[#DBPointer]

The Pointer format must be defined to 32 bit Double word while you need to access I, Q, M, L, DB.

L P#0.5 //Load &amp;amp;amp;amp;amp;amp;amp;nbsp;0.5 into Pointer Value
T MD100//Transfer the pointer to MD100
A Q[MD 100]//Check Q0.5
= M[MD 100]//If ON, Assign M0.5 to ON

OPN DB10//Open DB10
P P#3.0//Load 3.0
T #Pointer//Transfer the pointer to Local variable #Pointer
L DBW[#Pointer]//Load DB10.DBW3
L 0 //Load 0
&amp;amp;amp;amp;amp;amp;amp;gt;D//Compare with 0

It is possible to add these two pointer to get a new pointer(In Line3).

L P#1.0//Load the First Pointer value
L P#3.0//Load the second Pointer value
+D // Add this 2 pointer
T MD 0// Now the MD0 contains P#4.0.

Q:What is the result of P#1.1+P#7.7?
A:P#9.0.Because The address next to P#8.7 is P#9.0 not #8.8 and it is invalid.

Address Registers

AR1 and AR2 are the Address Registers that provided from S7 and let the programmer to access devices more flexibly.

LAR1 //Load AR1 With the Contents of ACC1&amp;amp;amp;amp;amp;amp;amp;nbsp;
LAR1 P#M100.0 //Load AR1 with a pointer Values
LAR1 MD30//Load AR1 With Pointer in MD30
LAR1 AR2//Load AR1 with the Contents of AR2

TAR1 //Transfer AR1 to ACC1
TAR1 MD30//Transfer AR1 to MD30
TAR1 AR2//Transfer AR1 to AR2

CAR//Exchanges AR1 and AR2

+AR1//Add ACC1 into AR1 and save into AR1
+AR1 P#200.0//Add the pointer constant to AR1 and save into AR1


So How to use AR1 ,AR2 ?Please follow the below format:

address identifier [address register, pointer]

Address Identifier can be I, Q, M, L, DI or DB in bit, byte, word or double word but the format must be 32Bit.

L P#M10.0//Load Pointer Value P#10.0
LAR1//Transfer to AR1
L W[AR1, P#0.0]//Load MW10
L W[AR1, P#2.0]//Load MW12

L P#M0.7//Load Pointer Value P#M0.7
LAR1//Transfer to AR1
L P#0.7//Load Pointer Value P#Q0.7
LAR2//Transfer to AR2
L M[AR1,P#1.0]//Load M1.7
= Q[AR1,P#0.1]//Assign to Q1.0

OPN DB100//Open DB100
L P#DBX0.0//Load Pointer Value
LAR1//Transfer to AR1
L #100//Load 100
T D[AR1,P#100.0]//Transfer to DB100.DBD100

The Above example is a basic application of Using AR1 and AR2.

Line4#The result of access MW12 because Pointer is P#2.0 and AR1 is M10.0
Line9#Same as Line4, Pointer is P#M0.7 and AR1 is 1.0, just ADD These ;).
Line15#open DB100 and set the pointer to 100.0. please take a look on the ”D” of D[AR1,P#100.0]. Because It is ”D”, the devices accessed in here is DBD100.
If we change D to W—–W[AR1,P#100.0], the devices accessed in here is DBW100.

Please comment it if you have any things that would like to discuss with me:)!
In the Next Time..

ーSiemensPLC#S7300_400 Pointer in SCL
ーSiemensPLC#S7300_400 Pointer with ARRAYをアクセス方法 in STL
ーSiemensPLC#S7300_400 Pointer with ARRAYをアクセス方法 in SCL

See u!!


Please Support some devices for my blog

Amazon Gift List

Find ME

Email:soup01threes* (* to @)


  • このエントリーをはてなブックマークに追加