我觉得对有干扰的场合还是蛮有用的。
Network 1 // Divide the calculation result (VD0) by 99, store it in AC0 .
// This routine produces a rolling average of the last 100 scans worth of an analog input.
//
// VD0 holds the average of the last 100 scans of the analog input AIW0. VD0 is multiplied by 99 in preparation
// to be added to the new analog value.
//
//
LD SM0.0
MOVR 0.0, AC0
MOVR VD0, AC0
*R 99.0, AC0
Network 2 // Convert the raw analog value (AIW0) to a real number, add it to the calculation result (AC0), divide by 100, move to VD0.
// The analog input AIW0 is converted to a real number, added to the calculation result in the rung above,
// divided by 100 and moved to VD0.
//
LD SM0.0
MOVD +0, AC1
MOVW AIW0, AC1
DTR AC1, AC1
+R AC0, AC1
/R 100.0, AC1
MOVR AC1, VD0
Network 3 // Truncate the calculation result, move it to VD4, move the higher order word (VW6) to VW8.
// The result VD0 which is a 32 bit real number is truncated to extract the 16 bit integer value
// which is held in VW6 and is moved to VW8. Use VW8 in any other part of your program as the
// analog average.
//
// the response time of the value is dependant upon the scan time.
//
LD SM0.0
TRUNC VD0, VD4
MOVW VW6, VW8
Network 4
// MEND
//
点击此处查看附件