Avg of a array

Node1

Member
Join Date
Jul 2017
Location
USA
Posts
20
I am trying to find the average of a array[31]. I am using the AVE instruction. My destination value is 1.$. Is that because there are 0 or null values? How do you seperate out the 0 or null values before using the AVE instruction?

Controller 1769-L33ERM
Revision 24.11
 
1.$ or 1.QNAN means you have and undefined number, which would be from a Null. 0's would not cause this unless in the divisor.

How is the array created you could always prefill it with zeros
 
roll your own.
an average is just the total divided by the number of samples.
the toughest part is knowing when to reset the average w/ new samples.
 
No need for a pre-fill. When arrays are created, they will be filled with zero value. "Null" values isn't a concept that the O/S supports or recognises. Something must have corrupted one or more values since it was created.

The only way to corrupt a REAL array is to FLL, COP or CPS something that isn't a properly-encoded REAL into it. This is because those instructions take no notice of data-type, and are just fast "byte-for-byte" copiers.

EDIT : Actually 1.$ is "infinity", usually preceded by + or -, and the only way I can figure how you might get that as a result is if you have the LENgth specified as longer than the array, and the instruction is picking up stuff from memory outside of the array tag
 
Last edited:

Similar Topics

Gents, Trying to shift and average 10 integer array values. First issue is shifting every value in the array forward one spot. 0..8 becomes...
Replies
5
Views
1,890
Our lift station pumps cycle on/off about 8x/hr sending waste flow offsite. We measure the flow during pump cycles. I will add a totalizer but...
Replies
19
Views
3,431
How would one come up with an average flow from the live GPM from the flow meter? I have the SCP set up and can watch the live GPM but I have...
Replies
15
Views
4,188
I am trying to get a rolling 3 hr avg of the tank weight loss of all 3 tanks. 3 tanks on 3 different scales with a 4 to 20mA signal to a...
Replies
19
Views
3,236
Is there a function block in RSLogix for calculating Min/Max/Avg of a group of analog inputs? I have 12 thermocouple inputs that need this...
Replies
3
Views
8,959
Back
Top Bottom