Meridian Works
ENTR
Open the simulator
Taking Over

Lesson 2

Seal-in Circuits, Set/Reset Coils and Edge Detection in Ladder Logic

Why an output forgets, how a seal-in or a set/reset pair makes it stay, which rung wins, what survives a power cut, and rising and falling edges.

From Usta's field manual in Meridian Works, a story-driven PLC course: chapter 2, “Memory & Moments”. How a signal is made to stay, which rung wins when two disagree, and the difference between a state and an instant.

Why an output forgets

The busbars in this room are heavy copper, and they have been cold for seven years. Before we energise them, we are going to talk about memory. You learned something in the gatehouse that you only half understand yet.

A coil is not a switch. Nobody sets it once and leaves it.

Every scan, a hundred times a second, the processor calculates the coil from scratch. It reads the inputs, runs the rung from left to right, and sets the coil to whatever power flow reached it. The coil's previous value plays no part.

So an output does not remember. There is nothing inside it to remember with.

This means that in a PLC program memory is not a property of the output. You build memory on purpose. If you did not build it, it is not there. Many faults in this trade start with somebody assuming the opposite. They press a button, the machine runs only while their finger is on it, and they are surprised.

You have actually built memory once already. In the gatehouse you wired the motor's own contact in parallel with the start button, and the rung began to hold itself. This is called a seal-in. The output feeds its own condition. It is memory built from a loop.

This chapter covers four things: two ways to make a bit stay, which one wins when they disagree, what is left after a power cut, and the opposite problem. A signal that lasts too long when the plant wants a moment.

Seal-in, Set and Reset

There are two ways to make a bit stay. Learn both, because you will meet both on site.

Seal-in. One rung and one coil. The start condition is wired in parallel with the output's own contact. Every reason to stop follows in series. Its advantage is that it is readable. Look at the rung and you see every condition that runs the motor, because there is nowhere else to look.

Set and Reset. Two separate coils. They do not behave like an ordinary coil. An ordinary coil writes both values: TRUE when power arrives, FALSE when it does not. A Set coil (S) writes only TRUE, and only when power reaches it. If no power reaches it, it writes nothing and the bit stays as it is. A Reset coil (R) is the opposite: it writes FALSE when power arrives and nothing otherwise.

The memory lives in that "writes nothing". The bit keeps its value because in most scans nobody writes to it.

In Rockwell these two coils are called OTL (latch) and OTU (unlatch). They behave the same.

Start_PB Busbar Stop_PB Busbar Start_PB Stop_PB S R Busbar Busbar 1 1 2

Look at the stop button in the two drawings. In the field it is the same NC device, and it reads TRUE while nobody presses it. In the seal-in it is asked with an NO contact, because there it means "you may keep running". On the reset rung it is asked with an NC contact, because there it means "stop now". Same wire, opposite question.

Which should you choose? If the whole condition fits comfortably on one rung, use a seal-in. Most motor starters are like this. If the start and stop reasons are far apart in the program, use Set/Reset. For example, a bit set by a step at the top of the program and cleared by the fault block at the bottom.

Set/Reset has a cost. There is no longer one rung to read, and the condition is spread across the program. Before you touch a bit that has a Set coil, open the cross reference and find every place that writes it. Every serious editor has that button. Use it.

Dominance: the last write wins

This is the most important page in the chapter. Read it twice.

If you put a Set and a Reset coil on the same bit, one day both rungs will be energised in the same scan. Not often, but it will happen. A start button's contact can stick. A wire's insulation can wear and touch 24 V. An operator can lean on one button while pressing the other. The processor asks the question a hundred times a second. Sooner or later both conditions are true in the same scan.

What happens then? The bit takes the value of the coil that ran last in the scan.

The processor runs rungs from top to bottom. If the Set rung is on top, it writes TRUE first. The Reset rung right below writes FALSE over it. The bit ends the scan FALSE. Swap the two rungs and the result changes. Remember chapter 1: the output sees only the value at the end of the scan. The writes in between are invisible. No meter can see them.

Start_PB Stop_PB Stop_PB Start_PB S R R S Busbar Busbar Busbar Busbar 1 2 1 2 = 0 = 1 Start_PB = 1 Stop_PB = 0 Start_PB = 1 Stop_PB = 0

So the order of the rungs decides. Not the names of the buttons, and not what you meant.

Put the Reset rung below the Set rung. Let stop dominate.

Write this rule at the top of the project. Do not let anybody talk you out of it. A machine that starts when you did not want it to is expensive. A machine that does not stop when you want it to is unacceptable. If you must write start-dominant logic, you should be able to explain why to another person out loud before you download it.

The same rule has a quiet version: two ordinary coils writing the same bit. In that case the upper coil does nothing, because the lower one writes over it every scan. No warning and no error appear. Sometimes an experienced person does this on purpose. Usually it shows that two people changed the same program and neither looked at the cross reference.

Give every signal a single writer.

What survives a power cut

A bit you set at four in the afternoon: is it still set the next morning, after the maintenance crew dropped the main breaker in the evening?

That depends on where the bit is kept. CPU memory comes in two kinds.

Non-retentive memory is cleared when power comes back. Every latch, every count and every flag starts from zero. It is as if the program had just been downloaded.

Retentive memory is kept through a power cut and comes back the way you left it.

Here the two platforms have opposite defaults, and knowing this matters:

  • In Siemens memory is not retentive by default. You mark the variables you want kept. Data blocks have a Retain column for this. In the M area you choose which bytes are kept.
  • In Rockwell tags keep their values by default. If something must be cleared at power-up, you do it in the program. The first-scan bit is used for this.

The rule is the same on both platforms: a motor's run command should almost never be retentive. Picture it: power is lost, half the crew climbs into the machine to find out why, power returns, and the conveyor starts by itself. Because it remembers that it was running. After every power cut the plant should come back quiet and wait for somebody to press START. This is the same thinking that wires stop buttons NC.

The data that should be retentive: the shift's part count, the running hours collected for maintenance, the recipe number the operator chose, the record of which alarm tripped first. In other words, information somebody would have to type in again if it were lost.

The first-scan bit. Something interesting happens in the first scan after power-up. A button that is already being held looks like a fresh press. Nothing remembers that it was already pressed. To prevent this, both platforms give you a bit. It is TRUE in the first scan after start-up and FALSE in every scan after that.

  • In Siemens the bit is called FirstScan. It appears when you enable the system memory byte in the CPU properties. Its default address is %M1.0. Because it is ordinary M memory, the program can write over it. A program that uses that byte for something else breaks its own first-scan bit.
  • In Rockwell the bit is called S:FS. It belongs to the controller. The program only reads it.

Put this bit as an NC contact in series in front of anything that must not fire at start-up.

In this simulator, downloading the program is a cold start: all memory is cleared. The Power cut button in the top bar keeps only the memory marked retentive. Try both and see the difference.

Level and event

Let us do a calculation that will change how you write programs.

Our scan is ten milliseconds. From the moment a person presses a button until they release it, about eight hundred milliseconds pass.

That is eighty scans.

That input is TRUE for eighty scans. Your rung runs eighty times with TRUE. If the rung counts, it counts to eighty. If it advances a step, it advances eighty steps. If it toggles a lamp, the lamp toggles eighty times. Eighty is an even number, so the lamp ends where it started. And the operator tells the supervisor the button is broken.

The button is not broken. You asked the wrong question.

"Is the button pressed?" is a level question. The answer is yes for as long as the condition lasts. "Was the button just pressed?" is an event question. The answer is yes only for a moment, and not again until the button is pressed again.

The contacts you know ask the first question. Two more contacts ask the second:

  • A P contact catches the rising edge. It conducts for the single scan in which its operand goes from 0 to 1.
  • An N contact catches the falling edge. It conducts for the single scan in which its operand goes from 1 to 0.
Btn P(Btn) N(Btn) 800 ms = 80 scans 10 ms = 1 scan 10 ms = 1 scan

That one-scan signal is called a one-shot. However long the finger stays on the button, the pulse lasts exactly one scan.

The falling edge is used less, but it is the right answer more often than most people think. "The guard has just been closed" is asked with an N contact on the guard switch. That way the machine becomes ready again without starting by itself. "The part has just left the sensor" is also asked with an N contact. That way you count the part that went past, not the one standing in front of the sensor.

The rule is simple: a button is a command, not a state. START does not mean "the operator wants to be running". It means "start now, once". Selector switches and sensors are the opposite. A guard is open for as long as it is open, and there you ask for the level every scan.

If holding a button down on one of your rungs gives a different result from touching it once, stop. You used a level where the plant wanted an event.

Where the edge is remembered, and the toggle

An edge is a comparison between the current value and the value one scan ago. So something has to store the value from one scan ago. Behind every P and N contact there is a hidden bit for this: the edge memory. Each scan the instruction compares the operand with this bit. Then it writes the current value into the bit for the next scan.

That is the whole mechanism. It also explains why the pulse lasts one scan. In the first scan the operand is 1 and the stored value is 0. They differ, so there is a rising edge. The contact conducts and the stored value becomes 1. In the second scan the operand is 1 and the stored value is also 1. There is no difference and the contact does not conduct. The finger can stay on the button until the end of the shift. The contact conducted only once.

Two consequences follow.

In Siemens the edge looks at the operand, not at the rung. The P contact makes its comparison whether power reaches it from the left or not. If you press START while an interlock is open, the edge is used up. No pulse comes out. Even if the interlock clears a second later, the button still being held does nothing. The operator has to release it and press again. This is not a defect: a command the machine could not carry out at that moment should not be carried out later either.

Rockwell asks a different question. Studio 5000 has no rising-edge contact. Instead it has the ONS instruction, placed in the middle of the rung. ONS does not look at a single tag. It looks at the power reaching it, the result of everything to its left, and conducts in the scan where that power goes from 0 to 1. Move ONS to another place on the rung and its meaning changes.

So a P contact behind an interlock uses up the edge. An ONS in the same place sees no edge to use up, and conducts in the scan the interlock clears. Two different but defensible answers to the same question. That is why it matters to know which platform you are on.

On real hardware you name the edge bit yourself. In Siemens this is usually an M bit; in Rockwell it is a BOOL tag you write next to the ONS. Using the same bit for two different edge instructions is a classic mistake. The two instructions share one memory and the pulses come and go. This editor gives every contact its own edge memory, so you cannot make that mistake here. But you will meet it in somebody else's program.

Now the circuit this whole zone is built on: the toggle. There is one button. Each press flips the output.

P Light_PB Toggle_Pulse Hall_Lights Toggle_Pulse Hall_Lights Toggle_Pulse Hall_Lights 1 2

Rung 1 turns the press into a one-scan pulse. Rung 2 says: if there is a pulse, flip the lamps this scan; if there is no pulse, leave them as they are. There are two parallel branches for this, and each is true only in its own case: "pulse and lamp off" or "no pulse and lamp on". The output reads its own value. This is one step beyond the seal-in idea.

So why not say "pulse and lamp on, then reset; lamp off, then set"? Try it on paper. The Set rung turns the lamp on. The Reset rung below looks at the lamp, sees it on, and turns it off in the same scan with the same pulse. The circuit undoes its own work.

Read the state once, decide once, write once. That is what this chapter has been teaching from the start.