Skip to main content

ONS — One Shot

storageBit

[ONS]

Makes a rung true for exactly one scan on each rising edge of its input. Requires a dedicated storage bit per instance.

Operands

NameType
storageBitBOOL

How It Works

ONS watches the rung condition that feeds it. The first scan the condition is true, ONS also passes true. On every subsequent scan — while the input stays true — ONS passes false. When the input drops back to false and then goes true again, ONS fires once more.

Input _____|‾‾‾‾‾‾‾‾|________|‾‾‾‾‾‾|___
ONS _____|‾|_______________|‾|________

Example — Counting Button Presses With ADD

Without ONS, ADD runs every scan the button is held, so Count races up many times per press:

XIC(Button)ADD(Count,1,Count)

Add ONS so the ADD rung is true for exactly one scan per press:

XIC(Button)ONS(ButtonPulse)ADD(Count,1,Count)

(A CTU would do the same job with built-in edge detection — no ONS needed. Reach for ONS when the instruction you're driving has no internal edge detection of its own.)

Common Mistakes

  • Reusing the same storage bit for multiple ONS instructions — each ONS needs its own storage tag.