SET_BF: Set bit field (S7-1200, S7-1500) - STEP 7

FBD (S7-1200, S7-1500)

ft:publication_title
FBD (S7-1200, S7-1500)
Product
STEP 7
Version
V20
Publication date
11/2024
Language
en-US
SET_BF: Set bit field

Description

You use the "Set bit field" instruction to set several bits starting from a certain address.

You specify the number of bits to be set with the value of the constant at the N input. The address of the first bit to be set is defined by <Operand>. If the value of <Operand> may not be greater than the number of bits in a selected byte. If this value is greater, the instruction is not executed and the error message "Range violation for index <Operand1>" is displayed. The bits remain set until they are explicitly reset by another instruction.

The instruction is only executed if the enable input EN has the signal state "1".

Bit fields of the type PLC data type, STRUCT or ARRAY

With structures of the type PLC data type, STRUCT or ARRAY, the number of bits contained in the structure represents the maximum number of bits that can be reset:

  • If you specify the value "20" at the N input, for example, and the structure only contains 10 bits, then only these 10 bits are set.

  • If you specify the value "5" at the N input, for example, and the structure contains 10 bits, then exactly 5 bits are set.

Parameters

The following table shows the parameters of the "Set bit field" instruction:

Parameters

Declaration

Data type

Memory area

Description

S7-1200

S7-1500

EN

Input

BOOL

I, Q, M, D, L or constant

I, Q, M, D, L, T, C or constant

Enable input

N

Input

UINT

Constant

Constant

Number of bits to be set

<Operand>

Output

BOOL

I, Q, M

With a DB or an IDB, an element of an ARRAY[..] of BOOL

I, Q, M

With a DB or an IDB, an element of an ARRAY[..] of BOOL

Pointer to the first bit to be set.

Example

The following example shows how the instruction works:

If the operands "TagIn_1" and "TagIn_2" have the signal state "1", 5 bits are set starting at the address of the operand "MyDB".MyBoolArray[4].