← Resources
Instructions·5 min read·

One shots: doing something exactly once

The instruction that turns a held button into a single event, and the three places it is genuinely required.

Short answer

A one shot, also written ONS or OSR, passes rung power for exactly one scan on each false-to-true transition of its input. It exists because most inputs are levels held for hundreds of scans, while most actions should happen once. It remembers the previous state of its own rung, which is why two one shots on the same tag behave independently.

A one shot fires once per transitionInputONSheld for five scans, fires on one

A one shot passes rung power for a single scan each time its input goes from false to true. Hold the input for a thousand scans and it fires once.

Why it is needed so often

Inputs are levels. A button is held for a few hundred milliseconds, which at a 10 ms scan is dozens of scans. Actions are usually events. Incrementing a count, capturing a reading, advancing a step: all of these should happen once per press.

Without a one shot, a single press increments a counter forty times and nobody can work out why.

Each instance has its own memory

A one shot remembers the previous state of its own rung, not of the tag it reads. Two one shots watching the same bit in different rungs behave independently, which is what you want and occasionally surprising.

This is also why a one shot cannot be shared. Copying a rung that contains one and forgetting to give the copy its own storage bit produces two instructions fighting over one memory location.

The three places it is genuinely required

  • Counting. Any count driven by a level rather than an edge.
  • Capture. Latching a measurement at the moment a trigger occurs, before it changes.
  • Sequencing. Advancing a step exactly once when a condition becomes true, rather than racing through every step in a single scan.

Common questions

When do I need a one shot?
Whenever an action must happen once per event rather than continuously: incrementing a counter, capturing a value at the moment of a trigger, starting a sequence, or sending a message. Without one, a button held for one second at a 10 ms scan fires the action a hundred times.
What is the Structured Text equivalent of a one shot?
An R_TRIG function block for a rising edge or F_TRIG for a falling edge, each needing its own instance variable. There is no expression for 'was false last scan', so the state has to be stored somewhere, which is exactly what the instance provides.

Keep reading