Learn PLCs free
Ladder Logic ElementsBeginnerImportant
5 min read
Updated
Beginner

PLC Rising Edge: R_TRIG, One-Shot & Timing

Rising Edge Detection

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

  1. 1Trend input, stored previous state, edge output and action result together.
  2. 2Hold the input true for several executions and confirm only one action occurs.
  3. 3Return the input false for at least one sampled execution, then test the next rising edge.
  4. 4Test cold and warm restart behavior using the actual controller retain settings.
  5. 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.

PlatformCommon termWhat to verify
IEC 61131-3 / CODESYSR_TRIGCLK is the Boolean input; Q is true when CLK is true and was false at the previous call.
Siemens STEP 7R_TRIG, P contact, P_TRIGSeveral positive-edge forms exist. R_TRIG stores prior CLK state in its instance and Q lasts one cycle.
Rockwell Studio 5000ONS, OSR, OSRIONS enables the remaining rung for one scan; OSR/OSRI write a one-scan output. Each requires dedicated state.
Manual Structured TextCurrent AND NOT PreviousCalculate the pulse before copying Current into Previous.

Rising-edge product counter

The edge state belongs to PartSensor. Holding PartSensor true keeps CountPulse false after the first detected execution.

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 / phaseExecution 1Execution 2Execution 3Execution 4Execution 5Execution 6
Input CLK001110
Previous CLK000111
R_TRIG.Q001000
Counter change+1
Deterministic truth trace for Q := CLK AND NOT PreviousCLK, followed by PreviousCLK := CLK.

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

SymptomLikely causeCheck next
Counter increases every scan while input is highThe level signal was used directly instead of the edge outputDrive the action from R_TRIG.Q, ONS output flow or the platform equivalent.
First edge after startup is missing or unexpectedPrevious-state initialization differs from the assumptionTest cold start, warm start and online edit on the target controller.
Occasional real pulses are missedInput pulse is shorter than the complete sampling pathCompare pulse width with module update, task period and phase; use hardware capture if required.
Two inputs trigger each otherThey share one edge instance or storage bitGive 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.

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.

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

Difficulty
Beginner
Tier
Important

About Ladder Logic Elements

Contacts, coils, timers, counters, and ladder diagram components

Total Terms:70
Difficulty:Beginner to Intermediate

Free PLC simulator

Stop reading, start doing

Write ladder logic in your browser, hit Run, and watch machine scenarios react. A 12-lesson curriculum across 8 PLC dialects — free account, no credit card.

Practice PLCs free →