Does anybody know of a manual or website that breaks down Indirect addressing. I have seen it used and find it hard to follow without any knowledge of it. Thanks for any info.
I will break it down for you - in simple terms, hopefully this will help you get to grips with Indirect Addressing.
Best to use an example, it always helps.
Suppose I need to know in my code whether a month has 28, 30, or 31 days (let's ignore leap-years to keep it simple). I might be using it for production rates per day (just an example !).
I could set up an array
Days[12] (a tag called Days that is an array of 12 elements, numbered ("indexed") as elements 0-11).
I could store the values for the number of days in each element of the array, where each element corresponds to a month of the year...
Days[0] = 31 ..January
Days[1] = 28 ..February
Days[2] = 31 ..March
Days[3] = 30 ..April
.....and so on to.....
Days[11] = 31 ..December
Before looking at Indirect Addressing, let's flip the coin and look at Direct Addressing. Suppose I want to know how many days are in month 7 (July). I could fetch the data from the array by addressing
Days[6]. I would have to have 12 unique "reads" of the array to fetch all 12 months data. "If Month=4 get Days[3]" etc.
Indirect addressing is a method of using an "indirect" value to specify which location of the data array you want to address. In this case we might have a tag that contains the month we are interested in, let's call it
Month. So we could subtract 1 from month, and store the result in another tag called
ArrayPointer. Then we could get the data for
any month, 1-12, by addressing into the array using the ArrayPointer tag : Days[ArrayPointer].
Logix5000 simply sees a tagname in the square brackets, and evaluates it, which for this simple arrangement just means fetching the value of the tag called ArrayPointer, and using that value as the element number of the Days array.
But this all looks a bit clumsy, month 1 needs to address the array at element 0, etc., so we can do a couple of things to make it easier.
Firstly, we could have created our array
13 elements long (indexes 0-12), and simply ignored element 0, so month 1 data is stored in
Days[1], month 9 in
Days[9], etc. Our Indirect Addressing example now doesn't need to subtract 1, so we can address each month's data more easily as
Days[Month]. Logix sees the tagname
Month in the brackets, fetches the value of
Month, and uses the value as the array element number to read or write.
Alternatively, we could have kept the original 12-element array, and performed the subtraction of 1
at the same time as the Indirection. This is where Logix is good, because it allows us to put
expressions in our indirects. So we could get the number of days for
Month by using the address
Days[Month-1]
. And so it goes on...
The expressions can be as complex as you like, the only critical thing is that it has to evaluate to a legal array element number : 0 to (arraylength-1). The only other thing to remember is we can't use "double-indirect" addressing,
Days[Period[6]] is not allowed.
So, whenever you see Indirect Addressing used in a program, it is nearly always a means to save program code, all you have to do is perform the same maths as the processor will do to the index expression inside the square brackets.
A long post to explain what is, actually, a very simple concept. Any questions, just ask.
P.S. I do hope you didn't mean
Indexed addressing and Logix5 or Logix500 .....