5/18/2011 11:28 AM | |
Posts: 270 Rating: (53) |
Hello vominhtan68, I'll try to explain line by line, however, if you open the program in something like Step 7 programming environment, you can alwaysmove the cursor on/ina name of STL instruction and press F1, which should open context help with the instruction. Also, what exactly happens kinda depends on the data you might have stored in the datablocks used. Also, I didn't get much sleep, so there might be some misscalculation of something or so, but you should get the general idea. .) OPN DB126 // this opens data block 126 L 4 // this loads number 4 into ACCU1 (generaly, L loads a number (in decimal by default) into ACCU1 SLW 3 // this shifts the little word of ACCU1 to left by 3. Now to understand this, ACCU1 has 32 bits (two words) and this only shifts bits 0 - 15 of it and doesn't affect the big word of ACCU1. SLW shifts those bits by specified amount. Essentaily, what it does in this case is it multiplies 4 by 8 (every logical shift left multiplies number by 2), so in ACCU1 you have stored number 32 now. LAR1// this loads the contain of ACCU1 into AR1 (address register used for address pointing used by following instruction), creating pointer to the location (converts bits into bytes, so divide the number in ACCU1 by 8. L DBD[AR1,P#12.0] // this instruction loads the double word from your previously opened data block using the address (AR1) and that address increased additionaly by pointer (P#12.0 - 12 bytes increase)into ACCU1, so what it does is to load the 4 bytes from DB 126 starting from byte16 which is now (also) in ACCU1. T DB10. DBD4 // this instruction is the opposite of L, it takes the contain of ACCU1 and stores it into specified location, which is, in this case, double word 4 in data block 10. One thing on a side note, which someone else would need to clarify, or you, if you try it with the data and see what the result is, I am not sure if this doesn't actually interrupt your opening of DB126 from before, so I'm not sure if in your following instruction you wouldn't actually read from DB10 instead of DB126 again. I'll asume not, but in general, this is kind of error that could cause you spent two nights searching for it, so that's why I mention it anyways. .) L DBD[AR1, P#16.0] // same as the time used before, this time, though, the AR1 address is increased by 16, so it's total of 20. L 100000E +003 // here comes the sweet/nice/tricky/etc part about L. You have in your CPU more than just one ACCU, specificaly, L works with with 1 and 2. So, it would load a number into ACCU1. But since you already have a value stored there, it moves the value from ACCU1 into ACCU2 and then stores the new value in ACCU1. The value is written not exactly correct, it's supposed to be 1.000000e+008 in the STL editor, but either way, it loads 100 000 000 into ACCU1. *R // this instruction multiplies two real floating point numbers stored in ACCU1 and ACCU2 and stores the result in ACCU1. RND // instruction RND rounds the real floating point 32-bit number in ACCU1 into 32-bit integer and keeps it then in ACCU1 TDB10. DBD8 // same as before, you store the value in ACCU1 into double word starting at 8th byte in data block 10. Anyway, as I said in start, you can find those and any other instructions explained in the Step7 help, if you want to see the actual result, look into those data blocks for the values stored at the specified places and also, if you want to proceed in working with STL, I suggest you to pass some sort of course or read some manuals at least, nice one for STL can be found athttp://support.automation.siemens.com/WW/view/en/45531107. Hope this helped, gl with you work with STL |
Last edited by: MM1234 at: 5/18/2011 11:32 AMOh ye, thanks miami, noticed a thing I forgot regarding the LAR1 .] |
|
This contribution was helpful to4 thankful Users |
5/18/2011 12:09 PM | |
Joined: 4/22/2010 Last visit: 5/3/2024 Posts: 5697 Rating: (714) |
Verry detailed answer I have attached a list of Stl statements, might be handy. Best regards, Marcjan AttachmentSTL-cheat-sheet-by-category.pdf (310 Downloads) |
Problem solved? |
|
This contribution was helpful to2 thankful Users |
5/19/2011 3:09 AM | |||||||||||
Joined: 10/7/2005 Last visit: 7/15/2024 Posts: 3009 Rating: (1053)
|
Yes it can be done that way. the thing though is that the above as well as the original logic use indirect addressing even though the "index" value (value of 4 in the original logic) is a constant!. This- while functional and working- is simply not efficient coding and achieves nothing other than creating unnecessarily complicated logic. Overall, the original logic can be implemented as below: [code]LDB126.DBD16 TDB10.DBD4 LDB10.DBD20 L 100000E +003 *R RND TDB10.DBD8[/code] I hope this helps |
||||||||||
Last edited by: fritz at: 5/19/2011 7:07 AMCheers |
|||||||||||
This contribution was helpful to3 thankful Users |
5/14/2018 9:23 AM | |
Joined: 6/19/2017 Last visit: 6/28/2024 Posts: 8176 Rating: (169) |
New question published by sumeet85 is split to a separate thread with the subject FC408. Best regards |
My Forum is the place to personalize your profile, |
|
Follow us on