Shifting an array pointer automatically

procet

Member
Join Date
Dec 2010
Location
New Brunswick
Posts
6
Not sure if this is possible but thought I would put it out there. Using Rockwell Studio 5000, is it possible to shift the address of an array being read by the program automatically if variables in the field change? For example: Product travels down the line and takes 100 seconds to go from point A to point B. A COP instruction shifts the associated DINT value of the product through an array, called Array[200], and at Array[100] the value is then read and used for further calculations in the PLC. Then a process change is made in the middle of the night and the operator changes the time for the product to get from A to B to 85 seconds. Is it possible for the program to change where it reads the array, going from Array[100] to Array[85], without programmer intervention?
 
You can use indirect addressing to access an array like Array_Tag[Index_Tag], and then change what location you look at with other logic. I will also mention to be very careful about keeping the Index_Tag in bounds of your array, otherwise it will throw a major fault.
 
If I'm understand you correctly, then yes you can. It's called an indirect address:

Array[TagName]

You can change the value of TagName to point to different elements of the array. Just be careful not to go outside the bounds of the array or you will fault the processor.
 
Sure, if rather than a constant inside the square brackets you place a variable as the pointer. You must be very careful to limit check the pointer or array index to ensure it does not exceed the limit of the array.
 
tumblr_offfypzQjm1v49cwoo1_500.gif
 
Hey guys, thanks. Learned something new about arrays today and, of course, it was one of those 'well that makes sense' moments.

🍻

You can put more than just an indirect reference tag inside the square brackets, in fact you can put any expression that will resolve to a number...

An example, suppose you wanted to address every third element of an array, you could put....

Array[Array_Index * 3]

For Array_Index going 0,1,2,3 etc., the actual Array element addressed would be 0,3,6,9 etc.

As stated, make sure the numbers you use cannot attempt to address outside of the Array boundaries, or Major Fault will occur. This is why most people will derive the index tag using maths instructions or a CPT, and apply limit checking on it, before attempting the indirection....

MUL Index, 3, Array_Index
LIM 0, Array_Index, xx
MOV Array[Array_Index], Destination

...where xx < Array Size
 
I will just add that while indirect addressing is a very useful and powerful tool, please be sure to leave a decent rung comment behind explaining what you are doing. It will likely save you an angry 3AM call from Bubba if he is not familiar with how indirect addressing works.


Bubba.
 

Similar Topics

Greetings, I am trying shift data in an array (such as Array[0] is shifted into Array[1], Array[1] is shifted into Array[2]......all...
Replies
10
Views
336
Hello Guys, I think I need to use SCL for the following task but am very weak using SCL in tia portal. I have results history data block. It is...
Replies
14
Views
2,951
Hey guys, What do you suggest for doing a shift of dints within an array like this? Thanks, Kevin
Replies
12
Views
2,540
Gents, Trying to shift and average 10 integer array values. First issue is shifting every value in the array forward one spot. 0..8 becomes...
Replies
5
Views
1,891
Hi, I am using RSLogix 5000 V19 and I am trying to figure out how to shift reals in an array. Currently, I setup a flip-flop that increments a...
Replies
19
Views
9,534
Back
Top Bottom