Indirect Addressing Not Working - Logix 5K

skyfox

Lifetime Supporting Member
Join Date
Nov 2006
Location
CA
Posts
276
Hello All,

Bit puzzled as to why this indirect address is not working.


IDX[10,10] ' Two dimensional array of Constants
DATA[10] ' One Dimensional array

When indirectly addressing DATA[IDX[1,5]]

Logix says invalid array subscript specifier. Value is within DATA[10] array's element count. Anyone knows Why?

If I do a MOVE. IDX[1,5] To X, X gets the correct value from the array. Is it not possible to use a multidimensional array element for indirect addressing?

Thanks.
 
Last edited:
indirect addressing on a multidimensional array is tricky at best
try it first on a single dimensional array then move on after you get it working
 
I am back again
data is a 1 dimensional array and IDX is a 2 dimensional array
you use a 2 dimensional array to address a 1 dimensional array
you can MOVE Data[5] to IDX[1,1] provided they are the same data type
if you want to reference IDX[DATA[2],5] the first dimension of IDX array is referenced by the value in DATA[5] the 2nd dimension of IDX is 5 (a fixed value in this case)
 
Then you can test X and correct its value before using it in DATA[X]. Nothing more painful than an "index out of range" error.

TN731286 Using indirect addressing with a multi-dimensional array (Access Level TechConnect)
\

nhatsen,

Thank for the reply. I do not have a Tech connect account any longer as the company is moving away from Rockwell/AB all together. We had 3 Tool kit licenses for the past 14 years. Toolkit costs have skyrocketed for essentially the same Technology re-branded with fancy names with few bells and whistles added) It is highway robbery. But that is a topic for another time.

Getting back to the problem, X has the correct value. I do not want to use X in DATA[x] because that defeats the purpose and adds an extra step. I will try and explain it a bit better clearer in my next post below in this thread. Thanks again for your help.

Cheers!
 
OK. I may not have explained my problem or what it is that I am after very clearly. I will give it another go.

This is a much simplified example. (Both Data and IDX arrays have several 100 elements)

IDX is a 2 Dimensional Array: Its sole purpose is to provide pointer (position) addresses to place Data in DATA[255] array.

IDX[10,10] ' Read only and contains values that are CONSTANTS.

IDX[1,1] = 1 ' Constant
IDX[1,2] = 2 ' Constant
...
IDX[1,9] = 9 ' Constant

IDX[5,1] = 100 ' Constant
IDX[2,2] = 55 ' Constant
...
IDX[4,9] = 9 ' Constant

ALL ELEMENT VALUES ARE WITHIN 0 to 254 AND ARE WITHIN THE (HI/LOW)LIMIT RANGES OF MY DATA ARRAY.

Data[255] Array ' Single dimension

I want to indirectly Address Data[255] like......

Data[IDX[5,1]] Data[IDX[1,1]] Data[IDX[1,9]]

Which would be the same as saying......

Data[100] Data[1] Data[9]

Basically, IDX[x,y] are place holders to tell the program where to place the data in data array DATA[255].

This is not working. I tried with a single dimensional array for the indirect address as well and that does not work either. But in theory, they both should.

NOTE:

In the real program.....I want to carry out the Indirect addressing by referencing the first dimension value via a tag that has a dynamic value. But that dynamic value is limit checked to ensure it is within the bounds of the IDX array's first dimension.

So for an example....

Without saying

Data[IDX[5,1]] it will be Data[IDX[Z,1]] where Z will contain the element value of the first dimension that is to be referenced.

So in a nutshell.....

Data[IDX[5,1]] ' Does not work ' IDX = Multi-dimensional array
Data[IDX[5]] ' Does not work ' IDX = One-dimensional array
DATA[x] ' X works. X= Tag
DATA[X*A+B] ' Works X, A, & B = Tags (or can be constants)

So, a pointer to an array element, does not seem to work with indirect addressing.

I sort of did a work around by using a base address Tag and then incrementing that Tag value by an offset (Tag) value to route data to desired registers. Ugly way of doing it though. Specially when you want to place lots of data in a table.
 
Last edited:
One more Clarification......

"Both Data and IDX arrays have several 100 elements."


Meant to say over 100 elements in the Real World Application and not in the example.
 
The root problem is that you cannot nest the indirection brackets....

Therefore DATA[IDX[1,5]] is invalid.

try ...

MOV IDX[1,5] temp

Then address ...

DATA[temp]

 
Thanks daba.

I was afraid of that. I was hoping to avoid that extra step. I eliminated IDX[x,y] array altogether and used a Tag (with a dynamic value) and used that along with a hard coded offset value to identify data locations.

X = Dynamic Value (Identifies the starting location for the new data)

Then used Data[X] Data[X+1] Data[X+2] Data[X+3] Etc., to place my data in the array. Then for the next run, X would then become x=[X+4], while making sure X does not exceed the Element count in my data array.

Thanks to everyone for your help!
 

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
578
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
649
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,299
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,252
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
1,903
Back
Top Bottom