Followers 0

# ControlLogix 1sec,1 min, and 15min average calcs

## 8 posts in this topic

Is there a simple way to perform ControlLogix 1second, 1 minute, and 15minute average calcs, and then reset the average to prepare for the next time period averages? I am reading some analog inputs and a modbus input, and need them to be averaged at the aforementioned intervals, so that drift calculations can be performed. Please assist.

##### Share on other sites
Store your analog values in an array, then use the FAL instruction to calculate the average for 1 second. Store the results in a second array, average those values every 1 minute, store the results in an additional array, average those every 15 minutes.

##### Share on other sites
Can you offer any examples? I'm guessing to have a 60 point array being filled every second and dividing the sum of all 60 values by 60 for the one minute array. Then I suppose to take the one minute calculated averages into a 15 point array and dividing the sum of all 15 values by 15. Example code or picture would be very helpful, as I have never used the arrays.

##### Share on other sites
Wow, Thanks paul! You said a mouthful. My first, or current attempt follows closely with your original proposal, except I used an "ADD + 1" instruction instead of a counter. I'm, also using a 100ms timer to trigger my counts, or summations. My biggest setback, or concern, is when to clear the register to get ready for the subsequent averages on the 1sec, 1min, and 15min totals for which to derive my averages. I will not be able to test the logic until one or two days before the scheduled FAT test; therefore, I was hoping to be certain as to the logic results.

##### Share on other sites
If you keep a running total and a circular FIFO it is not necessary to perform the summing of all 60 samples every time you recalculate the average. Here is a sample of the method I set up for another poster who was using an ML1100 to average 200 samples. This would be even simpler in the CLX, especially in ST.. It implements a circular FIFO using an array and a pointer instead of fifo instructions. Its fast because it doesn't shift any large chunks of data around in memory and each new sample requires only one subtracion, one addition, and a single divison to recalculate the new average. On the CLX use the CPT instruction to avoid the intermediate result storage. http://forums.mrplc.com/index.php?act=Atta...ost&id=5403 (original thread with the solution above http://forums.mrplc.com/index.php?showtopic=12206)

##### Share on other sites
Thanks guys, I have downloaded the file and see if I can replicate it and get it to work. This looks super!!!!!!!!!!!!

##### Share on other sites
Function Block has an Averaging Instruction