Omron CP1E-E@@D@-@ Computer Hardware User Manual


 
2 Instructions
2-288
CP1E CPU Unit Instructions Reference Manual(W483)
Function
Precautions
The processing information (R+1) is cleared to 0000 each time the execution condition changes from
OFF to ON.
But the processing information (R+1) will not be cleared to 0000 the first time the program is executed
at the start of operation. If AVG(195) is to be executed in the first program scan, clear the First Work
Area Word from the program.
Sample program
When CIO 0.00 is ON in the following example, the contents of D100 will be stored one time each scan
for the number of scans specified in D200. The contents will be stored in order in the ten words from
D302 to D311. The average of the contents of these ten words will be placed in D300 and then bit 15 of
D301 will be turned ON.
For the first N–1 cycles when the execution
condition is ON, AVG(195) writes the values of
S in order to words starting with R+2. The Pre-
vious Value Pointer (bits 00 to 07 of R+1) is
incremented each time a value is written. Until
the Nth value is written, the contents of S will
be output unchanged to R and the Average
Value Flag (bit 15 of R+1) will remain OFF.
When the Nth value is written to R+N+1, the
average of all the values that have been stored
will be computed, the average will be output to
R as an unsigned binary value, and the Aver-
age Value Flag (bit 15 of R+1) will be turned
ON. For all further cycles, the value in R will be
updated for the most current N values of S.
The maximum value of N is 64. If a value
greater than 64 is specified, operation will use
a value of 64.
The Previous Value Pointer will be reset to 0
after N–1 values have been written.
The average value output to R will be rounded
to the nearest integer.
R+N+1
R
R+1
R+2
R+3
S Cycle 1
S Cycle 2
S Cycle N
Average
N values
Average Valid Flag
S: Source word
N: Number of cycles
Pointer
AVG
D100
D200
D300
0.00
S
N
R
N:D200 (10 times)
S:D100
R:D300
R+1:D301
R+2:D302
R+3:D303
R+11:D311
Average
Average Valid Flag
15 780
Pointer
000A
S, scan 1
S, scan 2
S, scan n