Navigation:  Equipments (Devices) > SCA06 > Ladder > Logic > Logic Bit >

TESTBIT

Previous pageReturn to chapter overviewNext page

Logical block that revolutions the value of a specific bit in a field.

 

Ladder Representation

 

TESTBIT_block

 

Block Structure

 

Variable Type

Name

Data Type

Description

VAR_INPUT

Data

BYTE USINT SINT WORD UINT INT DWORD UDINT DINT

Variable whose bit will be tested

EN

BOOL

Block enabling

Position

BYTE USINT

Position of the bit that will be changed

VAR_OUTPUT

Q

BOOL

Value of the tested bit

 

Operation

 

This block when it has a TRUE value in EN, sends to the output Q the bit value indicated in Position in the Data variable.

 

When EN has FALSE value, Q also receives FALSE.

 

wpshelp_common_fig_note

NOTE!

It is important to notice that Position is within the range of values of bits corresponding to variable type in Data. For example: if Data is a BYTE, it has 8 bits, and Position must contain a value between 0 and 7.

 

Block Flowchart

 

TESTBIT_flowchart

 

Example in Ladder

 

TESTBIT_example01

 

The example above sets the bit value of zero position of AUX, whose initial value is 74 (0100 1010 in binary) to the output Q. Since this bit has value 0, the output is disabled.

 

TESTBIT_example02

 

The example above sets the value of the bit of position three of AUX to the output Q. Since this bit has value 1, the output is enabled.

 

TESTBIT_example03

 

The example above sets the bit value of position ten of AUX to output Q. Since AUX is a variable of BYTE type, it has only eight bits. Thus, the example above creates a runtime error in the block and therefore the output is disabled.

 

Example in ST

 

 The example below displays the instructions for applying the example above in the ST language.

 

 

VAR

   AUX : BYTE := 2#0100_1010;

   POS : BYTE := 3;

END_VAR

 

DO1 := FB_TESTBIT(

   EN:=DI1,

   Data:=AUX,

   Position:=POS);