341
Special Math Instructions
Section 5-23
Flags
ER:
Indirectly addressed EM/DM word is non-existent.
(Content of
*
EM/
*
DM word is not BCD, or the EM/DM area boundary
has been exceeded.)
R
1
and R
1
+N–1 are not in the same data area.
EQ:
ON when the minimum value is #0000.
5-23-3 AVERAGE VALUE – AVG(––)
Limitations
S must be hexadecimal.
N must be BCD from #0001 to #0064.
D and D+N+1 must be in the same data area.
DM 6144 to DM 6655 cannot be used for S, N, or D to D+N+1.
Description
AVG(––) is used to calculate the average value of S over N cycles.
When the execution condition is OFF, AVG(––) is not executed.
Each time that AVG(––) is executed, the content of S is stored in words D+2 to
D+N+1. On the first execution, AVG(––) writes the content of S to D+2; on the
second execution it writes the content of S to D+3, etc. On the Nth execution,
AVG(––) writes the content of S stored in D+N+1, AVG(––) calculates the
average value of the values stored in D+2 to D+N+1, and writes the average
to D.
The following diagram shows the function of words D to D+N+1.
Precautions
The average value is calculated in binary. Be sure that the content of S is in
binary.
N must be BCD from #0001 to #0064. If the content of N
≥
#0065, AVG(––)
will operate with N=64.
The average value will be rounded off to the nearest integer value. (0.5 is
rounded up to 1.)
Leave the contents of D+1 set to #0000 after the first execution of AVG(––).
Flags
ER:
Indirectly addressed EM/DM word is non-existent.
(Content of
*
EM/
*
DM word is not BCD, or the EM/DM area boundary
has been exceeded.)
S
: Source word
IR, SR, AR, DM, EM, HR, TIM/CNT, LR
N
:
Number of cycles
IR, SR, AR, DM, EM, HR, TIM/CNT, LR, #
Ladder Symbols
Operand Data Areas
D
:
First destination word
IR, SR, AR, DM, EM, HR, LR
AVG(
−−
)
S
N
D
D
Average value (after N or more executions)
D+1
Used by the system.
D+2
Content of S from the 1st execution of AVG(
− −
)
D+3
Content of S from the 2nd execution of AVG(
− −
)
D+N+1
Content of S from the Nth execution of AVG(
− −
)