FP_TEST_BIT

Bit test

This FP instruction checks the state 1 (TRUE) or 0 (FALSE) of bit position n_Pos in the input value at s if the trigger EN is in the ON-state. The result is stored in d.

Parameters

Input

s (WORD)

Input value

n_Pos (INT, DINT, UINT, UDINT)

Specifies the bit position to be checked in decimal data (permissible range: 0–15)

Output

d (BOOL)

State of bit position

Remarks

The specified bit is checked by the system variable sys_bIsEqual.

  • When specified bit is 0 (OFF), sys_bIsEqual (=flag) turns ON.

  • When specified bit is 1 (ON), sys_bIsEqual (=flag) turns OFF.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the area specified using the index modifier exceeds the limit.
sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the area specified using the index modifier exceeds the limit.

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;
			(*activates the function*)
		bBit0_is_TRUE: BOOL:=FALSE;
			(*TRUE if bit LSB of input value is TRUE else FALSE*)
		wValue: WORD:=2#101;
			(*input value*)
	END_VAR

POU body

When the variable bStart is set to TRUE, the function is carried out.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_CONTACT,,bStart,4,2,6,4,);
B(B_F,FP_TEST_BIT!,,9,1,17,6,,?DEN?D@'s'?Dn_Pos?AENO?Cd);
B(B_VARIN,,wValue,7,3,9,5,);
B(B_VARIN,,0,7,4,9,6,);
B(B_VAROUT,,bBit0_is_TRUE,17,3,19,5,);
L(1,3,4,3);
L(6,3,9,3);
L(1,0,1,7);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF bStart then
    FP_TEST_BIT(s := wValue, n_Pos := 0, d => bBit0_is_TRUE);
END_IF;

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