Parse Data from UDT

ggrice_71

Member
Join Date
Jun 2010
Location
South Georgia
Posts
7
Using Logix Designer, I have a UDT with multiple members

Time_Stamp..REAL
Min........ REAL
Max........ REAL
Avg........ REAL


I have created an array with a length of 20 so I have Table[0].Time_Stamp
Table[0].Min
Table[0].Max
Table[0].Avg

I need to get the average of all the Table[x].Min values from Table[0-19]. Is there a way to move all of the Table[x].Min out of the array into a contiguous array so I can use the AVE instruction, or is there a better way?

Thanks
 
Plenty of options.

1 - Subroutine, with a For loop
2 - Create an AOI
3 - JMP/LBL
4 - Indirect addressing
5 - brute force
 
Paully's5.0:

Is there really "indirect addressing" in PLCs, or is it really just "indexed" addressing? And what is the "brute force" solution?

ggrice_71:

You've done the right thing making your UDT to organize the data. I wouldn't write it to yet another data area. Just use the data where it is. Keep it in one spot - using a simple loop.

Also - do you really need "Avg" replicated 20 times in that UDT Array? Sounds like you just need AvgMin and AvgMax
 
Paully's5.0:

Is there really "indirect addressing" in PLCs, or is it really just "indexed" addressing? And what is the "brute force" solution?

Carry-over terminology from the world of PLC5/SLC/Micro where you have actual memory addresses, and the address reference changes - N[N:7]. But yes you are just indexing through the array.

Brute force, rather than a loop you would write individual rungs of logic to move the data where you want it to be. Some will argue this method will be faster than a loop, how often speed actually matters... Others will argue it's better for 'bubba'.

I should note, my examples 3 and 4 would be used together.
 
Paully's5.0:

Is there really "indirect addressing" in PLCs, or is it really just "indexed" addressing?

No it is not "indexed" addressing, it truly is "indirect"...

What you put inside the square brackets does not have to be an index tag, nor does it have to be a single tag, it can be a math expression. So long as the expression can be reduced to a single value at runtime, it will be valid.
 
According to Studio 5000 help...

Index Through Arrays
To dynamically change the array element that your logic references, use tag or expression as the subscript to point to the element. This is similar to indirect addressing in PLC-5 logic.

But does it really make much difference for the question asked?
 
Using Logix Designer, I have a UDT with multiple members

Time_Stamp..REAL
Min........ REAL
Max........ REAL
Avg........ REAL


I have created an array with a length of 20 so I have Table[0].Time_Stamp
Table[0].Min
Table[0].Max
Table[0].Avg

I need to get the average of all the Table[x].Min values from Table[0-19]. Is there a way to move all of the Table[x].Min out of the array into a contiguous array so I can use the AVE instruction, or is there a better way?

Thanks

Sure there is....

Just replace MyData with Table, and remove Trigger bits if you want it to execute every scan...

2017-08-11_114635.jpg
 
Last edited:
No it is not "indexed" addressing, it truly is "indirect"...

What you put inside the square brackets does not have to be an index tag, nor does it have to be a single tag, it can be a math expression. So long as the expression can be reduced to a single value at runtime, it will be valid.

daba:

"Indirect", as I've always known it from 'conventional' programming, involves pointers. So you'd define your pointer variable, load it with the *address* of something, then grab the value at the location referenced by the pointer.

Can you do pointers with ControlLogix PLCs (ie: assign the *address* of a tag to a variable)?
 
daba:

"Indirect", as I've always known it from 'conventional' programming, involves pointers. So you'd define your pointer variable, load it with the *address* of something, then grab the value at the location referenced by the pointer.

Can you do pointers with ControlLogix PLCs (ie: assign the *address* of a tag to a variable)?

Probably best to forget about "convention", not everyone abides by them.

To fully appreciate what addressing mode Logix5000 processors use, if we take a step back to earlier processors, such as PLC5 and SLC series, they actually had both modes, Indexed and Indirect.

Those legacy controllers use "data-tables" for data storage, not a tag database like Logix5000.

Addressing a location in those data-tables took the form "N23:45", which is iNteger 45 (the 46th integer), in iNteger table number 23.

We could replace either the table number or the element number with another data-table location enclosed in square brackets. For example...

N23;[N7:10], use the value in N7:10 as the element number in the N23 data table.

or...

N[N7:5]:0, use the value in N7:5 as the data-table number to look at the first element of it.

It was even possible to indirectly address both table number and element number.... N[N7:5]:[N7:10]

Those earlier controllers also had an "Index Register", stored in the Status data-table, that could also be employed manually, although the controller used it heavily in the execution of instructions that worked its way through data-tables, such as FAL, FSC, DDT, etc.

I've not seen it used often, but it was possible to pre-load the Index Register with a number, then use that as the Index into another data-table, eg....

#N23:30

The # indicated an "Indexed Address", the "effective address" being calculated at run-time as the starting address, plus the value of the index register. In the example above if the index register contained the value 135, the effective address would be N23:{30 + 135} = N23:165. It is even possible to combine both methods, eg....

#N23:[N7:6]

... but now it gets really confusing !!

Now Logix5000 controllers don't have data-tables, you only have arrays to store contiguous data. Addressing an element of the array can be evaluated at run-time, by placing an "expression" inside square brackets, eg....

NyArray[50]
MyArray[ArrayPointer]
MyArray[ArrayPointer + 23]

..are all valid.

This is similar to the legacy PLCs Indirect addressing mode, (although they didn't allow expressions, only other addresses). To simulate the indirect use of both "table" and "element", you can create two-dimensional arrays, eg....

MyArray[Table, Element]

I believe Indirect better describes this method of addressing file locations, irrespective of any "conventions".
 
daba:

Ok, but all of that is still only "indexed" addressing, even if they refer to it as "indirect". So we'll call it *their* version of "indirect" addressing, I guess.

But if I wanted to use pointers in a PLC application, could I use CoDeSys to generate my executables for Rockwell PLCs?
 
daba:

Ok, but all of that is still only "indexed" addressing, even if they refer to it as "indirect". So we'll call it *their* version of "indirect" addressing, I guess.

I disagree, and that may only be because I'm so used to it.

"Indexed" generally involves a special register (the index register), and that's the general meaning (google it). Indexed addressing generally does not need to specify the tag or register used for creating the effective address, as it is usually implied as the special "Index Register". In Logix5000 there's no "index register" and you can put anything you like inside the square brackets. At execution time the array element is indirectly addressed, because the expression is evaluated, rather than just using an "index".

Try using "indexed" addressing to work with every 5th element of an array, for example. That's easy in Logix5000, because you can do the math in the brackets.

But if I wanted to use pointers in a PLC application, could I use CoDeSys to generate my executables for Rockwell PLCs?

You can use whatever you like, slap a value into a "pointer" tag, and use that tag to indirectly address an element of an array.

The very fact that you used the word "pointer", infers that you want to address the final destination "indirectly" rather than directly.
 
Final thoughts....

It doesn't matter what method is used, "indexed" or "indirect", the final outcome is always going to be "indirect", what makes the difference is how that indirection is served up.
 
I'd forgotten this thread, but to put things into some sort of perspective, and I've already alluded to the terminology...

Any form of memory addressing that is not explicitly quoted, must, by definition, be "indirect".

There are many ways that the "indirection" can be performed, and some of those ways may involve using the value in an "index register" to evaluate the "effective address". In those cases I will allow you to call it "indexed addressing". In some cases the index register is automatically updated by the operating system as the instructions are executed.

Logix5000 systems do not have an "index register" that can be manipulated either before, or during, instruction execution, so these platforms cannot have "indexed addressing". Any form of "indexed" comes from using the file instruction's {Control}.POS value in the expression that forms the effective address.

In summary, I would say that Logix5000 systems only have "indirect" addressing, at the user instruction level.

My very first introduction to microprocessors was machine-level (assembly language) coding with the Motorola 6502 - it had a plethora of addressing modes, but at the end of the day, the ones that weren't "direct", had to be "indirect", in different ways......


OOPs... not "final thoughts" at all, lol
 
Last edited:

Similar Topics

Hi All, It's a long shot, but is there a way that a routine or AOI is written to scan all routines (routine names can be fed as inputs? if...
Replies
4
Views
575
Is there a way to export/import parse-able files of the PLC program of a Mitsubishi Electric (MELCO) iQ-R PLC? I am working with iQ-R PLC...
Replies
5
Views
1,732
Basic info: Wonderware System Platform 2014 Archestra Workflow External system, Alarm generated Text file With fixed delimiter I need some advice...
Replies
0
Views
3,023
hello all: I use a opc client to read data from AB controllogix through 1756-enbt.when i read a variable with the tag name 'a',the packet is...
Replies
0
Views
2,814
I am tracking production and accumulating it into a floating point number. In order to display that on an AB InView Message Display I have to...
Replies
15
Views
6,668
Back
Top Bottom