You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old March 15th, 2018, 06:33 PM   #1
procet
Member
Canada

procet is offline
 
Join Date: Dec 2010
Location: New Brunswick
Posts: 6
Shifting an array pointer automatically

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?
  Reply With Quote
Old March 15th, 2018, 06:42 PM   #2
Gomez_
Lifetime Supporting Member
United States

Gomez_ is offline
 
Join Date: Sep 2014
Location: California
Posts: 157
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.
  Reply With Quote
Old March 15th, 2018, 06:42 PM   #3
dmroeder
Lifetime Supporting Member
United States

dmroeder is offline
 
dmroeder's Avatar
 
Join Date: Apr 2006
Location: Vancouver, WA
Posts: 1,992
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.
  Reply With Quote
Old March 15th, 2018, 06:44 PM   #4
OkiePC
Lifetime Supporting Member
United States

OkiePC is offline
 
OkiePC's Avatar
 
Join Date: Mar 2005
Location: ENE of Nowhere Oklahoma
Posts: 9,615
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.
__________________
It's not all the variables I am most concerned with, it's the undiscovered constants.
  Reply With Quote
Old March 15th, 2018, 07:08 PM   #5
ASF
Lifetime Supporting Member
Australia

ASF is offline
 
Join Date: Jun 2012
Location: Australia
Posts: 2,491
  Reply With Quote
Old March 16th, 2018, 09:36 AM   #6
procet
Member
Canada

procet is offline
 
Join Date: Dec 2010
Location: New Brunswick
Posts: 6
Hey guys, thanks. Learned something new about arrays today and, of course, it was one of those 'well that makes sense' moments.

  Reply With Quote
Old March 16th, 2018, 10:29 AM   #7
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,258
Quote:
Originally Posted by procet View Post
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
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem


  Reply With Quote
Old March 16th, 2018, 09:24 PM   #8
willxfmr
Lifetime Supporting Member
United States

willxfmr is offline
 
Join Date: Nov 2013
Location: Wisconsin
Posts: 282
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.
__________________
“Now will come the nay-sayers with all the reasons why you shouldn't do this. Some of them are teachers, and some of us are doers. Besides, you have got to let the smoke out of this equipment every now and then, or it starts to clog up the chimney.”
~Lancie1
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Pointer to Array inside structure zigsmund LIVE PLC Questions And Answers 1 January 30th, 2017 11:55 AM
Variable array size call to add-on instruction - A solution Mr Modbus LIVE PLC Questions And Answers 4 July 17th, 2015 07:59 AM
S7: Add offset to Any Pointer for BLKMOV Mark Whitt LIVE PLC Questions And Answers 3 June 5th, 2015 02:53 PM
Array Shifting klawson2012 LIVE PLC Questions And Answers 19 December 11th, 2013 06:23 AM
Building an S7 Array Move Questions DesertDog LIVE PLC Questions And Answers 19 June 17th, 2004 09:51 AM


All times are GMT -5. The time now is 02:04 AM.


.