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.
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.
| Counter | Typical reset | Retentive? |
|---|---|---|
| Batch count | Approved batch start/reset | Usually during brief power loss |
| Shift count | Shift change with authorization | Yes until recorded |
| Rejected parts | Same production-period procedure | Usually yes |
| Lifetime total | Maintenance-only or never | Yes |
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
- Measure the real sensor ON and OFF times at minimum and maximum line speed.
- Verify wiring, input filtering and scan time.
- Monitor raw sensor, validated signal, one-shot pulse and CV together.
- Pass ten products slowly, then at normal speed, and compare physical and PLC totals.
- Test a product stopped in front of the sensor, rapid vibration, sensor disconnection and power cycling.
- Verify every permitted and prohibited reset path.
| Symptom | Cause | Correction |
|---|---|---|
| One part adds many counts | Level-based increment | Use a rising-edge pulse |
| Counts missed at high speed | Pulse shorter than scan/input filter | Use suitable input filtering or a high-speed counter |
| Extra counts during vibration | No debounce/validation | Validate pulse width and sensor setup |
| Count lost after power cycle | Non-retentive storage | Apply documented retentivity or save through the approved architecture |
Hands-On Lab: Build and Prove a Production Counter
Hands-on- 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
Build the signal path
Add a short validation TON, a rising-edge instruction and a CTU with PV=10. Use named intermediate tags.
Prove one-count behavior
Hold the raw sensor true for five seconds while watching the pulse and CV.
Test noise and line speed
Toggle the raw input faster than the validation time, then generate correctly spaced products.
Test batch complete and reset
Generate ten accepted pulses, confirm Q, then test reset only under the permitted machine condition.
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.
