PLC Simulator
fundamentals
ladder logic

One-Shots & Edge Detection in PLCs: ONS, OSR and R_TRIG

By PLC Simulation Software8 min read

One-Shots & Edge Detection in PLCs

A one-shot fires for exactly one PLC scan when an input changes state, instead of staying on the whole time the input is true. Rising-edge detection (IEC R_TRIG, Allen-Bradley ONS/OSR, the Siemens P contact) gives you a single-scan pulse the moment a signal goes from 0 to 1; falling-edge detection (F_TRIG, the N contact) does the same on the 1-to-0 transition. That one-scan pulse is what you reach for whenever you need to react to the event of something happening — not the fact that it is still happening.

This guide shows what an edge actually is, how the instructions behave scan by scan, the names every dialect uses, and the classic bugs that make one-shots misbehave.

One-shot and edge detection in PLCs explained with timing diagrams and ladder logic

Level vs edge: the core idea

Most contacts you write are level-triggered. An XIC / --| |-- contact is true for as long as the bit behind it is true. If you press and hold a button, the rung stays energised the entire time you hold it.

An edge-triggered instruction does not care that the bit is high — it cares about the moment it became high. It compares the bit's value this scan with its value last scan. If it was 0 last scan and is 1 this scan, that is a rising edge, and the instruction produces a pulse that is true for one scan only, then drops automatically even though the input is still held.

Level-triggered versus edge-triggered logic in a PLC compared side by side

That single-scan behaviour is the whole point. It turns a continuous signal into a discrete event you can count, latch, or step on exactly once.

What a rising edge looks like

Here is the behaviour that surprises people first: the input can be held high for a hundred scans, but the edge-detect output Q is only true for the first of them.

R_TRIG rising edge timing diagram showing a single-scan pulse when the input goes high

Read the diagram: CLK (the input) goes high and stays high, but Q is a one-scan blip on each 0-to-1 transition. To get another pulse the input must go low and high again. A F_TRIG is the mirror image — its pulse appears on the 1-to-0 transition instead.

A one-shot driving a coil

The classic rung puts an ONS (one-shot) between a contact and a coil. The button can be held down forever; the coil it drives only pulses once per press.

One-shot ONS instruction in a ladder rung driving a coil for a single scan

This is how you make a "press to toggle" or "press to start one cycle" button. Without the one-shot, holding the button would re-trigger the action every scan — hundreds of times a second.

The killer use case: incrementing a counter

Edge detection and counters go together. A CTU count-up instruction adds 1 on every rising edge of its enable. But if you wire a plain held contact straight into a counter, the counter behaviour already edge-detects internally on most platforms — the trap is when you build your own count logic with an ADD. Then you must put a one-shot in front, or the value races up by one per scan.

Edge pulse from a one-shot incrementing a PLC counter by exactly one per event

One press, one increment. That is only true because the rung pulses for a single scan.

The instruction names by dialect

The concept is identical everywhere; the spelling is not. Learn the IEC function blocks and you can map the rest.

Comparison table of R_TRIG and F_TRIG versus ONS OSR and P N edge contacts across IEC Allen-Bradley and Siemens

A few notes worth keeping in your head:

  • R_TRIG / F_TRIG (IEC 61131-3) are function blocks with a CLK input and a Q output, each carrying its own internal memory bit.
  • ONS (Allen-Bradley) is a single instruction that needs a dedicated storage bit; OSR/OSF are the rising/falling output-style one-shots in newer Rockwell processors.
  • P and N contacts (Siemens, also IEC LD) detect edges inline on a contact and need a memory bit address written underneath them.

Every one of these stores a "previous state" bit somewhere — which is exactly where the bugs come from.

When do you actually need an edge?

Not every rung needs a one-shot. Use this quick check before you add one.

Flowchart for deciding when you need an edge-triggered one-shot versus a level signal in a PLC

The rule of thumb: if you are reacting to an event (a button press, a part arriving, an alarm appearing) you want an edge. If you are reacting to a condition (a guard is open, a tank is full, a motor is running) you want the level.

Edge-detection pitfalls

One-shots cause some of the most confusing bugs in PLC code precisely because they "work" most of the time and fail in edge cases.

Checklist of common one-shot and edge-detection pitfalls in PLC programming

The single worst one is reusing the same one-shot storage bit in two places. The two instructions fight over the same "previous state" memory, and both fire unpredictably. Every ONS and every P/N contact needs its own unique memory bit. The next most common is putting the one-shot on the wrong side of a branch so it edge-detects something you did not intend — almost always traceable to the scan cycle reading the storage bit at a different point than you pictured.

Falling edges matter too

Do not forget the other direction. A F_TRIG or N contact is how you react to something stopping: latch a fault when a "machine running" bit drops, capture the final count when a guard opens, or trigger a cleanup routine the instant a cycle ends. It is the same single-scan pulse, just on the 1-to-0 transition.

Practice edge detection in your browser

The fastest way to make one-shots click is to wire one up and single-step the scan so you can see the pulse appear for one scan and vanish. You can do exactly that in the free browser PLC simulator — drop an R_TRIG, hold the input, and watch Q fire once. Switch the ladder logic editor between IEC, Allen-Bradley and Siemens dialects to see R_TRIG, ONS and the P contact side by side, and keep the TON / R_TRIG / TOF dialect cheat sheet open while you do.

FAQ

What is a one-shot in ladder logic? A one-shot is an instruction that produces a true output for exactly one PLC scan when its input transitions from false to true, then turns itself off even if the input stays true. It converts a held signal into a single momentary pulse.

What is the difference between ONS and OSR? Both are Allen-Bradley one-shots. ONS is an input-style instruction placed in series before the output it pulses. OSR (and its falling-edge sibling OSF) is an output-style instruction that sets a separate output bit for one scan on the rising edge. They behave the same; the difference is where they sit on the rung.

What does R_TRIG do in a PLC? R_TRIG is the IEC 61131-3 rising-edge function block. Its Q output is true for one scan each time the CLK input goes from 0 to 1. F_TRIG is the falling-edge equivalent that pulses on the 1-to-0 transition.

Why does my one-shot fire twice or not at all? Almost always because two instructions share the same storage / memory bit, or the bit is read and written at different points in the scan than you expected. Give every one-shot its own unique memory bit and check where in the scan the bit is updated.

When should I use an edge instead of a level contact? Use an edge when you are reacting to an event — a button press, a part arriving, an alarm appearing — and you want to act exactly once. Use a level contact when you are reacting to an ongoing condition that should keep the rung energised the whole time it is true.

Share:X / TwitterLinkedIn

Practice this yourself in the simulator

3 scenarios free — no install, no credit card. Write real ladder logic against a live machine model.

Try the simulator free →

Related articles

communications
modbus

Modbus TCP vs Modbus RTU: Same Protocol, Different Cables

Modbus TCP vs Modbus RTU compared: both use the same register model and function codes, but RTU runs on serial RS-485 and TCP runs on Ethernet. This post explains the differences, the MBAP header, how to choose, and how to troubleshoot each variant.

June 13, 2026 · 9 min read
communications
modbus

Modbus vs CAN Bus (CANopen): Industrial Protocol vs Embedded Network

Modbus and CAN bus target different environments. Modbus RTU/TCP is the open industrial register protocol for PLCs and process instruments. CAN bus with CANopen profiles connects embedded motion and drive systems. This post explains the architecture, frame format, and when each protocol fits.

June 13, 2026 · 9 min read
communications
modbus

Modbus vs DNP3: Process Protocol vs Utility Outstation Protocol

Modbus and DNP3 are both fieldbus protocols used to read RTUs and outstations, but DNP3 was purpose-built for utility SCADA — substations, water treatment, and pipelines — with built-in event reporting, data integrity, and time stamping that Modbus lacks. This post explains the differences and when each protocol is the correct choice.

June 13, 2026 · 9 min read