GATHER_BLK: Merge individual bits into multiple elements of an ARRAY of 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_BLK: Merge individual bits into multiple elements of an ARRAY of bit sequence

Description

The "Merge individual bits into multiple elements of an ARRAY of bit sequence" instruction merges the bits from an ARRAY of BOOL, an anonymous STRUCT or a PLC data type exclusively with Boolean elements into one or multiple elements of an ARRAY of <bit sequence>. At the COUNT_OUT parameter you specify how many elements of the destination ARRAY are going to be written. With this step you also implicitly specify how many elements of the ARRAY of BOOL, the anonymous STRUCT or the PLC data type are required. The destination ARRAY at the OUT parameter may have more elements than specified at the COUNT_OUT parameter. The ARRAY of <bit sequence> must have sufficient elements to save the bits that are going to be merged. However, the destination ARRAY may also be larger.

Note

Multi-dimensional ARRAY of BOOL

If the ARRAY is a multi-dimensional ARRAY of BOOL, the padding bits of the dimensions contained are counted as well even if they were not explicitly declared and are not accessible.

Example 1: An ARRAY[1..10,0..4,1..2] of BOOL is handled like an ARRAY[1..10,0..4,1..8] of BOOL or like an ARRAY[0..399] of BOOL.

Example 2: At the OUT parameter, an ARRAY[0..5] of WORD (sourceArrayWord[2]) is interconnected. The COUNT_IN parameter has the value "3". At the IN parameter, an ARRAY[0..1,0..5,0..7] of BOOL (destinationArrayBool[0,0,0]) is interconnected. Both the array at the IN parameter and at the OUT parameter has a size of 96 bits. 48 individual bits are merged from the ARRAY of BOOL.

Note

If the ARRAY low limit of the source ARRAY is not "0", note the following:

For performance reasons the index must always start at a BYTE, WORD, DWORD or LWORD limit. This means the index must be calculated starting at the low limit of the ARRAY. The following formula is used as basis for this calculation:

Valid indices = ARRAY low limit + n(number of bit sequences) × number of bits of the desired bit sequence

For an ARRAY[-2..45] of BOOL and the bit sequence WORD the calculation looks as follows:

  • Valid index (-2) = -2 + 0 × 16

  • Valid index (14) = -2 + 1 × 16

  • Valid index (30) = -2 + 2 × 16

You can find an example described below.

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 index of the source ARRAY does not start at a BYTE, WORD, DWORD or LWORD limit. In this case, no result is written to the ARRAY of <bit sequence>.

  • The ARRAY[*] of <bit sequence> does not provide the required number of elements.

    • S7-1500-CPU: In this case as many bit sequences as possible are merged and written to the ARRAY of <bit sequence>. The remaining bits are no longer taken into account.

    • S7-1200-CPU: There is no copying procedure.

Note

S7-1200-CPU: Enable output ENO = 0

When the enable output ENO has signal state "0", no data are written to the output parameter OUT.

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

Element of an ARRAY[*] of

- BOOL

- STRUCT

- PLC data type

Element of an ARRAY[*] of

- BOOL

- STRUCT

- PLC data type

I, Q, M, D, L

ARRAY of BOOL, STRUCT or PLC data type whose bits are merged (source ARRAY)

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

COUNT_OUT

Input

USINT, UINT, UDINT

USINT, UINT, UDINT, ULINT

I, Q, M, D, L

Counter how many elements of the target ARRAY are to be described.

The value must not be in the I/O area or in the database of a technology object.

OUT

Output

Element of an ARRAY[*] of

- BYTE

- WORD

- DWORD

Element of an ARRAY[*] of

- BYTE

- WORD

- DWORD

- LWORD

I, Q, M, D, L

ARRAY of <bit sequence> to which the bits are saved (destination ARRAY)

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 of a source ARRAY with the low limit "0"

Create the following tags in the block interface:

Tag

Section

Data type

Enable

Input

BOOL

SourceArrayBool

ARRAY[0..95] of BOOL

CounterOutput

UDINT

EnableOut

Output

BOOL

DestinationArrayWord

ARRAY[0..5] of 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

SourceArrayBool[0]

The operand "SourceArrayBool" is of the data type ARRAY[0..95] of BOOL. This means it provides 96 BOOL elements that can merged into words once again.

COUNT_OUT

CounterOutput = 3

UDINT3 (3 words are to be written. This means 48 bits must be available in the source ARRAY.)

OUT

DestinationArrayWord[2]

The operand "DestinationArrayWord" is of the data type ARRAY[0..5] of WORD. This means 6 WORD elements are available.

If the operand #Enable returns the signal state "1" at the enable input EN, the instruction is executed. As of the 1st element of the #SourceArrayBool operand, 48 bits are merged in the #DestinationArrayWord operand. The starting point in the destination ARRAY is the 3rd element. This means that the first 16 bits are written into the 3rd word, the second 16 nits into the 4th word and the third 16 bits into the 5th word of the destination ARRAY. If an error occurs during the execution of the instruction, the operand #EnableOut returns the signal state "0" at the enable output ENO.

Example of a source ARRAY with the low limit "-2"

Create the following tags in the block interface:

Tag

Section

Data type

Enable

Input

BOOL

SourceArrayBool

ARRAY[-2..93] of BOOL

CounterOutput

UDINT

EnableOut

Output

BOOL

DestinationArrayWord

ARRAY[0..5] of 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

SourceArrayBool[14]

The operand "SourceArrayBool" is of the data type ARRAY[-2..93] of BOOL. Because the starting point is the 16th element, only 80 BOOL elements that can be merged into words again are available.

COUNT_OUT

CounterOutput = 3

UDINT3 (3 words are to be written. This means 48 bits must be available in the source ARRAY.)

OUT

DestinationArrayWord[2]

The operand "DestinationArrayWord" is of the data type ARRAY[0..5] of WORD. This means 6 WORD elements are available.

If the operand #Enable returns the signal state "1" at the enable input EN, the instruction is executed. Starting with the 16th element of the #SourceArrayBool operand, 48 bits are merged into the #DestinationArrayWord operand. The starting point in the destination ARRAY is the 3rd element. This means the first 16 bits of the source ARRAY are ignored. The second 16 Bits are written into the 3rd word, the third 16 bits into the 4th word and the fourth 16 bits into the 5th word of the destination ARRAY. The remaining 64 bits of the source ARRAY are not taken into account either. If an error occurs during the execution of the instruction, the operand #EnableOut returns the signal state "0" at the enable output ENO.