Debounce data by filtering bits over a specified time
This FP instruction executes filter processing for specified bits to ensure that their signal is stable for a specified time. The instruction can be useful to negate the effects of bounce, e.g. for a switching device.
Input
Input data whose bits will be filtered according to the input mask
Input mask which specifies which bits will be filtered
Specifies the time in ms during which the signal at the specified bits has to be stable
Output
Filtered data
1 (16#0001) is assigned to s2_InputMask is , i.e. bit 0 will be filtered, the other bits will not be filtered, and the value assigned to s3_FilterTime is 500ms.
0 (16#0000) is assigned to s2_InputMask is , i.e. bit 0 to F will be not filtered
if the filter processing time specified by s3_Time is less than 0 or greater than 30000.
if the filter processing time specified by s3_Time is less than 0 or greater than 30000.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
bStart: BOOL:=FALSE;
wInputData: WORD:=16#A9BC;
wInputMask: WORD:=16#000C;
(*2#0000000000001100 i.e. bits 2 and 3 filtered*)
wOutputData: WORD:=0;
iFilterTime: INT:=100;
(*0.1 seconds*)
END_VAR
If bStart is TRUE, the bits of the data applied to s1_In are output as follows: The filtered bits will only be written to wOutputData after the filter time has elapsed. See time charts for a detailed explanation.
The bits which are not set in the mask data applied to n_Bits are directly output without conditions.
The bits which are set in the mask data applied to n_Bits are output after their signal has remained stable for the time specified by s3_Time in ms.
wOutputdata has the value 16#A9B0 for 100ms, when this time has elapsed wOutputData has the value 16#A9BC.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_VARIN,,wInputData,10,2,12,4,);
B(B_VARIN,,wInputMask,10,3,12,5,);
B(B_VARIN,,iFilterTime,10,4,12,6,);
B(B_CONTACT,,bStart,4,1,6,3,);
B(B_F,FP_DEBOUNCE!,,12,0,20,6,,?DEN?Ds1_In?Dn_Bits?Ds3_Time?AENO?Cd);
B(B_VAROUT,,wOutputData,20,2,22,4,);
L(1,2,4,2);
L(6,2,12,2);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
If (bStart) then
FP_DEBOUNCE(s1_In := wInputData,
n_Bits := wInputMask,
s3_Time := iFilterTime,
d => wOutputData);
End_if;