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 August 8th, 2017, 07:29 AM   #1
ggrice_71
Member
United States

ggrice_71 is offline
 
Join Date: Jun 2010
Location: South Georgia
Posts: 6
Parse Data from UDT

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
  Reply With Quote
Old August 8th, 2017, 10:46 AM   #2
Paully's5.0
Lifetime Supporting Member
United States

Paully's5.0 is offline
 
Join Date: Jan 2006
Location: WI
Posts: 1,892
Plenty of options.

1 - Subroutine, with a For loop
2 - Create an AOI
3 - JMP/LBL
4 - Indirect addressing
5 - brute force
__________________
"Comments should be like a mini-skirt... long enough to cover the essentials but short enough to keep your interest." - Uptown47
  Reply With Quote
Old August 8th, 2017, 04:41 PM   #3
SoftwareJanitor
Member
United States

SoftwareJanitor is offline
 
Join Date: Dec 2016
Location: Southeast
Posts: 116
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
  Reply With Quote
Old August 8th, 2017, 05:00 PM   #4
Paully's5.0
Lifetime Supporting Member
United States

Paully's5.0 is offline
 
Join Date: Jan 2006
Location: WI
Posts: 1,892
Quote:
Originally Posted by SoftwareJanitor View Post
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.
__________________
"Comments should be like a mini-skirt... long enough to cover the essentials but short enough to keep your interest." - Uptown47
  Reply With Quote
Old August 8th, 2017, 07:27 PM   #5
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 3,894
Quote:
Originally Posted by SoftwareJanitor View Post
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.
__________________
___________________________
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 August 8th, 2017, 07:48 PM   #6
Paully's5.0
Lifetime Supporting Member
United States

Paully's5.0 is offline
 
Join Date: Jan 2006
Location: WI
Posts: 1,892
According to Studio 5000 help...

Quote:
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?
__________________
"Comments should be like a mini-skirt... long enough to cover the essentials but short enough to keep your interest." - Uptown47
  Reply With Quote
Old August 11th, 2017, 05:47 AM   #7
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 3,894
Quote:
Originally Posted by ggrice_71 View Post
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...
Attached Images
File Type: jpg 2017-08-11_114635.jpg (17.9 KB, 63 views)
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem



Last edited by daba; August 11th, 2017 at 05:53 AM.
  Reply With Quote
Old August 11th, 2017, 12:26 PM   #8
SoftwareJanitor
Member
United States

SoftwareJanitor is offline
 
Join Date: Dec 2016
Location: Southeast
Posts: 116
Quote:
Originally Posted by daba View Post
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)?
  Reply With Quote
Old August 12th, 2017, 03:22 AM   #9
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 3,894
Quote:
Originally Posted by SoftwareJanitor View Post
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".
__________________
___________________________
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 August 14th, 2017, 01:44 PM   #10
SoftwareJanitor
Member
United States

SoftwareJanitor is offline
 
Join Date: Dec 2016
Location: Southeast
Posts: 116
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?
  Reply With Quote
Old August 15th, 2017, 05:52 PM   #11
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 3,894
Quote:
Originally Posted by SoftwareJanitor View Post
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.

Quote:
Originally Posted by SoftwareJanitor View Post
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.
__________________
___________________________
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 August 15th, 2017, 06:57 PM   #12
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 3,894
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.
__________________
___________________________
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
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
Loading .Pre in an array of timers? dginbuffalo LIVE PLC Questions And Answers 24 March 11th, 2016 06:44 PM
read special variables (pressure, temperature, ...) from tcp raw data stream hassanayoub85 LIVE PLC Questions And Answers 0 July 23rd, 2013 09:24 AM
Alphabetize UDT by one of the Data Types javaninger LIVE PLC Questions And Answers 7 February 17th, 2012 12:10 PM
Help me CIP read data fail from control LGX (1756-enbt)) chenhg LIVE PLC Questions And Answers 1 September 27th, 2008 05:31 AM
Confused "again" S7 indirect Thim LIVE PLC Questions And Answers 17 July 22nd, 2008 04:47 PM


All times are GMT -5. The time now is 11:48 AM.


.