Siemens STL Code

charmer

Member
Join Date
Nov 2002
Posts
3
I have just started out coding in STL and i have been given this piece of code to decipher

L DIW [AR2,P#8.0] //LOAD DEST DB#
T #DBNUM
OPN DB [#DBNUM] //OPEN DEST DB
L #BYTES
T #COUNT
L DIW [AR2,P#12.0] //DEST DB BIT OFFSET
LAR1 //AR1 -> DEST db
TAR2 //STORE DI OFFSET
T #SAVEAR2
L #LADDR //BYTE OFFSET IN PI
SLD 3 //..BIT OFFSET IN PI
LAR2 //AR2 -> PI
CILP: L #COUNT
L 0
<=I
JC CIDN
L PID [AR2,P#0.0]
T DBD [AR1,P#0.0]
+AR1 P#4.0
+AR2 P#4.0
L #COUNT
L 4
-I
T #COUNT
JU CILP
CIDN: NOP 0
LAR2 #SAVEAR2
SET
SAVE

Can any one help decipher what this piece of code does

Thanks
 
Charmer,

I might be able to help you on this, but I am not convinced that what you have posted is exactly what's in the program.

Also what does the PLC control that this code is taken from?

I will try and explain a few bits of the code for you

L DIW [AR2,P#8.0]

that means Load Data block Input Word

AR2 is Accumalative Register 2 P#8.0 will load a 32bit pointer into the address specified

OPN DB

This will open the data block specified, number missing from the code you posted (eg. OPN DB10)

going further down your code

T -this is the transfer instruction.

SLD 3 - this means Shift Left Double word 3 times

<=I - this means greater than or equal to the Integer in accumulator 2 or in your case is the integer in count <= 0.

SET means SET the RLO (result of logic operation) to '1'

That is all that I can drag out of the old grey matter at the moment without digging my manuals out.

I hope this helps, I sure others will chip in as well

Paul
 
Almost

Charmer, I agree with Paul. This can't be an accurate transaltion, but it looks to me like it is copying 32 bit values from and address in #LADDR ( LONG ADDRESS, WITH DB and OFFSET? ) to an address initially pointed to AR2. AR2 get used as a source pointer later in the code.

The register #BYTES controls the number of 32 bit transfers, not the number of bytes transfered.


PLucas said:
Charmer,

I might be able to help you on this, but I am not convinced that what you have posted is exactly what's in the program.

Also what does the PLC control that this code is taken from?

I will try and explain a few bits of the code for you

L DIW [AR2,P#8.0]

that means Load Data block Input Word

AR2 is Accumalative Register 2 P#8.0 will load a 32bit pointer into the address specified

Paul

Code:
     L     DIW [AR2,P#8.0]
This LOADS a value, pointed to by AR2+8, into the accumulator.
ARX is an ADDRESS REGISTER. In your case, address register 2.

I also have my doubts about DIW. I think DI is data instance. There are two Data Block Registers that specify which data areas are accessible at that time and you must chose between them by specifying DBW or DIW. I/O us ccessed using the P.



In Siemens STL the addressing mode [ARX,P#XX.X] can be used in two ways.

1. The P#XX.X can be an array address in the current data block and ARX can used as a index into the array.

2. A pointer to a record or structure can be loaded into ARX. The P#XX.X can be used as an offset to access different field of a record such as name, rank and serial number. Name would have an offset of 0 so it would use [ARX,P#0.0]. The rank would be offset by the number of allowable characters in the name. Lets say 20 so to access the rank one would use [ARX,p#20.0]. Serial number would be att offset 24 from the beginning of the name so the serial number would used [ARX,P#24.0]

Siemens makes complex addressing easy. It is too bad that P#XX.X can't be a literal that is compiled so I can used [ARX,P#Name],[ARX,P#Rank] and [ARX,P#Serial]. This would be more self documenting and much easier to maintain. Just think of what happens if I didn't allocate enough characters for the name and I must expand name field to 32 characters. Now I must change the hard coded offset for Rank and Serial Number everywhere ( all changes should be in just one file if you wrote the code right) in the program. That is a lot of work and is error prone. Hopefully Siemens will fix this in the future.
 
Hi, Charmer,

Interestin program, althoug I don´t understand all...

L DIW [AR2,P#8.0]
Load instance data word (Data word Nr. is specified by the content of the AR2 Register + 8 Bytes

T #DBNUM
Transfer to the local data variable called DBNUM

OPN DB [#DBNUM]
Open the DB that´s Number is stored in #DBNUM

L #BYTES, T #COUNT
The content of another local variable (probably var_in) is stored in
the (temporary?) local data of this code block

L DIW [AR2,P#12.0]
As Above

L AR1, T AR2, T #SAVEAR2
Transfer the content of Accu1 into the AR1 register, load the content
of the AR2 register to accu 1, transfer to local data Dword called
SAVEAR2, because you want to restore the original AR2, for further use

Then the content of the local Dword #LADDR is loaded, the SLD instruction is to shift that value 3 times left, then the value is
stored in AR2 (The SLD 3 instruction is necessary, because the bits 0..2 of a pointer or an AR register are the bit adress of an adress
identifier, you can´t use them to load a Dword)

CILP: L #COUNT
L 0
<=I
JC CIDN
L PID[AR2,P#4]
T DBD[AR1,P#4]
L #COUNT
L 4
-I
T #COUNT
Here, The local data word #COUNT is compared with 0, if equal or less the program brances to the label CIDN:, then comes another interesting part: The content of the specified peripherial input Doubleword (not the process image of inputs!) is transfered to the
data doubleword calculated by the content of AR2+ 4 bytes.
Then the value of #COUNT is loaded in Accu1, is decreased by 4 and
written bach into #COUNT again.

The last instructions only restore the "original" AR2 (instruction 9,
you remember...)
Then the RLO is set to 1 and then saved into the BR- bit of the
statusword. (For use in the block that has originally called your code block?)

Just as PLucas writes, i also think that this isn´t the complete code,
the local data declaration table is also missing...
Hope this is some sort of help to you.

Greetings
OB90

:BE
 
Thank you

Thank you everyone for your help i have been able to deturmine what the code is doing and have also been contacted by the person who wrote the code.

Thank you again

Chris :)
 
To cut a long story short...

Hi, John,

This code is mainly for copying some Doublewords from the peripherial input data area into a datablock, until the value of #COUNT is less or equal to zero...

Greetings

OB90

:BE
 
Hi, John,

OB90 is correct the code copies a chunk of data from a device on a PROFIBUS network and moves it to a data block.

Thanks again for everyones help

Chris
 
ar2

L 0
T #i
A80a: L #i
L 3
<=I
JCN A809
L #i
ITD
L L#2
+D
L L#8
*D
TAR2
+D
LAR1
L DIB [AR1,P#64.0]
L #DB_SCALE
T LW 56
TAK
T LB 55
TAK
L #ti_ADR
L #i
+I
ITD
L L#8
*D
L LB 55
OPN DB [LW 56]
TAK
LAR1
TAK
L DBB [AR1,P#0.0]
<>I
JCN A80c
SET
= L 30.0
= #sb_APPL_ID_ERR
A80c: L #i
L 1
+I
T #i
JU A80a
A809



I need help from every one. why ar2 to be use that. before ar2 not use any LAR2 or other. content in curent have what?
anyone help me change to SCL please! that is loop:
FOR i:=0 TO 3 BY 1 DO....

END_FOR;
 
Here's how you start a new thread:

new001.JPG
 

Similar Topics

IS it possible to write this on a better way: L #db_Num2 L 121 ==I JNB _02 CALL "CONT_C" , "DB_reg_igla1"...
Replies
3
Views
2,621
so the code I am trying to do loads two different values and then I try and tell if the value subtracted from the other value is less than 15 and...
Replies
11
Views
4,291
Hello I am incrementing db8.dbw0 by one in another fb and comparing it to acc1 whenever m199.7 is set would there be cleaner way to do this. I'm...
Replies
5
Views
2,672
Hi Siemens Experts, I am hoping someone can shed some light on my issue. I have uploaded the code from a S7-300 (317-2PN/DP) using Step 7...
Replies
9
Views
651
I'm having trouble trying to convert this code to ladder, anyone able to help me? A M4.0 A M4.1 A M117.0 AN M17.7 A ( A I38.6 AN I3.7 O ( A M4.5...
Replies
8
Views
1,203
Back
Top Bottom