Adding Elements of an Array

mjc5728

Member
Join Date
Aug 2023
Location
Pittsburgh
Posts
3
Hello there! I've used the information on this site before, but this is my first time posting.

I'm using CCW for the first time, and was wondering if anyone had an efficient way to add up all of the elements of an array?

I'm using a FFL and FFU to maintain a running count of starts per hour for a compressor system. It is loading and unloading just fine, but I was wondering if there was an instruction/idea similar to the FAL I could utilize to add up all of the elements to get the live running total of starts?

I'm doing it in 1 minute intervals, and I guess I could use an add for all 60 elements, but didn't think that would be the best way to go about it.

Thanks in advance for any advice!
 
Welcome to the forum!

These are integer values, so start with 24 zeros in the array and a running total (UDINT) of 0.

Every time you FFL (load) a new value into the array, add that value to the running total. Or if you load a 0 and increment the latest array element directly, then increment the running total for every element increment.

Either way, very time you FFU (unload) the oldest value from the array, subtract that oldest value from the running total.

That's if you want to get fancy. Otherwise, this is only 24 items, so write a FOR-END_FOR function block in structured text and call it any time you update a value in the array.
 
Does CCW have an AVE (AVErage) instruction? In the Logix 5000 world, you pass in an array and length and it gives you the average. If CCW has something similar, you can AVE and then MUL by the LEN of the AVE.



I like Brian's suggestion of using ADD with FFL and SUB with FFU. I'm a bit paranoid about stuff not happening when I expect it to, though, so I might be more likely to write a loop instead.
 
Joseph, I see what you mean with the possible timing issues. It does have an average instruction available. I have tested drbitboy's method and it seems to be working...but I might as well see if the other way works too while I'm at it!

Thank you both for your responses, and for the warm welcome to the forum.
 
Brian's method is definitely more elegant, especially since you're already handling a FIFO array. Using an AVE instruction would take more memory and more processor cycles (probably...) than his ADD/SUB instructions. I've seen...weird things happen where something always works until one day it just doesn't in a non-replicable way. I tend to try to keep things super simple and often "brute force" things that probably shouldn't be.
 

Similar Topics

I Have an array of DINT and I need to sum the values of the 50 elements I know I must use a FAL and in the expression use the FAL (Control.pos) as...
Replies
1
Views
2,073
Hello all! So I have one project with a S7-1214 and a MTP1500 "Project1" and one project with another S7-1214 "Project2". Both of these PLC:s need...
Replies
1
Views
16
Hi Everyone, Currently we have three plants running with Controllogix PLCs (L72, L73, L74). In each of these plants we have 2 FTView SE...
Replies
0
Views
69
Hello, Im building project with 1756-L82ES controller and 1756-IB16S card but i cant find it when trying to add the card to IO configuration...
Replies
3
Views
144
Hello, I have a pair of redundant 1756-L71 controllers rev 24. These controllers currently have produced and consumed tag interfaces to 3 other...
Replies
2
Views
176
Back
Top Bottom