Timers, Counters, and Comparison Instructions in PLCs
What You'll Learn
- 1Select the correct timer type for a delay requirement
- 2Count events with up and down counters
- 3Combine comparisons for bands and interlocks
- 4Explain timer reset and retentive behavior
Timers, counters, and comparisons are the working vocabulary of discrete control. A timer delays or stretches an action relative to a rung condition, a counter accumulates events such as parts or jams, and comparison instructions turn numbers into decisions. Choosing the wrong timer type or forgetting a reset is a frequent source of intermittent faults, so reset rules and status bits deserve close attention.
Timer Types and Reset Rules
An on delay timer starts timing when its rung becomes true and sets the done bit when the accumulated time reaches the preset; if the rung goes false first, a non retentive timer resets immediately. An off delay timer does the opposite, timing after the rung goes false, which suits fan coast after stop or flash off logic. A pulse timer produces a fixed length pulse on a rising edge, ideal for stroke or blip outputs.
A retentive timer keeps its accumulated value when the rung drops out and advances again when the rung is true, and it must be cleared by an explicit reset. That behavior fits total run time for maintenance and soak cycles. Timers use their own time base, and mixing millisecond and second presets is a classic commissioning error, as is assuming a timer tracks wall clock time, which requires a real time clock instruction instead.
Counters and Event Accumulation
An up counter increments on a false to true transition of its input, a down counter decrements, and a reset instruction clears the accumulator. Only the edge matters, so holding a sensor on for many scans counts once provided the input transitions properly. Presets define a target such as a batch size or a jam threshold, and reaching the preset sets the done bit used by comparisons.
For pulses faster than the scan can resolve, use a high speed counter module or an encoder input rather than a program counter, because a scan can miss short edges entirely. Beware signed integer limits: an integer that reaches its maximum wraps or faults depending on the platform. Design counters with explicit reset conditions and handle overflow so a run counter cannot silently corrupt a batch quantity.
Comparisons and Bands
Comparison instructions test equal, not equal, greater than, less than, and the inclusive variants between limits. They convert measurements into alarms and interlocks: run the pump only when level is above minimum and below maximum, or stop when temperature exceeds trip. Limit comparisons provide a simple band check with a single instruction.
Analog values fluctuate, so a single comparison chatter creates alarm storms. Add hysteresis by using separate trip and reset thresholds, or a timer that must see the condition persist. Deadband tuning in the transmitter or the scaling block also reduces noise. Keep alarm limits documented with engineering units so a later range change cannot silently break the logic.
Timer and Counter Behavior
| Type | Trigger | Reset Behavior |
|---|---|---|
| On delay TON | Rung goes true | Resets when rung goes false |
| Off delay TOF | Rung goes false | Accumulates after rung drops |
| Pulse TP | Rising edge | Runs one preset width |
| Retentive RTO | Rung true, accumulates | Requires explicit reset |
| Up counter CTU | Input rising edge | Explicit reset only |
| Down counter CTD | Input rising edge | Explicit reset only |
Real-World Examples
- Motor start delay â An on delay timer holds start until lubrication pressure is proven for three seconds before contactor pickup.
- Conveyor jam detection â An up counter counts box edges and trips when a preset is reached without an empty gap clearing the count.
- Batch box count â Two counters track total and remaining boxes, with a done bit triggering the discharge step.
- High temperature alarm with hysteresis â A comparison trips at ninety degrees and resets at eighty five, preventing chatter at the limit.
đTimers Are Not Clocks
Common Mistakes
Assuming a non retentive timer holds its value
Fix: A false rung resets most timers, so use a retentive type or latch the value when accumulation matters.
Counting fast pulses in the scan
Fix: Short pulses between scans are missed; use a high speed counter or hardware interrupt input.
Using one threshold for trip and reset
Fix: Add hysteresis so an analog value sitting at the limit does not toggle the output every scan.
Key Takeaways
- Timer type determines behavior when the rung condition disappears.
- Counters count edges, not elapsed scans.
- Retentive timers and counters need explicit resets.
- Comparisons need hysteresis and persistence for analog signals.
Frequently Asked Questions
Why did my timer reset unexpectedly
A non retentive timer clears whenever its rung goes false, so check the rung conditions before blaming the preset.
How many pulses can a program counter catch
Only transitions the scan observes, so pulses shorter than the scan interval can be missed entirely.
What is the difference between a preset and a done bit
The preset is the target value; the done bit signals the accumulated value has reached it.
Interview Questions
Q1: Design a three second start delay that survives a momentary dropout
Use a retentive on delay timer with a separate reset condition, or filter the rung with a seal so a brief dropout does not restart the count.
Q2: How do you stop alarm chatter on an analog limit
Trip and reset at different thresholds, optionally combined with a confirmation timer so only sustained conditions annunciate.
Extended Learning: Beyond the Basics
Key Concepts Summary
This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.
Prerequisite Knowledge
Before studying this topic in depth, ensure you understand:
- Basic definitions and terminology
- Core formulas and their derivations
- Common applications in real-world scenarios
- Typical pitfalls and misconceptions
Step-by-Step Walkthrough
Let us work through a complete example to solidify understanding:
Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.
Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.
Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.
Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.
Common Mistakes to Avoid
- Misidentifying the problem type â Always start by categorizing the problem
- Incorrect formula application â Verify the formula applies to your specific case
- Unit errors â Always check units are consistent throughout
- Sign errors â Pay careful attention to positive and negative values
- Rounding too early â Keep full precision until the final answer
- Forgetting constraints â Check that solutions satisfy all given conditions
Real-World Applications
Understanding this concept is essential for:
- Advanced problem solving in examinations
- Building intuition for more complex topics
- Developing analytical thinking skills
- Applying mathematical reasoning to practical situations
Practice Exercises
- Basic: Solve 5 problems of increasing difficulty using the core concept.
- Intermediate: Apply the concept to word problems with multiple steps.
- Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
- Challenge: Create your own problem that requires this concept plus additional knowledge.
Interview and Exam Tips
- Common question patterns: Identify which exam or interview formats test this topic
- Time management: Practice completing problems within time constraints
- Common traps: Know the typical mistakes examiners set as distractors
- Verification strategy: Develop a quick method to check your answer
Related Topics
- Previous Topic â Build on the foundation laid here
- Next Topic â See how this concept extends to more advanced material
- Practice Problems â Additional exercises with solutions
- Video Explanation â Visual walkthrough of key concepts
Quick Reference Card
| Concept | Formula/Rule | Key Insight | Common Use |
|---|---|---|---|
| Core Definition | See main text | Understand the intuition | Foundation for all applications |
| Key Formula | See main text | Memorize the derivation | Direct problem solving |
| Special Case | See main text | Recognize when it applies | Simplifies complex problems |
| Edge Case | See main text | Know the limitations | Avoids errors |
Further Reading
For students who want to go deeper:
- Standard textbooks on the subject
- Research papers applying this concept
- Online courses with video explanations
- Practice problem collections with detailed solutions