Schneider PLC Structured Text Counter – Examples and Applications

Published on Sep 04, 2025 | Category: Structured Text

Share this Page:

Structured Text (ST) is a high-level programming language used in Schneider PLCs and other industrial controllers. It allows engineers to write complex logic using statements, loops, and functions, similar to traditional programming languages like Pascal or C. Structured Text is ideal for applications that require precise control, calculations, or data handling.

A counter in Schneider PLC Structured Text is a fundamental instruction that counts events or pulses, such as items on a conveyor, machine cycles, or alarm occurrences. Counters can be implemented as Count Up (CTU), Count Down (CTD), or Count Up/Down (CTUD) to track production, monitor operations, or manage automated processes efficiently.

This page provides practical examples of using counters in Structured Text, including syntax, logic, and real-world applications. You will learn how to configure CTU, CTD, and CTUD counters in EcoStruxure Control Expert, along with explanations of input, output, preset values, and current count. By the end of this page, you will be able to implement counters for industrial automation tasks with Schneider PLCs.

Types of Counters in Schneider PLC Structured Text

In Schneider PLCs, a counter is a function used to count events, pulses, or operations in automation processes. In Structured Text (ST), counters have parameters like CU (Count Up), CD (Count Down), R (Reset), PV (Preset Value), CV (Current Value), and Q (Output when the count reaches PV). Counters are similar to counters in ladder logic but implemented using Structured Text code.

The main types of counters in Schneider PLC Structured Text are:

Counter Classification by Type and Data Type in Structured Text

In Schneider PLC Structured Text, counters are not only classified by counting direction (CTU, CTD, CTUD) but also by the data type of their preset value (PV). Each combination creates a specific counter function block, such as CTU_INT, CTD_DINT, or CTUD_UDINT. Using the correct counter type ensures compatibility with the required range of counts in your application.

Some common counter function blocks based on type and data type are:

Selecting the correct counter type and data type ensures reliable counting in your Structured Text programs and prevents overflow or unexpected behavior.

How Counters are Used in Structured Text

In Structured Text (ST), counters are declared and executed as function blocks. Each counter instance must have a unique name (e.g., CTU_0, CTD_1, CTUD_0) so they can be used independently within a program. A counter function is called with specific input and output parameters that define its counting behavior and status.

General Syntax Example:

Counter_Name (CU := count_up_condition, CD := count_down_condition, R := reset, PV := preset_value, Q => output, CV => current_value);

Counter Parameters in Structured Text

Each counter function block in Structured Text has standard input and output parameters. These parameters control the operation of the counter and provide useful feedback for program logic.

Input Parameters

Output Parameters

How to Add Counters in Structured Text – Schneider PLC

In Schneider PLC EcoStruxure Control Expert, you can use counters directly in your Structured Text (ST) programs by accessing the Types Library Browser. The Types Library contains pre-defined counter function blocks like CTU, CTD, and CTUD, which can be easily added to your program without manually declaring all logic.

Steps to Add a Counter:

  1. Open the Types Library Browser: In your project, navigate to the ST editor and open the Types Library Browser to view available libraries and function blocks.
  2. Select the Library: Choose Base Lib or the library containing standard counter blocks.
  3. Search for the Counter: Use the search box to find the counter you want: CTU for Count Up, CTD for Count Down, or CTUD for Count Up/Down.
  4. Add to Your Program: Drag and drop the counter into the Structured Text editor or use the Copy to Project option.
  5. Configure the Counter: Each counter function is automatically given a unique instance name (e.g., CTU_0). Enter all input and output parameters with the proper data types: CU, CD, R, PV, Q, CV, according to your program logic.

Using the Types Library Browser ensures you are using standard, tested function blocks, which reduces errors and makes your Structured Text program easier to read and maintain. Once added, the counter can be referenced and used just like any other variable or function block in your code.

img/ecostruxurest-counter/how-to-add-counter-in-schneider-plc-structured-text-example.webp

Schneider PLC CTU – Count Up Counter in Structured Text

The CTU (Count Up) counter in Schneider PLC Structured Text is a function block used to count events or pulses in an industrial automation process. Each instance of a CTU counter must have a unique name so that multiple counters can be used independently in the same program. The counter increases its current value (CV) by one each time the CU input is TRUE. The counter compares the current value against the preset value (PV). Once the current value reaches the preset value, the output Q becomes TRUE, which can be used to trigger other actions in the program, such as turning on a conveyor stop signal or signaling that a batch process is complete.

Parameters of the CTU counter:

img/ecostruxurest-counter/counter-up-in-schneider-plc-structured-text-example.webp

For example, consider a counter used to count items passing on a conveyor. Each time a sensor detects an item, the CU input turns TRUE, incrementing the counter. When the counter reaches the preset value of 5, the Q output turns TRUE, which can trigger an indicator light or stop the conveyor for the batch. If at any time the process needs to be restarted, setting the R input to TRUE resets the counter back to zero, ready to count the next batch of items.

Schneider PLC CTD – Count Down Counter in Structured Text

The CTD (Count Down) counter in Schneider PLC Structured Text is a function block that decreases its current value (CV) each time the CD input is TRUE. It is commonly used in applications where you need to track remaining items, count down production cycles, or implement countdown timers. Unlike the CTU counter, which starts from zero and counts up, the CTD counter starts from a specified value and counts down toward zero.

Parameters of the CTD counter:

img/ecostruxurest-counter/counter-down-in-schneider-plc-structured-text-example.webp

For example, imagine a CTD counter monitoring a stock of raw materials in a production line. The counter is initialized with a preset value of 10 using the LD input. Each time an item is used, the CD input pulses, decreasing the counter by one. When the current value reaches zero, the Q output turns TRUE, triggering an alert that the stock is empty or needs replenishment. This ensures efficient inventory management and prevents production delays. The counter can be reset or reloaded at any time to start a new countdown.

Schneider PLC CTUD – Count Up/Down Counter in Structured Text

The CTUD (Count Up/Down) counter in Schneider PLC Structured Text is a versatile function block that can both increase and decrease its current value (CV) depending on input signals. The CU input increments the counter, while the CD input decrements it. This type of counter is ideal for applications where items can be added or removed dynamically, such as inventory tracking, reversible conveyor operations, or bidirectional event counting.

Parameters of the CTUD counter:

img/ecostruxurest-counter/counter-up-down-in-schneider-plc-structured-text-example.webp

For example, consider a CTUD counter used to monitor a reversible conveyor belt. The counter starts with a current value of zero. When the belt moves forward, the CU input pulses, incrementing the counter. When the belt moves backward, the CD input pulses, decrementing the counter. The QU output becomes TRUE when the counter reaches a preset value of 5, indicating a forward limit, while the QD output becomes TRUE when the counter reaches zero, indicating a backward limit. The R and LD inputs allow resetting or loading a specific value into the counter as needed.