I’ve needed a time-average function several times, so I figure other people have also. Here is a handy AOI which makes it easy to use in a ControlLogix ladder program. (AB has the Moving Average MAVE instruction in function block and structured text environments but not ladder) I use this instruction when I’m trying to control something from a signal that jumps around too much. The instruction takes samples from the input at the interval you set it to, and outputs the average of all the samples. I’ve included the import file and screenshots of the ladder code.
AOI: TimeAve.L5X.zip
Here is a sample of how the TimeAve instruction is used. As shown it will give the average of 8 samples taken at 100ms intervals:
The standard deviation output is a good indicator how ‘jumpy’ your input is. I’ve used it to wait for a valid number from a scale.
I was looking for a MAVE equivalent and landed on this blog. Thanks for sharing that AOI. It saved me a lot of time.
One change I had to make though. The Input variable is a DINT type while the SampleArray[] is a REAL type. I needed the precision of a REAL type for my Average so I ended up having to change the Input variable to a REAL type.