LadderLogicOnline

Learn › Instructions

ONS, OSR and OSF: One-shot instructions

A one-shot turns a signal that stays on for a while (a held button, a box sitting in front of a sensor) into a pulse that lasts exactly one scan. It's how you make something happen once per press instead of on every scan.

Why you need a one-shot

A PLC solves your whole program over and over, many times a second (see How a PLC scan cycle works). In the Playground the program scans once per screen refresh, usually around 60 times a second. If you hold a push button for half a second, every rung that reads it sees it as true for roughly 30 scans in a row.

For coils that's exactly what you want: the output is on while the button is held. For instructions that do something each scan they're true, it's a problem. An ADD that adds 1 to a total would add about 30 for one press. A MOV that copies a reading would keep copying it. A one-shot fixes this by passing power for the single scan when its rung goes from false to true, and then going false again even though the button is still held.

Counters (CTU and CTD) already have this built in: they only count on the false-to-true transition, using their CU and CD bits to remember the last state. You don't need a one-shot in front of a counter. You do need one in front of math, moves and anything you want to trigger once.

ONS: One Shot

ONS sits in the middle of a rung, like a contact. It takes one tag, a BOOL storage bit, which it uses to remember whether its rung-in was true on the previous scan. Each scan:

 |   AddBtn      Add_ONS                        |
 |----] [------[ONS]------[ADD  A Total  B 1  Dest Total]--|
Each press of AddBtn adds exactly 1 to Total, however long it's held.

Everything to the right of the ONS sees one true scan per press. Everything to its left behaves normally.

Give every one-shot its own storage bit, and don't use that bit anywhere else in the program. If two one-shots share a storage bit, or another rung writes to it, they'll fight over it and miss or double up pulses.

OSR: One Shot Rising

OSR is an output instruction, so it goes in the last column of a rung. It has two operands, both BOOL tags: a Storage Bit and an Output Bit. When its rung goes from false to true, it turns the Output Bit on for one scan. On every other scan the Output Bit is off.

 |   PE1                                                 |
 |----] [---------------------[OSR  Stor PE1_Mem  Out PE1_Edge]--|
 |                                                       |
 |   PE1_Edge                                            |
 |----] [---------------------[ADD  A Boxes  B 1  Dest Boxes]----|
OSR makes a one-scan pulse bit you can use on other rungs.

The difference from ONS is where the pulse ends up. ONS passes power along its own rung; OSR puts the pulse in a bit that any rung can read. That's handy when several rungs need the same edge, or when you want to name it (Start_Pressed reads better than another copy of the button logic).

Remember rung order: the Output Bit is set when the OSR rung is solved, so rungs below it see the pulse in the same scan. Rungs above it see it on the next scan, by which time it's already off. Put rungs that read the pulse after the OSR.

OSF: One Shot Falling

OSF works the same way as OSR, with a Storage Bit and an Output Bit, but it fires on the opposite edge: the Output Bit is on for one scan when the rung goes from true to false.

Falling edges are useful when something should happen when a signal ends. A box has fully passed a photo eye when the eye's tag turns off. A push button has been released. A machine cycle has finished when its running bit drops.

 |   PE1                                                   |
 |----] [---------------------[OSF  Stor PE1_FMem  Out Box_Cleared]--|
Box_Cleared is on for one scan as the back of each box leaves the beam.

Which one to use

InstructionWhere it goesOperandsFires when
ONSMiddle of the rungStorage bitRung-in goes false → true; passes power for one scan
OSRLast columnStorage Bit, Output BitRung goes false → true; Output Bit on for one scan
OSFLast columnStorage Bit, Output BitRung goes true → false; Output Bit on for one scan

Use ONS when the pulse only matters to that one rung. Use OSR or OSF when you want a named pulse bit, or when you need the falling edge.

Try it in the Playground

  1. Open the Playground. In the Tags panel add a DINT tag called Total and a BOOL called Add_ONS.
  2. Add a rung: XIC Start, then an ADD in the last column with Source A Total, Source B 1 and Dest Total.
  3. Press Run, then press and hold the green Start button for a second. Watch Total in the Tags panel shoot up by dozens.
  4. Stop, select the space between the XIC and the ADD, and add an ONS with the tag Add_ONS. Run again: now each press adds exactly 1.

Common mistakes