PLC Simulator
Edge detection

ONSOne Shot

ONS (One Shot) is an edge-detection instruction: when the rung entering it transitions from false to true, it passes continuity for exactly one program scan, then blocks until the rung goes false and true again.

Join 1900+ learners practicing PLC programming

How it works

What ONS does during the scan

Ladder logic is level-based by default: a rung that is true stays true, scan after scan, for as long as its conditions hold. Plenty of real actions must happen once per event instead — add 1 to a total, index a sequence step, capture a value the instant a sensor trips. The ONS is the bridge: it remembers, in a storage bit you assign, what the rung-in condition was on the previous scan, and it only conducts on the scan where that condition changes from false to true. Hold the button down for ten seconds at a 10 ms scan and the logic downstream of the ONS still executes exactly once, not a thousand times.

The storage bit is not decoration — it is the instruction’s entire memory, and it must be unique. Give two ONS instructions the same storage bit and they corrupt each other’s edge history, producing pulses that vanish or double depending on rung order. The bit should also never be examined, forced, or written anywhere else in the program.

Allen-Bradley actually offers three one-shot flavours, and the distinction shows up in searches and interviews constantly. ONS is an input instruction: it sits in the middle of the rung and gates continuity. OSR (One Shot Rising) and OSF (One Shot Falling) are output instructions from the SLC-500 lineage: they sit at the end of a rung and pulse a separate output bit for one scan on the rising or falling edge of the rung. In Logix ladder you will mostly write ONS; in older SLC programs and in conversions you will meet OSR everywhere.

The IEC 61131-3 world does the same job with the R_TRIG and F_TRIG function blocks (rising/falling trigger) — each instance carries its own memory, so there is no shared-storage-bit trap — and Siemens ladder programmers know the same idea as the P and N edge contacts. Mitsubishi uses PLS (pulse on rising edge) and PLF (pulse on falling edge). The concept is universal; only the packaging changes.

ONS one-shot instruction highlighted on a ladder rung — a Part_Sensor contact feeding an ONS with its storage bit so the Count_Pulse coil fires for exactly one scanA ladder rung between power rails: an XIC contact tagged Part_Sensor feeds the highlighted ONS one-shot block with storage bit ONS_Store, ending in an OTE coil tagged Count_Pulse. The ONS passes rung continuity for a single scan on the false-to-true transition, no matter how long the sensor stays on.L1L2Part_SensorXICONSONS_StoreCount_PulseOTEtrue for 1 scan
The ONS (highlighted) sits between the sensor contact and the output: Part_Sensor may stay on for thousands of scans, but Count_Pulse fires for exactly one.
ONS one-shot timing diagram — the input stays on for many scans but the one-shot output is true for exactly one scan on the rising edgeTwo timing lanes. Lane 1: the input signal goes high and stays high for a long period, then drops and pulses again. Lane 2: the one-shot output produces a single narrow one-scan pulse at each rising edge of the input, staying low the rest of the time.rising-edge pulse →InputONS out1 scanholding the input ON does not re-fire it
ONS timing: the input goes high and stays high, but the one-shot output is a single-scan pulse on each rising edge — holding the input on does not re-fire it.

Across vendors

ONS in Allen-Bradley, Siemens, IEC 61131-3 and Mitsubishi

PlatformName / syntaxNotes
Allen-Bradley (Studio 5000 / RSLogix)ONS / OSR / OSFONS storage_bit is an input (mid-rung) instruction. OSR/OSF are output instructions that pulse an output bit on rising/falling edges — common in SLC-500 code.
IEC 61131-3 (CODESYS, OpenPLC)R_TRIG / F_TRIGStandard function blocks: trig(CLK := Sensor); IF trig.Q THEN … Each instance holds its own edge memory.
Siemens (TIA Portal)P / N contactsThe -|P|- and -|N|- edge contacts in LAD (each needs a unique memory bit, same trap as ONS), plus R_TRIG/F_TRIG blocks in SCL.
Mitsubishi (GX Works)PLS / PLFPLS M0 sets M0 for one scan on the rising edge of the rung; PLF on the falling edge.

Searches for "one shot rising" usually mean OSR by name, but in modern Studio 5000 ladder the idiomatic instruction is ONS mid-rung. Functionally all of these detect the same false-to-true transition.

In practice

Worked ONS examples

Example 1 — count parts, not scans

| Part_Sensor    ONS_1                    CTU Parts_Count |
|-----] [--------[ONS]-----------------[ PRE 100       ]-|

In Logix the CTU itself is edge-sensitive on its rung-in condition, but this pattern matters the moment any other instruction sits on the rung or the counter is replaced by an ADD: the ONS guarantees the downstream logic sees exactly one true scan per part. Without edge awareness, an ADD here would increment on every scan the sensor is blocked — a 10 ms scan turns one slow-moving box into hundreds of counts.

Example 2 — toggle an output with one button

| Toggle_PB    ONS_2      Lamp                Lamp_Off_Req |
|----] [-------[ONS]------] [--------------------( )------|

| Toggle_PB    ONS_3      Lamp                Lamp_On_Req  |
|----] [-------[ONS]------]/[--------------------( )------|

A push-on/push-off button is impossible without edge detection: while the button is held, a level-based rung would flip the lamp on and off every scan, and the final state on release would be luck. The one-shots make each press a single event; the Lamp contact steers that event to either the on-request or off-request rung.

Note the two separate storage bits (ONS_2, ONS_3). Sharing one bit between the rungs is the classic mistake — the first rung’s ONS would consume the edge and the second rung would never fire.

Gotchas

Common ONS mistakes

  • Reusing a storage bit across two ONS instructions

    Each ONS needs a dedicated, unique storage bit. Shared bits corrupt the edge memory: one instruction records "already seen true" and the other never pulses. Symptoms are maddeningly rung-order dependent.

  • Placing the ONS before the conditions instead of after

    ONS detects the transition of everything to its LEFT. Put it directly after the button contact but before qualifier contacts and the pulse can be blocked by a qualifier; put it after all conditions and adding a new series condition changes when edges are detected. Decide which event you are detecting and place the ONS so exactly that expression feeds it.

  • Expecting a one-shot to fire on the first scan after power-up

    Storage bits that retain their value through a power cycle can suppress (or create) an edge on the first scan, depending on the pre-outage state. If first-scan behaviour matters, initialize the storage bit explicitly.

  • Using ONS where the platform already gives you edges

    Logix CTU/CTD increment on the rung’s false-to-true transition by themselves — an ONS in front of a plain counter rung is harmless but redundant. Know which instructions are already edge-sensitive before sprinkling one-shots.

  • Debugging with the storage bit

    Forcing or toggling the storage bit from the tag monitor rewrites the instruction’s memory and fabricates or eats edges. Watch the pulsed output bit instead.

Run ONS live — no install

Drop the instruction on a rung in the browser simulator, toggle the inputs, and watch the rung state, accumulator values and outputs update scan by scan.

Questions

ONS — frequently asked

What does the ONS instruction do in a PLC?

ONS (One Shot) passes rung continuity for exactly one program scan when the rung entering it transitions from false to true. It uses a dedicated storage bit to remember the previous scan’s rung state; while the input stays true, the ONS blocks until the rung has gone false and true again.

What is the difference between ONS, OSR and OSF?

ONS is an input (mid-rung) instruction that gates continuity on a rising edge. OSR (One Shot Rising) and OSF (One Shot Falling) are output instructions — placed at the end of a rung, they pulse a separate output bit for one scan on the rung’s rising or falling edge respectively. OSR/OSF dominate older SLC-500 programs; ONS is the usual choice in Studio 5000.

What is one shot rising in ladder logic?

A one shot rising detects the moment a condition changes from false to true and produces a single-scan pulse. In Allen-Bradley it is the OSR instruction (or ONS mid-rung); in IEC 61131-3 it is the R_TRIG function block; Siemens ladder uses the -|P|- contact and Mitsubishi uses PLS.

Why does my one-shot fire twice or not at all?

Almost always a storage-bit problem: two ONS/OSR instructions sharing one storage bit, the bit being written elsewhere in the program, or the bit being forced from a tag monitor. Give every edge instruction its own bit that appears nowhere else, and the pulses become deterministic.