ONS — One Shot
storageBit
Makes a rung true for exactly one scan on each rising edge of its input. Requires a dedicated storage bit per instance.
Operands
| Name | Type |
|---|---|
storageBit | BOOL |
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.
The rise has to happen while the program is running. If the input is already on when the program starts, ONS does not fire — to a one-shot, an input that was on from the beginning is old news, not a new press. The first pulse comes only after the input goes off and on again. (Prescan sets this up before the first scan.)
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.)
Try one-shots in the Rising Edge exercise — fire for a single scan when a button turns on.
Common Mistakes
- Reusing the same storage bit for multiple
ONSinstructions — eachONSneeds its own storage tag. - Expecting a pulse from an input that is already on at startup — the one-shot only fires on a rise it observes while scanning.
Related
- Counters overview — built-in edge detection, no
ONSneeded - Bit instructions overview