![]() |
||
|
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc. |
||
| ||
New Here? Please read this important info!!!
|
|
#1 |
|
Member
![]() 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 |
|
|
|
#2 |
|
Member
|
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 |
|
|
|
#3 | |
|
Member
|
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:
Code:
L DIW [AR2,P#8.0] 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. |
|
|
|
|
#4 |
|
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 |
|
|
|
#5 |
|
Member
![]() Join Date: Nov 2002
Posts: 3
|
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
|
|
|
|
#6 |
|
Member
|
Wellll,
Aren't you gonna tell us what the hell it does???? I, for one, would like to know.
__________________
The Big Cheese |
|
|
|
#7 |
|
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 |
|
|
|
#8 |
|
Member
![]() 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 |
|
|
|
#9 |
|
Member
![]() 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; |
|
|
|
#10 |
|
Supporting Member
![]() Join Date: Nov 2006
Location: UK
Posts: 4,542
|
Here's how you start a new thread:
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |