VC21LPFilter
V = Variables
C = Claculation functions
The VC21LPFilter function implements a low-pass digital filter of the first order for values in the range from -999999 to +999999. It ' also provided the pre-charge filter option.
IMPLEMENTATION
VC20LPFilter (Mode, Tsample, Tau, FilterIn, FilterOut)
Parameters:
IN/OUT | VARIABLE TYPE | EXAMPLE NAME | DIM | |
---|---|---|---|---|
IN | CONST / GLOBAL | Mode | F | Mode of operation (0=pre-charge, 1=filter execution). |
IN | CONST / SYSTEM | Tsample | W | Sample time filter (msec) [0÷32767]. |
IN | CONST / SYSTEM | Tau | W | The filter time constant (ms) [0÷32767] |
IN | GLOBAL | FilterIn | L | Value of the variable that you want to filter [-999999÷999999] |
OUT | GLOBAL | FilterOut | L | Value of the filtered variable [-999999÷999999] |
Description
The VC21LPFilter function implements a digital low-pass filter of the first order whose time constant (Tau) is defined in the parameters passed to the function. Assuming you start from a zero input variable value, the output of the filter takes a value equal to 63% of the input after the long Tau. Similarly the cutoff frequency of the filter is . If the Mode topic is zero allows you to preload the filter to a value that can be set with the topic FilterIn.
Example
;--------------------------------------------- ; Project : REG_012 ; Module Name : ReadTemp ; Author : ; Description : Read temperature & filter ;--------------------------------------------- MAIN: CALL ReadTemp swTsample = 100 ;100 ms time sampling filter swTau = 5000 ;5 sec filter time constant gfMode = 1 ;normal execution VC21LPFilter (gfMode,swTsample, swTau, gwFilterIn, gwFilterOut) WAIT 1 JUMP MAIN
Note
-
The function contains an internal timer to actually execute the filter each sample time(Tsample). The function should be executed at a frequency higher than the sample time (Tsample). Typically each cycle task.