GATHER: Merge individual bits into a bit sequence (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
GATHER: Merge individual bits into a bit sequence

Description

The "Merge individual bits into a bit sequence" instruction merges the bits from an ARRAY of BOOL, an anonymous STRUCT or a PLC data type exclusively with Boolean elements into a bit sequence. The bit sequence is saved in a tag of the data type BYTE, WORD, DWORD or LWORD.

Note

Multi-dimensional ARRAY of BOOL

With the "Merge individual bits into a bit sequence" instruction, the use of a multidimensional ARRAY of BOOL is not permitted.

Note

Length of the ARRAY, STRUCT or PLC data type

The ARRAY, STRUCT or the PLC data type must have exactly the number of elements that is specified by the bit sequence.

This means for the data type BYTE, for example, the ARRAY, anonymous STRUCT or the PLC data type must have exactly 8 elements (WORD = 16, DWORD = 32 and LWORD = 64).

Note

Availability of the instruction

The instruction can be used with a CPU of the S7-1200 series as of firmware version >4.2, and for a CPU of the S7-1500 series as of firmware version 2.1.

The enable output ENO returns signal state "0" if one of the following conditions applies:

  • Enable input EN has signal state "0".

  • The ARRAY, anonymous STRUCT or the PLC data type (UDT) has fewer or more BOOL elements than specified by the bit sequence. In this case the BOOL elements are not transferred.

  • Fewer than the necessary number of bits are available.

Parameter

The following table shows the parameters of the instruction:

Parameter

Declaration

Data type

Memory area

Description

S7-1200

S7-1500

EN

Input

BOOL

BOOL

I, Q, M, D, L or constant

Enable input

ENO

Output

BOOL

BOOL

I, Q, M, D, L

Enable output

IN

Input

ARRAY[*] of BOOL, STRUCT or PLC data type

*: 8, 16, 32 or 64 elements

ARRAY[*] of BOOL, STRUCT or PLC data type

*: 8, 16, 32 or 64 elements

I, Q, M, D, L

ARRAY, STRUCT or PLC data type, the bits of which are merged into a bit sequence.

The values must not be located in the I/O area or in the DB of a technology object.

OUT

Output

BYTE, WORD, DWORD

BYTE, WORD, DWORD, LWORD

I, Q, M, D, L

Merged bit sequence, saved in a tag

You can select the required bit sequence from the "???" drop-down list of the instruction box.

You can find additional information on valid data types under "See also".

Example with an ARRAY

Create the following tags in the block interface:

Tag

Section

Data type

Enable

Input

BOOL

SourceArray

ARRAY[0..15] of BOOL

EnableOut

Output

BOOL

DestinationWord

WORD

The following example shows how the instruction works:

The following table shows how the instruction works using specific operand values:

Parameter

Operand

Data type

IN

SourceArray

The operand "SourceArray" is of the data type ARRAY[0..15] of BOOL. It consists of 16 elements and is therefore just as large as the WORD in which the bits are to be merged.

OUT

DestinationWord

WORD (16 bits)

If the operand #Enable returns the signal state "1" at the enable input EN, the instruction is executed. The bits of the #SourceArray operand are merged into a WORD. If an error occurs during the execution of the instruction, the operand #EnableOut returns the signal state "0" at the enable output ENO.

Example with a PLC data type (UDT)

Create the following PLC data type "myBits":

Create the following tags in the block interface:

Tag

Section

Data type

Enable

Input

BOOL

SourceUDT

"myBits"

EnableOut

Output

BOOL

DestinationWord

WORD

The following example shows how the instruction works:

The following table shows how the instruction works using specific operand values:

Parameter

Operand

Data type

IN

SourceUDT

The "SourceUDT" operand has the PLC data type (UDT). It consists of 16 elements and is therefore just as large as the WORD in which the bits are to be merged.

OUT

DestinationWord

WORD (16 bits)

If the operand #Enable returns the signal state "1" at the enable input EN, the instruction is executed. The bits of the #SourceUDT operand are merged into a WORD. If an error occurs during the execution of the instruction, the operand #EnableOut returns the signal state "0" at the enable output ENO.