FP_COUNT_TRUE_BITS

Number of ON bits

This FP instruction counts the number of bits which are TRUE in the data specified by s if the trigger EN is TRUE. The result is stored in d.

Parameters

Input

s (WORD, DWORD)

Input value

Output

d (INT, DINT, UINT, UDINT)

Number of bits which are TRUE in the argument applied at s

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*)
		dwChecked_value: DWORD:=16#1111FFFF;
			(*this value will be checked
for ON-bits*)
		iOutput_value: INT:=0;
			(*result after a 0->1 leading
edge from start: 20*)
	END_VAR

POU body

When the variable bStart is set to TRUE, the function is carried out. The number of bits which are TRUE in the binary equivalent of 16#1111FFFF is 20.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,FP_COUNT_TRUE_BITS!,,15,1,27,5,,?DEN?D@'s'?AENO?Cd);
B(B_CONTACT,,bStart,10,2,12,4,);
B(B_VARIN,,dwChecked_value,13,3,15,5,);
B(B_VAROUT,,iOutput_value,27,3,29,5,);
L(1,3,10,3);
L(12,3,15,3);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF bStart then
    FP_COUNT_TRUE_BITS(s := dwChecked_value, d => iOutput_value);
END_IF;

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