380 Rockwell Automation Publication 1756-RM003N-EN-P - October 2011
Chapter 8 Array (File)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
File Average (AVE)
The AVE instruction calculates the average of a set of values.
Operands:
Relay Ladder
Structured Text
Structured text does not have an AVE instruction, but you can achieve the same
results by using a SIZE instruction and a FOR...DO or other loop construct.
SIZE(array,0,length);
sum := 0;
FOR position = 0 TO length-1 DO
sum := sum + array[position];
END_FOR;
destination := sum / length;
See Structured Text Programming
for information on the syntax of constructs
within structured text.
Operand Type Format Description
Array SINT
INT
DINT
REAL
Array tag Find the average of the values in this array
Specify the first element of the group of elements
to average
Do not use CONTROL.POS in the subscript
Dimension to
vary
DINT Immediate
(0, 1, 2)
Which dimension to use
Depending on the number of dimensions, the order
is:
array[dim_0,dim_1,dim_2]
array[dim_0,dim_1]
array[dim_0]
Destination SINT
INT
DINT
REAL
Tag Result of the operation
Control CONTROL Tag Control structure for the operation
Length DINT Immediate Number of elements of the array to average
Position DINT Immediate Current element in the array
Initial value is typically 0