General

This example of programming a counter using a DFB is provided for instruction purposes.

Characteristics of the DFB Type

The DFB type used to create the counter is as follows.

The elements of the Cpt_parts DFB type are as follows.

Elements

Description

Name of the DFB type

Cpt_parts

Input parameters

  • Reset: counter reset (EBOOL type)

  • Presel: Preset value of the counter (DINT type)

  • Count: upcounter input (EBOOL type)

Output parameters

Done: preset value reached output (BOOL type)

Public internal variable

V_cour: current value of the counter (DINT type)

Operation of the Counter

The operation of the counter must be as follows.

Phase

Description

1

The DFB counts the rising edges on the Count input.

2

The number of edges it counts is then stored by the variable V_cour. This variable is reset by a rising edge on the Reset input.

3

When the number of edges counted is equal to the preset value, the Done output is set to 1. This variable is reset by a rising edge on the Reset input.

Internal Program of the DFB

The internal program of the DFB type Cpt_parts is defined in Structured Text as follows.

Example of Use

Let us suppose your application needs to count 3 part types (for example, bolts, nuts and screws). The DFB type Cpt_parts can be used three times (3 instances) to perform these different counts.

The number of parts to be procured for each type is defined in the words %MD10, %MD12 and %MD14 respectively. When the number of parts is reached, the counter sends a command to an output (%Q1.2.1, %Q1.2.2 or %Q1.2.3) which then stops the procurement system for the corresponding parts.

The application program is entered in Ladder language as follows. The 3 DFBs (instances) Cpt_bolts, Cpt_nuts and Cpt_screws are used to count the different parts.