s7 indirect addressing

interlock

Member
Join Date
May 2011
Location
Middle East
Posts
29
Hello,
The STL codes are as under for an s7-300 program?

A M 3.0
JC Z1

LAR1 P#3.0
A I [AR1,P#0.0]
= Q [AR1,P#0.0]
T AR1 MD4
S M 3.0

Z1: A M 3.1 "PUSH BUTTON"
FP M 3.2
= M 3.3

A M 3.3
JCN Z2

L AR1 MD4
+AR1 P#0.1
A I [AR1,P#0.0]
= Q [AR1,P#0.0]
T AR1 MD4
Z2: NOP 0

The program intially assigns the value of I3.0 TO Q3.0.
Thereafter, with every press of push button M3.1 , the values of I3.1 , I3.2 , I3.3 ....... are assigned to Q3.1 , Q3.2 , Q3.3 ......
Do we really need those load , transfer , load , transfer commands between AR1 and MD4?
why can't we work around with AR1 alone to do the job?
It is to be noted that indirect addressing is being used only in one network and in one FC only (It is not used anywhere else in the program).
So why those codes are loading and transferring between AR1 and MD4 as if AR1 data will be over-written somewhere else in the program?
or is it poor programming?
Regards
 
Your analysis of this code is incorrect, the incrementing of the address only occurs if I3.0=1 as the set of M3.0 is dependant on the state of I3.0

MD4 is used to save the incrementing address so I would ditch the use of AR1 viz:

Code:
      A     M      3.0
      JC    Z1

      L     P#3.0
      T     MD     4
      A     I [MD     4]
      =     Q [MD     4]
      S     M      3.0

Z1:   A     M      3.1
      FP    M      3.2
      =     M      3.3

      A     M      3.3
      JCN   Z2

      L     MD     4
      +     1
      T     MD     4
      A     I [MD     4]
      =     Q [MD     4]
Z2:   NOP   0
 
Yes, the codes go ahead only when I3.0 is "true".
BUt I'm curious to know why can't we do this with AR1 alone?
Isn't "+AR1 P#0.1" sufficient to increment bit-by-bit if we keep looping around.
(Ofcourse , its good you eliminated the AR1 altogether ........ but how if one intends to keep AR1 and do the job ........Is it not possible to do without using MD4 then?)
 
Many thanks for the reply.

@ L D[AR2,P#0.0] : "AR1 is set to zero at the start of each scan of OB1 so you cannot use it to retain an address."

That was the "missing link" in my query.
 
Yes, I realise now that I should have stated this in post #2

Note also that AR1 can be used by code generated by Step 7 when referencing structures.
 
Here's an example. I've created a function with an input parameter of type STRUCT. When I access the variables in the STRUCT, AR1 is used "behind the scenes". This is clearly demonstrated as I have loaded AR1 with an arbitrary value and it has been modified from P#9999.0 to V20.0

AR1 is also used when referencing UDT parameters in FC's

sss6.JPG
 
Last edited:
Your analysis of this code is incorrect, the incrementing of the address only occurs if I3.0=1 as the set of M3.0 is dependant on the state of I3.0

MD4 is used to save the incrementing address so I would ditch the use of AR1 viz:

Code:
      A     M      3.0   // If M3.0 = 1  Jump to Z1 
      JC    Z1            // JC execute if RLO = 1 , if FC = 1 check previous other                     wise use previous

      L     P#3.0        // Points to location 3, 4bytes so 3,4,5,& 6 to accu 1
      T     MD     4     // Transfer that pointer to MD4 ?? transfer pointer ?? address or value??
      
      A     I [MD     4]   //since 3.0 is in md4 it checks state of I3.0 correct?
      =     Q [MD     4] //then output state of I3.0
      S     M      3.0     // ???

Z1:   A     M      3.1   //checks state of m3.1?
      FP    M      3.2     // rising edge of 3.2
      =     M      3.3    // outputs m3.3

      A     M      3.3   // checks m 3.3
      JCN   Z2           // if rm3.3 not equal to 1 

      L     MD     4    // load md4 into acc1 is this the address I 3.0?
      +     1             // add1 but what 1? 1 byte 1 bit? 1 word??? 
      T     MD     4   //transfer back to md 4 
      A     I [MD     4]    // check rlo of in md4 which is I 3.0 to those 4 bytes? 
      =     Q [MD     4]   // output the 
Z2:   NOP   0             // No operation

sorry to bring up such an old thread, but lately I have found my lack of knowledge in pointers. I would like to make this part of me stronger so I've been trying to read more about them and get an understanding. do I have this correct???
 

Similar Topics

Howdy folks, I am an Allen Bradley guy currently living in an Emerson world. Working with Rx3i on PacSystems Machine Edition v. 9.6? i think...
Replies
3
Views
634
Hello, I'm very new to programming with absolutely zero schooling in this field and pretty hands off training in my new role, it's been fun...
Replies
4
Views
673
Hello Friends, I am trying to index M Bits, however GX Works2 is not allowing it with following message. https://ibb.co/zPcqj6M...
Replies
3
Views
1,392
Hi All, which the best way to do the indirect addressing in an optimize DB? Ccurrently this is my partial code inside an FB...
Replies
7
Views
2,280
Hey everyone, Just used the PLC5/Logix migration utility to convert a program, and while addressing the PCEs, I noticed a lot of errors for "XIC...
Replies
12
Views
2,011
Back
Top Bottom