You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old November 19th, 2002, 09:09 AM   #1
charmer
Member
United Kingdom

charmer is offline
 
Join Date: Nov 2002
Posts: 3
Siemens STL Code

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
  Reply With Quote
Old November 19th, 2002, 10:38 AM   #2
PLucas
Member
England

PLucas is offline
 
PLucas's Avatar
 
Join Date: Apr 2002
Location: Gillingham Kent
Posts: 1,743
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
  Reply With Quote
Old November 19th, 2002, 03:59 PM   #3
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, UMSA, United Marxist States of America
Posts: 5,486
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.


Quote:
Originally posted by PLucas
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.
  Reply With Quote
Old November 19th, 2002, 05:41 PM   #4
OB90
Guest
 
Posts: n/a
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
  Reply With Quote
Old November 20th, 2002, 08:39 AM   #5
charmer
Member
United Kingdom

charmer is offline
 
Join Date: Nov 2002
Posts: 3
Smile 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
  Reply With Quote
Old November 20th, 2002, 11:00 AM   #6
john paley
Member
United States

john paley is offline
 
john paley's Avatar
 
Join Date: Apr 2002
Location: Tennessee
Posts: 304
Wellll,

Aren't you gonna tell us what the hell it does???? I, for one, would like to know.
__________________
The Big Cheese
  Reply With Quote
Old November 20th, 2002, 03:14 PM   #7
OB90
Guest
 
Posts: n/a
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
  Reply With Quote
Old November 21st, 2002, 03:16 AM   #8
charmer
Member
United Kingdom

charmer is offline
 
Join Date: Nov 2002
Posts: 3
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
  Reply With Quote
Old January 9th, 2008, 09:19 PM   #9
fh43bktdh
Member
Viet Nam

fh43bktdh is offline
 
Join Date: Jan 2008
Location: HAI DUONG
Posts: 5
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;
  Reply With Quote
Old January 10th, 2008, 02:09 AM   #10
L D[AR2,P#0.0]
Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 4,542
Here's how you start a new thread:

  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Simulator, Simulation, Shadow Code Terry Woods LIVE PLC Questions And Answers 1 January 2nd, 2005 01:40 PM
Siemens S7-300 Encoder Setup. damirault LIVE PLC Questions And Answers 4 August 30th, 2004 01:04 PM
starting out Brendan Dixon LIVE PLC Questions And Answers 8 June 20th, 2004 08:48 PM
Automatin Direct Changes Download ArikBY LIVE PLC Questions And Answers 53 May 12th, 2004 12:05 AM
Siemens S7 pointer +stl question DeHulk LIVE PLC Questions And Answers 3 March 26th, 2003 09:29 AM


All times are GMT -5. The time now is 07:03 AM.


.