PLC Rising Edge: R_TRIG, One-Shot & Timing
Quick answer
A PLC rising edge occurs when a Boolean changes from false to true. R_TRIG or a one-shot compares the current input with stored previous state and makes its output true for one program execution, even if the input stays true for many scans.
Key Takeaways
- A PLC rising edge occurs when a Boolean changes from false to true. R_TRIG or a one-shot compares the current input with...
- Beginner-level topic in Ladder Logic Elements
- Commonly used in: Count one product when a sensor first turns on, Start a sequence once from a maintained command
- Related to: Falling Edge (Negative Edge), One Shot, TON (Timer On-Delay)
Detailed Definition
Rising-edge detection converts a state change into a one-execution pulse. The detector needs memory of the previous call: Q is true only when CLK is true now and was false previously. On later executions with CLK still true, Q returns false.
“Exactly one scan” really means one execution of the task or block that calls the detector. A 10 ms periodic task produces a pulse that exists for one 10 ms task interval in that task’s logic, while another task may observe it differently. The input must also be sampled long enough to be seen; an edge detector cannot recover a pulse the task never sampled.
Evidence and scope
The one-execution pulse and instance-memory behavior were checked against current CODESYS Standard 3.5.22.0, Siemens STEP 7 V21 and Rockwell Studio 5000 V38.01 documentation. First-call initialization and task scheduling remain runtime-specific.
Technical review:
Critical behavior
- The detector must execute while the signal is false before it can reliably recognize the next false-to-true transition.
- Q is true for one call of the detector, not for a universal wall-clock duration.
- A pulse shorter than the input-update and task-sampling path can be missed before edge logic sees it.
- Each signal normally needs its own detector instance or storage bit; sharing state corrupts edge history.
- Calling the same detector instance conditionally can leave stale previous-state memory and create a delayed or unexpected pulse.
Verification checklist
- 1Trend input, stored previous state, edge output and action result together.
- 2Hold the input true for several executions and confirm only one action occurs.
- 3Return the input false for at least one sampled execution, then test the next rising edge.
- 4Test cold and warm restart behavior using the actual controller retain settings.
- 5Measure the shortest physical pulse and use a high-speed or latched input when software sampling is insufficient.
IEC and vendor terminology
Similar-looking instructions do not always have identical execution, initialization or storage behavior.
| Platform | Common term | What to verify |
|---|---|---|
| IEC 61131-3 / CODESYS | R_TRIG | CLK is the Boolean input; Q is true when CLK is true and was false at the previous call. |
| Siemens STEP 7 | R_TRIG, P contact, P_TRIG | Several positive-edge forms exist. R_TRIG stores prior CLK state in its instance and Q lasts one cycle. |
| Rockwell Studio 5000 | ONS, OSR, OSRI | ONS enables the remaining rung for one scan; OSR/OSRI write a one-scan output. Each requires dedicated state. |
| Manual Structured Text | Current AND NOT Previous | Calculate the pulse before copying Current into Previous. |
Rising-edge product counter
PartSensor EdgeMemory CountPulse
|---------| |----------------[ ONS ]-------------------( )---------|
|---------| | CountPulse-------------------------[ CTU PartCount ]--|Rising-edge timing by task execution
The pulse is produced only at an execution where current state is true and saved previous state is false.
| State / phase | Execution 1 | Execution 2 | Execution 3 | Execution 4 | Execution 5 | Execution 6 |
|---|---|---|---|---|---|---|
| Input CLK | 0 | 0 | 1 | 1 | 1 | 0 |
| Previous CLK | 0 | 0 | 0 | 1 | 1 | 1 |
| R_TRIG.Q | 0 | 0 | 1 | 0 | 0 | 0 |
| Counter change | — | — | +1 | — | — | — |
Working LD and ST example
Count one part per false-to-true transition
Use one named R_TRIG instance so a maintained sensor does not increment the count on every execution.
Ladder Diagram
|--[ PartSensor ]--[ one-shot: PartSensorEdge ]--[ ADD 1 PartCount ]--|Structured Text
PartSensorEdge(CLK := PartSensor);
IF PartSensorEdge.Q THEN
PartCount := PartCount + 1;
END_IF;Expected result: PartCount increments once at the first sampled false-to-true transition. It does not increment again until PartSensor has been sampled false and then true.
Failure modes and diagnostic checks
| Symptom | Likely cause | Check next |
|---|---|---|
| Counter increases every scan while input is high | The level signal was used directly instead of the edge output | Drive the action from R_TRIG.Q, ONS output flow or the platform equivalent. |
| First edge after startup is missing or unexpected | Previous-state initialization differs from the assumption | Test cold start, warm start and online edit on the target controller. |
| Occasional real pulses are missed | Input pulse is shorter than the complete sampling path | Compare pulse width with module update, task period and phase; use hardware capture if required. |
| Two inputs trigger each other | They share one edge instance or storage bit | Give each independent signal dedicated edge memory. |
Current primary and technical sources
These sources support the behavior summarized on this page. The project's controller, firmware and IDE help remain authoritative for implementation.
- R_TRIG Standard function block
CODESYS Development — Current Standard library declaration and ST call
- R_TRIG positive-edge detection, STEP 7 V21
Siemens — Instance memory and one-cycle Q behavior
- Bit instructions, Studio 5000 V38.01
Rockwell Automation — ONS, OSR, OSRI and related bit-instruction purposes
- IEC 61131-3:2025 publication record
IEC — Current programming-language standard publication
Continue with the practical guide
Common Questions
What is Rising Edge (Positive Edge)?
A PLC rising edge occurs when a Boolean changes from false to true. R_TRIG or a one-shot compares the current input with stored previous state and makes its output true for one program execution, even if the input stays true for many scans.
When should I use Rising Edge (Positive Edge)?
Rising Edge (Positive Edge) is particularly useful in scenarios such as Count one product when a sensor first turns on and Start a sequence once from a maintained command. Consider implementing it when you need reliable, efficient solutions for these types of applications.
What should I verify before using Rising Edge (Positive Edge)?
Trend input, stored previous state, edge output and action result together. Hold the input true for several executions and confirm only one action occurs. Return the input false for at least one sampled execution, then test the next rising edge. Test cold and warm restart behavior using the actual controller retain settings. Measure the shortest physical pulse and use a high-speed or latched input when software sampling is insufficient.
What are related concepts I should learn?
To fully understand Rising Edge (Positive Edge), you should also familiarize yourself with Falling Edge (Negative Edge), One Shot, and TON (Timer On-Delay). These concepts work together in industrial automation systems.
Continue Learning
Ready to deepen your understanding of Rising Edge (Positive Edge)? Here are some recommended resources:
Was this helpful?
Let us know if this glossary term helped you understand Rising Edge (Positive Edge) better.
Your feedback helps us improve our glossary and create better content for the PLC programming community.
Quick Info
- Category
- Ladder Logic Elements
- Difficulty
- Beginner
- Tier
- Important
About Ladder Logic Elements
Contacts, coils, timers, counters, and ladder diagram components