Multi Demensional Array Total

Oakley

Member
Join Date
Oct 2004
Posts
1,082
I have a UDT that is within a 3 dimensional array.
I have a requirement to total one of the fields.

I have tried JMP/LBL with add instruction to totalize - problem is the huge scan time to accomplish.

Anyone know of an elegant efficient way to totalize a 3 dimensional array?
 
Depends on the structure of the array, and it's size.
Indexed addressing, and for/next loops is one way.

Or, use FAL to do partial combines into a target array, then a loop to sum that up.
 
Forgot : Using RSLogix5000 V17 and required to use Ladder code.

I have nested two jumps with an FAL and it seemed to help, but was wondering if there was a better solution.

The array is [5,20,20]
 
Not super elegant (in fact pretty ugly), but you could use CPT instruction and generate expresion in excel. I dont beleive there is a limit to how long an expresion can be.

Alternative: How often do you need this totalised and how often does the data change? If not required rapidly, do your array indexing once per scan. No for/next loops required and no slowing down of scan time. 2000 elements = 2000 scans = not very long in the real world.
 
Kiwi is on the right track. Of course without seeing the code, I have no idea if it is reasonable for your situation. The key here is you pay a significant penalty for using multiple array indices with variables. i.e. Foobar[a,b,c] The same instruction with the indices as constants (Foobar[1,2,3]) does not pay the penalty (the compiler resolves the address). Check out the instruction execution times in the manual, it covers added time for this.

The point is, if you express everything with constants or even get it down to one variable, it executes much faster. It may take a lot of rungs and look kinda ugly though.

Using one array index with a variable is a pretty good deal. It's the second one that starts to bite into performance. I know you are probably stuck with your UDT, but keep it in mind for the next time. Designing data structures well is one of the things that distinguishes really good code from average code.
 
My UDT has been directed to me. Not too bad - only 3 words.

Now I have a 3-dimensional array of 5 x 20 x 20 of these 3 words.

So, I need 2000 calculations summing the 3rd word of the UDT.

I really only need the total about every 10 seconds - much less than the other control sequences that need to be executed every second or better.

The idea of one calculation per scan may be of some merit.
 
Hey, do you actually need to sum them FROM the UDT?
I do long run averaging here, by loading up FIFO's with values, and then adding them to a totalizer (just a real register) as the pop off of the FIFO stack until it's empty.

Could you just sum the elements AS you add/update them in the UDT?
 
Values are populated in the UDT values from IO and an AOI.
I just need to totalize an attribute of the UDT.

No elegant efficient programming to interrogate a 3 dimensional array.

Too bad the FAL can't be nested.
 
THis is another example of not definiing the problem.

The obvious solution is to use three nest loops.

Why not always keep a running sum that always gets modified as each field that is part of the sum is modified?

If the Array cell is being assigned values then

OldValue=Array[i,j,k];
Arrayr[i,j,k]:=NewValue;
Sum = Sum + NewValue - OldValue;

if the cells are only going to be incremented then

Array[i,j,k]:=Array[i,j,k]+1;
Sum = Sum + 1;
 
I first implemented the obvious solution - huge impact on the scan time. It was unacceptable for the control portion of the code.

I then had 2 nested loops with an FAL - that was significatly better, but still I felt that this could be better implemented seeking efficiency.

I thought of the tracking as the value is updated - lot's of code. Not a big fan of having so much repeated code.

This afternoon I will tinker around with the once per scan idea. Like I stated in a previous post - this value is not critical that it has the total every scan. The values don't change that often, and it is not used in control.
 
Without playing around with it, is there any chance you can 'Cheat' ?

That is, using the AVE instruction to do the summing for a 'column' at a time, multiply back by the number of elements in the column (to get column sum)...

It seems rather odd that there isn't just a plain old sum command.
 
Findings:
3 For/Next loops nested - 141250 us.
2 For/Next loops nested with 1 FAL - 20000 us.
2 Counters nested with 1 FAL - 1188 us.

Thanks to all for the ideas.
 
One more thought on this...

When you first go to run mode, go ahead and do the whole calculation, whichever method is suitable (all in one scan, or broken up).

Once the total is calculated, each time a change is made, subtract the old value from your total, and add the new value. This might bite you if you try to go online and manually make chages to values, but if all of the editing is done programmatically, it might be a viable option.

Paul
 

Similar Topics

Hello, I had a question about benchmarking the Rockwell FactoryTalk View SE software. I've installed in the neighborhood of 30 different...
Replies
2
Views
279
Hello, I'm trying to test Acopos multi using Automation Studio. Ready LED is green blinking, how can i know what error of Acopos on Automation...
Replies
1
Views
131
Good Afternoon , I'm sure there are many Ishida Muti-Head Weigh Systems . We have a Ishida CCW-M-214W Multi-Head system . We are...
Replies
1
Views
533
Hi Guys, I'm trying to integrate Pilz Ethernet IP Module to ControlLogix. I added Pilz module as a Generic Ethernet module and I'm able to...
Replies
2
Views
510
Good Morning , We have a Ishida Multi-Head Scale . I had experiece with them for chips , crackers , etc. , but now we are using them for...
Replies
7
Views
460
Back
Top Bottom