Sign in to follow this  
Followers 0
apmcs1

Indirect addressing of DB address in S7-300

4 posts in this topic

I want to indirectly address DB50.DBW 420.0 through DB50 DBW 459.0 a word at a time (16 bit). This is in an FC using STL What I want to accomplish is check each word to see if it is between 20 hex and 7E hex and if it is not to set it to 20 hex. Would it be easier to just use decimal? 32 and 126 anyway this is what I have so far STRT: NOP 0 L p20 Load hex 20 into ACCU1 L DB50.DBW 420.0 Load value in DBW 420 into ACCU1 (moving old value into ACCU2) <L comparison is ACCU2 < ACCU1 (20<DBW 420) JC CHNG Jump conditionally (if true) to CHNG L p 7E >L JC CHNG JU NOCH CHNG: NOP 0 L p 20 T DB50.DBW 420.0 NOCH: NOP 0 Here I would like to add one to a pointer that is added to the beginning address of DB50.DBW 420.0 Check to see if the pointer is <=40 JC STRT Jump to start of this program to check the next register if pointer less than 40 clear or zero the pointer END Not sure if I am loading a hex value of 20 when I do the L p 20 I don't understand the indirect addressing I have ordered a book on Siemens S7-300, 400 but I don't have it yet, I am trying to learn by reading the help and the PDFs but their explanations and examples don't always make sense to me. Also ordered the step by step CDs from Siemens. Any help would be appreciated Thanks Dave

Share this post


Link to post
Share on other sites
I won't take credit for this, its a modernised copy of the built in examples you get in step 7 programming software. You need 2 TEMP variables created. BufferAR1 - DWORD Number - Int The code as follows TAR1 #BufferAR1 //save the current AR1 to replace at the end of the block. OPN DB50 // Open your data block L P#DBX 0.0 // Load first dataword in pointer format L 420 // your start address SLD 3 // The address is byte/bit format, so shifting right 3 moves the 420 outside the bit parts. // (not sure if L P#DBX420.0 will work OK) L 40 // Loop of 40 (459-420 = 40 words[check my math]) Next: T #Number // update loop counter A( L 32 L D [AR1, P#0.0] // If 32<= DW [x] <=I ) A( // AND L 126 <=I // DW [x] <= 126 ) JC INC // 32<=DW<=126 Jump over and INC loop pointer L 32 // 20 HEX T D[AR1, P#0.0] // into dataword INC: L P#2.0 //Offset in bytes to next dataword +AR1 // add it to address register using as indirect addressing L #Number Loop Next // Loop will decrement the number in the accumulator and jump to Next LAR1 #BufferAR1 // Once the loop has completed all 40 words, reload AR1 with what it originally had and //end here I found this example in the editing screen, select help and then help on STL, followed by a search of the term loop (usually used in indirect addressing problems). Also for pointer and any parameter descriptions, go to help and contents, down near the end of contents you will see appendix, open that and select data types and parameter types and then under parameter types it gives very good descriptions of how pointers and any's are made up. Siemens S7 is far superior to S5 in the help and examples it has built in.

Share this post


Link to post
Share on other sites
Wow! Thank you so much Groo I knew what I wanted to do but was so far off it's pitiful. I am now looking up all the functions you used so I will understand it all before using it. I'm sorry but I just don't get a lot of their explanations in the help files, I come from a background of Modicon 584, 984, Allen Bradley PLC5, SKC500, Direct Logic, plus various small PLC's and these Siemens seem very powerful but are very different. What also makes it hard to understand the programs I have right now in S7-200's and a S7-300 is that all the descriptors and comments are in German. Thanks again Dave Welch

Share this post


Link to post
Share on other sites
Just noticed I made a small mistake, I said to check the maths, you want 40 bytes, 20 words, so the loop should be preset with 20 not 40. I've done quite a bit in the past with Modicons and Bradleys but mainly Siemens, think Step 7 is best on market at the moment, very powerful and got rid of most of the annoying things that spoilt S5. Glad it helps anyway *2 Forgot an important bit as well.. after L P#DBX 0.0 // Load first dataword in pointer format L 420 // your start address SLD 3 // The address is byte/bit format, so shifting right 3 moves the 420 outside the bit parts. ensure you have +D // add double words, thats the address as a pointer LAR1 // and store into the address register No.1 very important that bit sorry Edited by Groo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0