PLC Programming · Technical Blog

PLC Counter Programming for Reliable Production Counting

Learn how to count parts once—and only once—with edge detection, CTU presets, sensor validation, batch logic, controlled reset and production totalization.

2,500+ engineers trained 4.9/5 Google rating 21+ years, Chinchwad, Pune Next batch: contact for dates
Quick answer

A reliable production counter increments once for each confirmed part event, not once per PLC scan. Feed a clean rising-edge pulse into CTU, separate batch reset from lifetime totals, validate sensor behavior, and define exactly what happens after power loss, recipe change and operator reset.

  • A raw sensor held ON across many scans must still create only one count.
  • Debounce or validation logic prevents vibration and noisy transitions from adding false parts.
  • Batch count, shift count and lifetime total need separate reset and retentivity rules.

Why PLC Production Counters Overcount

A PLC may scan its logic thousands of times while one product remains in front of a sensor. If count logic increments on signal level instead of a transition, a single part can add dozens or hundreds of counts. Mechanical vibration, poor alignment, transparent packaging and electrical noise can create additional false transitions.

Start by defining one valid product event: for example, a photoelectric sensor changing from false to true and remaining stable for at least 30 ms. Then convert that event into a one-scan pulse before it reaches the counter.

Want to practice this on real hardware?

Join a live Siemens PLC session with practical TIA Portal exercises—online, Pune classroom or corporate in-plant.

Book a Free Demo Class

CTU and Rising-Edge Detection

The IEC CTU function increments CV on a rising edge at CU. When CV reaches preset PV, Q becomes true. R resets the counter. In Siemens TIA Portal the safest design makes the edge visible and testable, even if the chosen counter instruction already detects the edge internally.

  • CU: one confirmed part pulse.
  • R: controlled reset command.
  • PV: batch target.
  • CV: current counted quantity.
  • Q: batch-complete status when CV ≥ PV.

Signal validation pattern

Use a short TON to confirm the sensor stays active, then apply a positive-edge instruction to the validated signal. Do not choose an arbitrary debounce time: at maximum line speed it must be shorter than the minimum gap between valid products.

Production Architecture and Reset Design

One number rarely satisfies every production requirement. Separate counters by purpose and ownership.

CounterTypical resetRetentive?
Batch countApproved batch start/resetUsually during brief power loss
Shift countShift change with authorizationYes until recorded
Rejected partsSame production-period procedureUsually yes
Lifetime totalMaintenance-only or neverYes

Reset should be deliberate, authorized and logged. A reset pushbutton must not erase a lifetime total or create an immediate machine start. If counts are sent to SCADA, SQL or an MES, include a unique batch ID and use a handshake or sequence number so communication retries do not duplicate records.

Commissioning and Troubleshooting

  1. Measure the real sensor ON and OFF times at minimum and maximum line speed.
  2. Verify wiring, input filtering and scan time.
  3. Monitor raw sensor, validated signal, one-shot pulse and CV together.
  4. Pass ten products slowly, then at normal speed, and compare physical and PLC totals.
  5. Test a product stopped in front of the sensor, rapid vibration, sensor disconnection and power cycling.
  6. Verify every permitted and prohibited reset path.
SymptomCauseCorrection
One part adds many countsLevel-based incrementUse a rising-edge pulse
Counts missed at high speedPulse shorter than scan/input filterUse suitable input filtering or a high-speed counter
Extra counts during vibrationNo debounce/validationValidate pulse width and sensor setup
Count lost after power cycleNon-retentive storageApply documented retentivity or save through the approved architecture

Hands-On Lab: Build and Prove a Production Counter

Hands-on
Before you start
  • TIA Portal with PLCSIM or safe PLC trainer
  • Simulated photoeye tag, reset command and batch preset of 10
  • Watch table containing raw sensor, validated sensor, pulse, CV and Q
  • Estimated time: 25 minutes
1

Build the signal path

Add a short validation TON, a rising-edge instruction and a CTU with PV=10. Use named intermediate tags.

One clean rising-edge pulse reaches CU for each accepted sensor event.
2

Prove one-count behavior

Hold the raw sensor true for five seconds while watching the pulse and CV.

CV increases by exactly one although the input spans many PLC scans.
3

Test noise and line speed

Toggle the raw input faster than the validation time, then generate correctly spaced products.

Short noise pulses are rejected while valid products count once.
4

Test batch complete and reset

Generate ten accepted pulses, confirm Q, then test reset only under the permitted machine condition.

Q becomes true at the preset and reset clears only the intended batch counter.
Checkpoint—how to know you did it right

Your monitored values match every expected result, abnormal cases have been tested, no force remains active, and the final project revision and test evidence are saved.

Frequently asked questions

Why does my PLC counter increase every scan?

The program is incrementing while a signal is true instead of only when it changes from false to true. Use a positive-edge pulse or an IEC counter with verified edge behavior.

When should I use a high-speed counter?

Use hardware high-speed counting when the input pulse can be shorter than the PLC input filter or scan cycle, such as encoders and fast packaging lines.

Should production counters be retentive?

It depends on the business meaning. Batch and shift totals often need retention through brief outages; temporary diagnostic counts may not. Document the restart and reset philosophy.

Reviewed by Bhawesh Kumar SinghIndustrial Automation Trainer and Industry 4.0 Consultant · Softwell Automation · 21+ years industry experience

Get the full syllabus + free demo class

Share your details—a Softwell training advisor will contact you with batch dates, fees and hardware-practice options.

No spam. Used only to share course details for this enquiry.

Learn with practical industrial examples

Join live online, Pune classroom or corporate in-plant automation training.

Request Course Details
Verified learning pathway

Discuss PLC Counters and Production Counting

Explore practical curriculum, software, hardware and batch options for this technology.

Content reviewed: 14 July 2026

Siemens PLC & TIA Portal Learning Path

Continue with the related Siemens PLC tutorials in this practical learning series.

  1. SCL vs Ladder Logic
  2. Upload PLC Program
  3. TIA Selection Tool
  4. Analog Input Scaling
  5. PLC Counters
  6. PLC Timers
  7. Addressing & Data Types
  8. Hardware & PLC Tags
  9. OB, FB, FC & DB
☎ Call WhatsApp ✉ Email Enquire Now