CTD: Count down (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
CTD: Count down

Description

You can use the "Count down" instruction to decrement the value at output CV. When the signal state at the CD input changes from "0" to "1" (positive signal edge), the instruction is executed and the current counter value at the CV output is decremented by one. Each time a positive signal edge is detected, the counter value is decremented until it reaches the low limit of the specified data type. When the low limit is reached, the signal state at the CD input no longer has an effect on the instruction.

You can query the counter status in the Q output. If the current counter value is less than or equal to "0", the Q output is set to signal state "1". In all other cases, the Q output has signal state "0". You can also specify a constant for the PV parameter.

The value at the CV output is set to the value of the PV parameter and saved to a edge memory bit when the signal state at the LD input changes from "0" to "1". As long as the LD input has signal state "1", the signal state at the CD input has no effect on the instruction.

Note

Only use a counter at a single point in the program to avoid the risk of counting errors.

Each call of the "Count down" instruction must be assigned an IEC counter in which the instruction data is stored. An IEC counter is a structure with one of the following data types:

For S7-1200 CPU

Data block of system data type IEC_<Counter> (Shared DB)

Local tag

  • IEC_SCOUNTER / IEC_USCOUNTER

  • IEC_COUNTER / IEC_UCOUNTER

  • IEC_DCOUNTER / IEC_UDCOUNTER

  • CTD_SINT / CTD_USINT

  • CTD_INT / CTD_UINT

  • CTD_DINT / CTD_UDINT

  • IEC_SCOUNTER / IEC_USCOUNTER

  • IEC_COUNTER / IEC_UCOUNTER

  • IEC_DCOUNTER / IEC_UDCOUNTER

For S7-1500 CPU

Data block of system data type IEC_<Counter> (Shared DB)

Local tag

  • IEC_SCOUNTER / IEC_USCOUNTER

  • IEC_COUNTER / IEC_UCOUNTER

  • IEC_DCOUNTER / IEC_UDCOUNTER

  • IEC_LCOUNTER / IEC_ULCOUNTER

  • CTD_SINT / CTD_USINT

  • CTD_INT / CTD_UINT

  • CTD_DINT / CTD_UDINT

  • CTD_LINT / CTD_ULINT

  • IEC_SCOUNTER / IEC_USCOUNTER

  • IEC_COUNTER / IEC_UCOUNTER

  • IEC_DCOUNTER / IEC_UDCOUNTER

  • IEC_LCOUNTER / IEC_ULCOUNTER

You can declare an IEC counter as follows:

  • Declaration of a data block of system data type IEC_<Counter> (for example, "MyIEC_COUNTER")

  • Declaration as a local tag of the type CTD_<Data type> or IEC_<Counter> in the "Static" section of a block (for example #MyIEC_COUNTER)

When you set up the IEC counter in a separate data block (single instance), the instance data block is created by default with "optimized block access" and the individual tags are defined as retentive. For additional information on setting retentivity in an instance data block, refer to "See also".

When you set up the IEC counter as local tag (multi-instance) in a function block with "optimized block access", it is defined as retentive in the block interface.

The execution of the "Count down" instruction requires a preceding logic operation. It can be placed within or at the end of the network.

Parameters

The following table shows the parameters of the "Count down" instruction:

Parameter

Declaration

Data type

Memory area

Description

S7-1200

S7-1500

CD

Input

BOOL

I, Q, M, D, L or constant

I, Q, M, D, L or constant

Count input

LD

Input

BOOL

I, Q, M, D, L, P or constant

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

Load input

PV

Input

Integers

I, Q, M, D, L, P or constant

I, Q, M, D, L, P or constant

Value to which the CV output is set with LD = 1.

Q

Output

BOOL

I, Q, M, D, L

I, Q, M, D, L

Counter status

CV

Output

Integers, CHAR, WCHAR, DATE

I, Q, M, D, L, P

I, Q, M, D, L, P

Current counter value

You can select the data type of the instruction from the "???" drop-down list of the instruction box.

Example

The following example shows how the instruction works:

When the signal state of the "TagIn_1" operand changes from "0" to "1", the instruction is executed and the value at the "Tag_CV" output is decremented by one. With each additional positive signal edge, the counter value is decremented until the low limit of the specified data type (INT = -32768) is reached.

The value of the PV parameter is adopted as the limit for determining the "TagOut" output. The "TagOut" output has signal state "1" as long as the current counter value is less than or equal to "0". In all other cases, the "TagOut" output returns the signal state "0".