2-389
2 Instruction Descriptions
NJ-series Instructions Reference Manual (W502)
Conversion Instructions
2
MovingAverage
Each time the instruction is executed, the value of In is stored in Buf[CurIndex]. The average of CurIn-
dex + 1 numbers that start from Buf[0] is calculated and stored in Out.
When the number of instruction executions reaches BufSize, the value of Q changes to TRUE.
Each time the instruction is executed, Buf[0] to Buf[BufSize
−
1] are overwritten with the value of In in
cyclic fashion. The average of Buf[0] to Buf[BufSize
−
1] is calculated and stored in Out.
The value of CurIndex returns to 1 after it reaches BufSize and it is then incremented again. The value
of Q remains TRUE.
Inputting Numbers Up to BufSize
Inputting Numbers after Reaching BufSize
CurIndex=def
In=abc
CurIndex=def
In=abc
Second Execution of Instruction
Out=jkl
Q=mno
The value of In is stored in Buf[1].
Average of Buf[0] and Buf[1]
Incremented
Incremented
CurIndex=def
Third Execution of Instruction
Out=jkl
Q=mno
The value of In is stored in Buf[2].
Average of Buf[0] to Buf[2]
CurIndex=def
TRUE because the number of
numbers stored has reached BufSize.
FALSE because the number of numbers
stored has not reached BufSize.
1
2
2345
1234
2345
0
1789
FALSE
2
3456
1234
2345
3456
2345
TRUE
3
Buf[0]=ghi[1]
Buf[1]=ghi[2]
Buf[2]=ghi[3]
Buf[0]=ghi[1]
Buf[1]=ghi[2]
Buf[2]=ghi[3]
CurIndex=def
In=abc
CurIndex=def
In=abc
Fourth Execution of Instruction
Out=jkl
Q=mno
Buf[0] is overwritten with the value of In.
Average of Buf[0] to Buf[2]
Returns to 1.
Incremented
CurIndex=def
Fifth Execution of Instruction
Out=jkl
Q=mno
Buf[1] is overwritten with the value of In.
Average of Buf[0] to Buf[2]
CurIndex=def
TRUE because the number of
numbers stored has reached BufSize.
TRUE because the number of
numbers stored has reached BufSize.
1
4567
4567
2345
3456
3456
TRUE
1
3
5678
4567
5678
3456
4567
TRUE
2
Buf[0]=ghi[1]
Buf[1]=ghi[2]
Buf[2]=ghi[3]
Buf[0]=ghi[1]
Buf[1]=ghi[2]
Buf[2]=ghi[3]