DOWNLOAD FREE GUIDE

The One-Shot Instruction Explained (+Avoid these 3 Pitfalls)

plc tia portal Feb 27, 2026

A PLC one-shot instruction (also called edge detection in TIA Portal) is one of the most important building blocks in PLC programming. Whether you're working with Siemens TIA Portal, P_TRIG, N_TRIG, or Rockwell one-shots, understanding how edge detection works is essential for creating reliable PLC logic.


When it comes to programming PLCs, you’ve got to master the basics first. You don’t start running before you can walk, right? The basics are very important because everything else you build on top, depends on them.  If your foundation is unstable, the big application you try to build on top of it, will eventually come crashing down.

Now, when we're talking about logic, some of the most basic instructions are: normally open/normally closed contacts, the MOVE instruction, compare instructions, output coils, set/reset coils and the one-shot.

In this article, I’m going to explain exactly what a one-shot is, show you where it’s useful (including two practical examples), and how to implement it in your TIA Portal project. And make sure you stick around until the end, because I’ll also cover three common mistakes that can make your one-shots misbehave - and you’ll want to avoid those.

Are you ready to learn about one of TIA Portal's most powerful instructions? Then let's go!

 


WHAT IS A ONESHOT?


Fun fact: “one-shot” isn’t actually a Siemens term. It comes from Rockwell’s RSLogix / Studio 5000, where the instruction is called ONS (One Shot). Siemens actually calls it edge detection, but most PLC programmers still say “one-shot” because everyone understands it.

 

So what does it do?

A one-shot is an instruction that executes for one PLC scan cycle onlywhen the logic before it goes from FALSE to TRUE. Or in Siemens language: it compares the current RLO (Result of Logic Operation, basically everything before the one-shot) with the previous RLO.

 Yes, the official Siemens explanation is very cryptic - I know :-D

 


One-Shot (Edge Detection) – Quick Definition

A PLC one-shot instruction (edge detection) executes logic for exactly one PLC scan cycle when a signal changes state.

  • Positive edge (P_TRIG): FALSE → TRUE

  • Negative edge (N_TRIG): TRUE → FALSE

One-shots are commonly used to:

  • Start sequences

  • Increment counters

  • Trigger alarms

  • Log events

  • Latch commands


 

You can compare it to the flash on your Canon or Sony camera. If you want to make a picture, you press the shutter button, which executes a short light-flash (even if you keep holding the button down).  The flash fires at the exact moment the button changes from FALSE to TRUE.

 

 

A one-shot works the same way: the logic before it goes TRUE (and can stay TRUE forever), and the logic after the one-shot executes just once.

 

So how does a one-shot instruction remembers the TRUE or FALSE state of the logic before it?

Because it uses a memory bit. If you add a one-shot instruction to your logic, you need to add a memory bit to the instruction, else you logic will compile with faults.  This memory bit remembers the previous state.

"Was the signal TRUE or FALSE in the last scan?"

 


POSITIVE VS. NEGATIVE EDGE DETECTION


As mentioned before, the official term for one-shot in Siemens terminology is edge detection.  And in TIA Portal, you get two instructions for this:

  • P_TRIG: the positive edge detection
  • N_TRIG: the negative edge detection

 

 

 

This is how TIA Portal edge detection works in real projects:

  • Positive edge detection triggers (executes the logic for one scan) when the preceding logic goes from FALSE → TRUE.
  • Negative edge detection triggers when the preceding logic goes from TRUE → FALSE.

 

 

Let's see both of them in action using 2 practical examples. 

 


USE CASE: Positive Edge - Starting a Sequence


Imagine you got a machine with a cleaning sequence that is initiated by pressing a "start cleaning" button on the side of the machine. Once the operator presses that button, the sequence should start - even if the operator doesn't release the button immediately. 

Here we use a positive edge detection.  The logic detects the button input going from FALSE to TRUE, and it uses this information to go from sequence "0" to sequence "1", starting the cleaning procedure.

 

 

Now what you don’t want is to stay stuck in sequence 1 just because the operator keeps holding the button down.

That’s exactly what would happen if you don’t use a one-shot. On every scan cycle, the PLC sees the button as TRUE and keeps writing “1” into your sequence step again and again.

But that’s not what we want.

We want the sequence to switch to step 1 only once - at the exact moment the button changes from FALSE to TRUE. After that, it should move on normally, regardless of how long the operator keeps pressing the button.

 


USE CASE: Negative Edge - Counting Parts Leaving a Conveyor


Now picture a production line where a conveyor belt moves products from the beginning of the line to the end, where they're handed over to a packaging line. We want to increment a counter each time a product leaves the conveyor.

So how we do that?

We can install for example a sensor at the end of the conveyor. Whenever a product is in front of the sensor, it gives a TRUE signal. The moment the product leaves, the sensor goes to FALSE. And that's when we want to increase the counter, when the product leaves the detection area of the sensor.

This is a perfect use case for a negative edge detection. It detects the sensor transition going from TRUE → FALSE, and when this event occurs, we increment the product counter by 1.

 

 

Now you might be thinking:

"But Hans, couldn’t we just invert the sensor signal and use a positive edge detection instead?"

Yes, you are absolutely correct! In fact, that's what I usually do about 99% of the time. I will use a positive edge detection (P_TRIG) instead of a negative one (N_TRIG), simply because I find it keeps the logic simple and easier to read.

 

 

At the end of the day, it's really just a personal preference. But if I would have to recommend one instruction, go with the positive edge detection. In most real-world projects, that’s all you’ll ever need, especially considering that some PLC platforms don’t even provide a dedicated negative edge instruction.

 


3 PITFALLS TO AVOID


If you use one-shots correctly, they can seriously level up your programming. They’re perfect for triggering alarms, logging events, latching commands, incrementing counters, or starting sequences whenever needed.

But - and this is important - there are a few mistakes, a couple of pitfalls, you really want to avoid. These are the kind of mistakes that can cause your one-shot instructions to execute at the wrong time, or not execute at all.

Let’s go through them.

 

PITFALL 1 - Using the wrong memory type

When you declare the memory bit for your positive or negative edge detection, it must be declared in the static area of your function block. Never in the temporary area.

 

 

Why?

Because the entire idea of a one-shot is that it compares the current RLO (the state of the logic before the instruction) with the previous cycle’s RLO. That means you need memory that remembers states from one scan to the next.

And what’s the defining characteristic of temporary memory?

That's right: It does not retain its value between scans.

If you use temp memory, your one-shot has no “previous state” to compare with. And without that, edge detection simply doesn’t work.

 

PITFALL 2 - Re-using the same memory bit

Each one-shot needs its own dedicated memory bit.

You should never use that bit somewhere else, especially not in another edge detection.

That memory bit stores the previous state of the logic before the one-shot. If you reuse it in another one-shot instruction, it will overwrite the stored state. And this makes your edge detection unpredictable and useless.

 

 

Create every one-shot with a dedicated memory bit - always.

 

PITFALL 3 - Not running the logic cyclically

Some PLC applications might have function blocks that only execute (conditions in front of the EN of the function block) under certain conditions.  For example a cleaning function block might only execute if the machine state handler is in the cleaning state. 

That approach does NOT work well with one-shots.

A one-shot must run cyclically, every scan. Why? Because it constantly compares the current RLO with the previous scan’s RLO. If the block isn’t executed every cycle, that comparison doesn't work.

 

 

Yes, there are situations where you can execute a function block conditionally and still use one-shots inside it. But that requires extra precautions. For example, you have to make sure that on the first scan when the function block becomes active, you do not evaluate any one-shots yet.

So here's my advice (and this goes especially if you’re just starting out): If you use a one-shot, make sure the logic containing it is executed always, cyclically. This tip alone will save you a lot of troubleshooting time. 

 


So… did you learn something new about one-shot instructions (or edge detection, as we officially call it in TIA Portal)?

I hope you did.

More importantly, I hope this introduction helped you truly understand what a one-shot actually does, when you should use it, and where things can go wrong if you’re not careful.

Once you really get edge detection, all that PLC logic that once seemed confusing suddenly clicks, suddenly makes sense. You’ll be able to create latched commands, log events, trigger alarms, and start sequences - all with confidence and complete peace of mind.

 

Frequently Asked Questions

What is a PLC one-shot instruction?

A PLC one-shot instruction executes logic for one scan cycle only when a signal changes state. In Siemens TIA Portal this is called edge detection and is implemented with P_TRIG and N_TRIG instructions.


What is the difference between P_TRIG and N_TRIG?

  • P_TRIG triggers when a signal goes from FALSE to TRUE.
  • N_TRIG triggers when a signal goes from TRUE to FALSE.

Why is my one-shot not working in TIA Portal?

Common causes include:

  • Using TEMP memory instead of STATIC memory

  • Reusing the same memory bit

  • Logic not running cyclically


 

Until next time, stay structured!

-Hans

 

Download your FREE GUIDE NOW!


5 Simple Steps to Drastically Improve your PLC Program Structure in TIA Portal by Hans Schrynemakers

This is one of my most popular guides, and I’m happy to share it with you for free! Inside, you'll learn about:

  • The #1 Way to Eliminate Messy PLC Programming in Just 5 Easy Steps!
  • The Proven Method for Building Scalable, Future-Ready PLC Applications in TIA Portal.
  • Discover How Modular Design and Structured Data Can Eliminate Costly Errors and Downtime.
  • Break Free from Unstructured Programming - Build Clear, Modular TIA Portal Applications with Confidence.
  • Master the Techniques that Separate Amateur PLC Programmers from Professionals.
DOWNLOAD FREE GUIDE