File Average (AVE)
The AVE instruction calculates the mean of a set of values.
IMPORTANT:
Make sure the Length does not cause the instruction to exceed the specified Dimension to vary. If this happens, the destination will be incorrect. For more information, see Viewing an Array as a Block of Memory.
If an overflow occurs during expression evaluation, the instructions reads past the end of an array, the instruction sets the ER bit and stops execution
Available Languages
Ladder Diagram
Operands
There are data conversion rules for mixed data types within an instruction. See Data Conversion.
Ladder Diagram
Operand | Type | Format | Description |
---|---|---|---|
Array Tag | SINT INT DINT REAL | 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
the order of the dimensions is: array[0,1,2] |
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 | Offset into the specified array which identifies the current element that the instruction is accessing.
initial value is typically 0 |
Affects Math Status Flags
See Math status flags.
Major/Minor Faults
None specific to this instruction. See Common Attributes for operand related faults.
Execution
Ladder Diagram
Condition/State | Action Taken |
---|---|
Prescan | The .EN bit is cleared. The .DN bit is cleared. If .ER bit is zero during prescan, all the control bits (.DN, .EN, .EU, .EM, .UL, .IN and .FD) will be cleared to zero. |
Rung-condition-in is false. | See AVE Flow Chart (False) |
Rung-condition-in is true. | The AVE instruction calculates the average by adding all the specified elements in the array and dividing by the number of elements. |
Postscan | N/A. |
AVE Flow Chart (False)
Example 1
Ladder Diagram
Example 2
Ladder Diagram
Provide Feedback