s7-400 indirect addressing

devittjl

Member
Join Date
Mar 2004
Location
Puget sound area, WA
Posts
4
Here is a sample of what I have...

A "LOGATLC1"
= L 0.0
A L 0.0
JNB _002
L "Nich".LC1_SCALED
T "Data".Shift[83]
_002: NOP 0
A L 0.0
BLD 102
S DB1.DBX 166.7

I would like to make the [83] in "Data".Shift[83] a variable based on a calculation. The variable will be an INT.

I also need the 166.7 in DB1.DBX 166.7 to update as well.

Can anyone help?
Thanks,
John
 
Unfortunately, S7 will not let you indirectly address the array instance by inserting a variable in the brackets. But, there are other ways to do it:

First, you will have to calculate a pointer to the array you want to use. To do this, you would need to know the length of the array plus the starting address of the first array. For our example, I'll assume that each array is two bytes, the first array is "Data".Shift[1], and is located at byte 100 of the data block. And, the array instance that you want to point to is stored in an integer (we'll call it ShiftInstance for now).

So, you could create a pointer to array[83] like this:

L P#100.0 //Loads a pointer to byte 100
LAR2 //Set AR2 to byte 100
L #ShiftInstance //Load the array you want to use.
+ -1 //Decrement the Shift Instance by one.
ITD //Convert it to a DINT
L L#2 //Load the array length (two bytes in this case)
*D //Multiply
SLD 3 //Shift the value three bits to find bit pointer
+AR2 //Add our array offset to the original pointer.

Now, you can point to your array directly by using AR2:

L "Nich".LC1_SCALED
T DIW[AR2,P#0.0]

You will have to open the other data block ("Data") as an instance data block first since you need to have two blocks open at once.

Take a look at this, and get back to use with more questions. There are other ways to do it, but this method works for any number and size of arrays.


As for making DB1.DBX 166.7, update, what do you mean? Do you want to indirectly address it also? Or do you mean that the data block may change, but the 166.7 is always the same?
 

Similar Topics

I am confused. I am using indirect addressing to copy from one point to another based on an integer file but I got one Copy instruction that...
Replies
4
Views
2,201
Hi, Am I right in saying that indirect addressing cant not be accessed at file level in these PLCs? i.e N[x]:1 where x is pointer to address...
Replies
3
Views
5,291
wildcatherder arrived at a satisfactory resolution to his question in this thread. I'm just not sure how since nothing was ever really resolved...
Replies
1
Views
2,294
Greetings, I had an issue with a RIO rack 2 and IFM I/O Link dropping on my network. I would loose connection for a second or 2 then they would...
Replies
3
Views
85
I HAVE B&R POWEL PANEL 400 HMI. THE ISSUE IS HMI NOT BOOTING, DISPLY SHOWING CONTIUESLY (ATTEMPTING TO A BOOT HARD DRIVE....)
Replies
1
Views
61
Back
Top Bottom