Counters in PLC Programming

A PLC counter counts up or down within a function block until it reaches a limit. Reaching that limit sets the output.
In PLC programming, counting tracks how often a process completes or how many products it produces. A PLC counter works as a digital tally counter to help manage these industrial tasks efficiently.
PLC counters also support logging to SCADA systems by recording how often these events have happened or setting alarms after an event has happened a certain number of times.
Timers are useful, and every PLC programmer needs to understand the basics of counting in a PLC program. Here I explain how counters work and how to use them in your PLC programs.
Watch my PLC counter tutorial or read the written tutorial below the video:
Content:
Basics of Counting in a PLC
Before adding counting to a PLC program, learn the basics of its counter instructions and the PLC itself. These determine how counting works in your program.
Learn the counting limits of your PLC so you know the maximum number its counter can reach before a reset or overflow.
Counter Limits
To store numbers in the PLC, counters use variables with specific data types. Every counter must store at least two numbers:
- Counter Limit
- Current Counter Value
The data type used to store these two numbers also limits their values. Many PLCs store them as WORD or Integer data types. As covered in the basics of PLC data types, a WORD takes up 16 bits.
A signed integer uses 16 bits too. The first bit holds the sign, leaving 15 bits for the number itself.
With a little bit of calculation we’ll quickly find out that the maximum value of a WORD is 16.535. The maximum value of the signed integer is 32.767.
You will rarely need to count this high, but knowing these limits helps you avoid overflow errors.
High-Speed Counters
Standard counters might be unable to keep up with fast pulses from sources such as encoders. For these signals, you need a high-speed counter module designed to capture them.
Known as high-speed counters, these input modules capture inputs across a range of high frequencies.
Counter Function Blocks
Every counter operation or counter function block has inputs and outputs. Two have already appeared in this tutorial: the counter limit and current counter value.
Check which data types the inputs and outputs accept. Counters normally use boolean and WORD data types, although the types can depend on your PLC platform. Consult that platform’s counter documentation before using them.
Up Counter (CTU)
Start with the up counter instruction, usually called CTU. This PLC counter increases the count, as its name suggests.
The illustration below shows the up counter function block:
Each incoming pulse adds one to an Up Counter. Once the count reaches the specified limit, the counter sets an output.
How it works
Each pulse on the count input (CU) will increase the current counter value (CV) by 1. When CV is greater than or equal to the counter limit (PV) the output (Q) is set. A pulse on the reset input (R) will reset the value of CV to 0.
Example:
Use an up counter to track how often an event has happened. For example, you might need to clean a system after a process completes 10 times.
Set the counter limit (PV) to 10 and send a pulse to the count input (CU) whenever the process completes. After the process has completed 10 times, the counter sets output (Q). You can use that output to trigger an alarm telling you that the system needs cleaning.
After cleaning, send a pulse to the reset input (R) to start the count again.
Down Counter (CTD)
PLC programs also commonly count down. This tells you how many counts remain before reaching a limit. You can calculate this from an up counter, or use a down counter to track it directly.
A Down Counter starts at a set number and counts backwards to zero. Its countdown shows how many processes remain.

The down counter has a load pin, called LD, in place of the reset pin. Load assigns a value to the current counter value, giving the counter a starting point for counting down to 0.
How it works
Each pulse on the count input (CD) will decrement current counter value (CV) by 1. When CV is less than or equal to 0 the output (Q) is set. A pulse on the load input (LD) will assign the value of counter limit (PV) to CV.
Example:
Imagine a semi-automatic process that an operator starts with a manual task. The process must complete 10 times, with an inspection when 2 repetitions remain. Because the total number of repetitions can change, the operator needs to see how many remain.
Use a down counter for this task. Assign the total number of process repetitions to the counter limit (PV), then pulse the load input (LD). The current counter value (CV) now contains that total.
Pulse the count input (CD) each time the process completes. Display CV so the operator can see how many repetitions remain and inspect when there are 2 left. You can also trigger an alarm by comparing CV to 2 with an equality operator.
Up Down Counter (CTUD)
The up down counter combines both directions of counting. This is useful when you need to increase and decrease the same count, with an upper limit and a lower limit.
The illustration below shows its extra pins compared with the other counters:

This counter increases and decreases a shared current counter value (CV). At the top of the function block are 2 count inputs, with one for counting up and the other for counting down.
How it works
Each pulse on the count input (CU) will increase the current counter value (CV) by 1. And each pulse on the count input (CD) will decrement current counter value (CV) by 1.
When CV is greater than or equal to the counter limit (PV) the output (QU) is set. When CV is less than or equal to 0 the output (QD) is set.
A pulse on the reset input (R) will reset the value of CV to 0. A pulse on the load input (LD) will assign the value of counter limit (PV) to CV.
Example:
An up down counter can track finished products. Suppose you need to produce a certain number of products in a batch control system. Each finished product requires manual inspection. When an inspector discards a product, subtract it from the finished product count.
With an up down counter, pulse the count up input (CU) whenever a product is finished. If that product fails the inspection, pulse the count down input (CD) to decrease the number of products produced.






