FP_DEBOUNCE

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.

Parameters

Input

s1_In (WORD)

Input data whose bits will be filtered according to the input mask

n_Bits (WORD, INT, UINT)

Input mask which specifies which bits will be filtered

s3_Time (INT)

Specifies the time in ms during which the signal at the specified bits has to be stable

Output

d (WORD)

Filtered data

Time chart

  • 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.

    1.  (1) Bit 0 of input data
    2.  (2) Bit 0 of filter result
    3.  (3) Data is initialized when the system detects the trigger's rising edge.
    4.  (4) The instruction does not operate while the trigger is OFF.
  • 0 (16#0000) is assigned to s2_InputMask is , i.e. bit 0 to F will be not filtered

    1.  (1) Bit 1–15 of input data
    2.  (2) Bit 1–15 of filter result
    3.  (3) Data is initialized when the system detects the trigger's rising edge.
    4.  (4) The instruction does not operate while the trigger is OFF.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the filter processing time specified by s3_Time is less than 0 or greater than 30000.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the filter processing time specified by s3_Time is less than 0 or greater than 30000.

Example

POU header

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

POU body

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.

LD body

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

ST body

If (bStart) then
    FP_DEBOUNCE(s1_In := wInputData, 
                n_Bits := wInputMask, 
                s3_Time := iFilterTime, 
                d => wOutputData);
End_if;

Modified on: 2019-08-23Feedback on this pagePanasonic hotline