6F3B0253

7. Instructions

FUN 056

MAVE

Moving average

Expression

Input [ A MAVE (n) B C ]Output

Function

When the input is ON, this instruction calculates the average value of the latest n scan’s register A data, and stores it in C. The allowable range of n is 1 to 64.

This instruction is useful for filtering the analog input signal.

The latest n scan’s data of A are stored in n registers starting with B, and C+1 are used as pointer.

Execution condition

Input

 

Operation

Output

OFF

No execution

 

OFF

ON

Execution

 

ON

Operand

 

Name

 

 

Device

 

 

 

 

 

 

 

 

 

Register

 

 

 

 

Constant

Index

 

 

X

Y

R

S

T.

C.

XW

YW

RW

SW

T

C

D

I

J

K

 

 

A

Input data

 

 

 

 

 

 

 

 

 

 

n

Data size

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1 - 64

 

B

Start of table

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

C

Output data

 

 

 

 

 

 

 

 

 

 

 

 

 

Example

The latest 5 scan’s data of XW04 is stored in D0900 to D0904 (5 registers), and the average value of them is calculated and stored in D0010.

D0011 is used as internal work data.

 

XW04

D0010

 

 

 

 

1st scan

1000

200

= (1000) / 5

 

 

2nd scan

1005

401

= (1000 + 1005) / 5

 

 

3rd scan

1009

603

= (1000 + 1005 + 1009) / 5

 

4th scan

1012

805

= (1000 + 1005 + 1009

+ 1012) / 5

5th scan

1007

1006

= (1000

+ 1005 + 1009

+ 1012

+ 1007) / 5

6th scan

1004

1007

= (1005

+ 1009 + 1012

+ 1007

+ 1004) / 5

7th scan

998

1006

= (1009

+ 1012 + 1007

+ 1004

+ 998) / 5

8th scan

994

1003

= (1012

+ 1007 + 1004

+ 998 + 994) / 5

Basic Hardware and Function 159

Page 161
Image 161
Toshiba 6F3B0253 user manual Mave, Moving average