You are on page 1of 13

Ladder Logic Programming Examples

Once a piece of ladder logic is created that accomplishes a specific task it can be re-used in
other areas of the program and in other applications as well. So by creating ladder logic
programming examples we can speed up or overall programming time.
Constructing a program is then a simple matter of grabbing the appropriate ladder logic
programming examples and connecting them in an orderly fashion. Let us take a look at some
very simple, ladder logic programming examples
Latching in a PLC
Latching is one of the most important pieces of ladder logic programming that you’ll ever use.
When we use the term latching in a PLC it refers to changing the state of an output to TRUE,
holding the state of that output TRUE until certain conditions occur, then returning the state
of the output back to FASLE.
This can be achieved with two methods.
1. Set and Reset instructions. In an Allen Bradley PLC they are called Latch and
Unlatch instructions. These instructions simulate the function of an electro-
mechanical latching relay. Advantages include flexibility in programming because the
Set (Latch) and Reset (Unlatch) symbols do not need to be in the same rung. The
disadvantage is that debugging can become more difficult because the Set (Latch) and
Reset (Unlatch) symbols may be scattered throughout the program.
2. Latching logic. Quite often referred to as hold in logic. It’s ok to interchange the terms.
The advantage of latching logic is that troubleshooting is easier because the symbols
used are all in the same rung. The disadvantage is that there is some inflexibility in
programming because latching logic requires all the symbols to be on the same rung
and may even overflow to the next rung. This can be restrictive in some cases.
Simple applications requiring a latch are well suited to use latching logic. But when it comes
to more complex applications the use of Set (Latch) and Reset (Unlatch) symbols may be
required.
Latching in a PLC requires at least one input to set the latch (Input A), one input to reset the
latch (Input B) and one output to store the latch state (Output Y).
The inputs that set and reset the latch are usually momentary pulses. A great example of a
device that can provide a momentary pulse to a PLC input is a push button.

Ladder Logic Latch with SET & RESET Symbols


Let’s start with the Set (Latch) and Reset (Unlatch) logic. The rungs below show the basic
code.
When both Input A and Input B are FALSE then the state of Output Y does not change. If
Output Y is FALSE then it stays FALSE.

Page 1 of 13
Ladder Latch
If Input A goes TRUE momentarily then the SET symbol changes the state of Output Y to
TRUE.
Then, after subsequent scans, if Input A changes state to FALSE it does not affect the state of
Output Y. In other words, Output Y is latched TRUE.

Ladder Latch (Set or Latch)


Only when Input B changes state to TRUE will the RESET symbol change the state of Output
Y back to FALSE. In other words, Output Y is now unlatched.

Ladder Latch (Reset or Unlatch)


Remember the PLC scan runs from left to right and from top to bottom. So if both Input A and
Input B are TRUE at the same time, then in the ladder diagram above the first rung is evaluated
and Output Y is set TRUE.
But, then the second rung is evaluated and Output Y is set FALSE. Once the scan reaches the
end of the entire program it will execute the state of Output Y as FALSE.

Page 2 of 13
Ladder Logic Latch with Hold in Logic
Using hold in logic to achieve latching has a similar outcome to using Set (Latch) and Reset
(Unlatch) symbols.
But with hold in logic both Input A and Input B are on the same rung as Output Y. Also, the
way in which the latch is SET and RESET is done differently.
Notice that Input B is a normally closed (NC) contact symbol and Output Y is used twice and
branched (or in parallel with Input A).

Ladder logic latch with hold in logic


Remember the scan goes from left to right and top to bottom. So the scan starts from the left
hand side of the rung and moves right to Input A. If Input A goes TRUE and Input B is FALSE
then Output Y goes TRUE.

The scan continues on with the rest of the program and it cycles back to the rung.
Previously Output Y had changed state to TRUE, so now Output Y that is in a branch across
Output A, also goes TRUE and there is no other change.

Page 3 of 13
When the scan cycles back again from the top, if Input A goes FALSE, with Input B still
FALSE, then Output Y stays TRUE.
This is because Output Y is held in by itself using the branch across Input A.
Notice that the logic flows from the left hand side rail through the Output Y branch and then
through Input B to Output Y at the right hand side rail.

Ladder hold in logic (Latched)


Once we have triggered the hold in logic using Input A, Output Y will remain latched even if
Input A goes FALSE.
Output Y will remain latched TRUE until Input B goes TRUE. Because Input B is a normally
closed (NC) contact symbol, when it goes TRUE, the logic flow is blocked and Output Y goes
FALSE. Thus releasing the latch.
Remember the NC contact symbol works like a NOT statement, it is reverse logic.

So, when the scan cycles back again from the top then Output Y, branched across Input A, also
goes FALSE.

Ladder hold in logic (Unlatched)

Page 4 of 13
Once Input B returns to the FALSE state we are back at the start, ready to initiate the latch
again.
We can write out the logic expression above as:
IF (INPUT A OR OUTPUT Y) AND NOT (INPUT B) THEN OUTPUT Y.
Hold in logic is great to use because it simplifies your code. It enables us to place all the
conditions that initiate and release latch in the same rung. This makes it easier to read and
troubleshoot.

PLC Motor Control


Ladder logic for motor control can be accomplished using hold in logic. Remember it is ok to
also call it latching logic.
Simple ladder logic for motor control using push button start stop logic includes a start button,
stop button, motor thermal overload and motor run contactor.
When we wire up the inputs to the PLC the start push button input is wired normally open
(NO). So when the start button is pushed the PLC input changes state from FALSE to TRUE.

Start Button
But the stop push button and thermal overload are always wired normally closed (NC). So
when the stop button is pushed it changes from CLOSED to OPEN. In turn the PLC input
changes state from TRUE to FALSE.

Stop Button

Page 5 of 13
In fact the rule of thumb is that any device that is required to stop the motor should be wired
normally closed (NC), to make it “fail safe”. The most common failures are wire break, device
failure or PLC input failure.
Wiring the stop push button normally closed (NC) is done because when a failure occurs in the
PLC input circuit it will, more often than not, lead to an open circuit which changes the state
of the PLC input from TRUE to FALSE.
However, if we wire the stop PLC inputs as normally open (NO) and a failure occurs then the
state of the PLC input does not change. It stays FALSE, even if the stop button is pressed,
because there is an open circuit in the connection to the PLC input.
So if there is no change in state, we cannot tell the motor to stop in our ladder logic program,
which is really bad.
So for any PLC input that is intended to stop the motor we need to
WIRE THE MOTOR STOP SIGNALS NORMALLY CLOSED AND USE A NORMALLY OPEN
SYMBOLS IN THE PLC.
Now that we’ve grasped the concept of the fail-safe stop input let’s move on to the motor
control ladder logic programming example.
Motor Control Ladder Diagram
First up let’s list the required inputs and outputs for our motor control ladder diagram. PLC
manufacturers use different memory address allocation so the input output allocations used
here are arbitrary address.
Below is the list of required inputs:

Next let’s list the required outputs.

The ladder logic programming example uses the M1 START push button input to activate the
M1 RUN output.
The M1 RUN output is used a second time to latch the M1 RUN output.
Both M1 STOP and M1 TOL are wired normally closed (NC) to the PLC inputs and thus need
to be configured as normally open (NO) symbols in the logic.
So when either stop is activated the logic flow is broken and the latch is reset.

Page 6 of 13
Motor Control Ladder Diagram
Remember, we must wire M1 Stop and M1 TOL using normally closed (NC) contacts to the
PLC inputs to make it “fail-safe” and for this motor control ladder diagram to work.

PLC Wiring Basics


Below is a table which displays the different combinations of PLC digital input wiring
and ladder logic symbols that can be used. It also outlines the logic state each of the ladder
logic symbols depending on whether the PLC input is activated or de-activated. When the
symbol is BLACK its state is FALSE and when the symbol is GREEN its state is TRUE.

PLC Wiring Basics and Ladder Logic Symbols

Page 7 of 13
PLC Timer
There are various types of PLC timers used in ladder logic programming. By far the most
common PLC timer is the ON delay timer.
The symbol for an ON delay timer is expresses differently depending on the PLC manufacturer.
But all ON delay timers have four essential elements:
1. Tag/Address
2. Start Input
3. Done Output
4. PRESET Time Value
Some PLC manufacturers also have accumulated time value, remaining time value, a time base
value (seconds, milliseconds, etc.) and timer reset input.
A basic symbol for an ON delay timer in PLC ladder diagram is shown below.

Timer in PLC Ladder Diagram


The ON delay timer is activated when the start input is TRUE. After the PRESET time expires
then the DONE output also goes TRUE. If at any time the start input goes FALSE the timer is
reset and the done output goes to FALSE.
Check out the timing chart below to get a better picture of how the ON delay timer works.

Timer in PLC Ladder Diagram ON Delay Timer Timing Chart

Page 8 of 13
PLC Timer Example
Let’s build on the previous example of motor control using latching logic. We can introduce a
warning siren in order to let operators know that the motor is about to start. But we need to add
an ON delay timer in order to delay the motor from starting.
Because we are trying to accomplish two actions (siren and motor run) we’ll need to add an
intermediate internal variable to replace M1 Run output.
Let’s call the internal variable Start Command with address M1.0 (remember PLC
manufacturers use different memory address allocation so M1.0 is an arbitrary address).
Then we can use the Start Command to trigger each action on a different rung and add the
required control logic.
Below is the list of required inputs, no change:

Next let’s add the extra siren output.

We need to add an extra internal variable.

Finally let’s add the ON delay timer.

Remember, we must wire M1 Stop and M1 TOL using normally closed (NC) contacts to the
PLC inputs to make it “fail safe” and for this motor control ladder diagram to work.
Check out the motor control ladder diagram with delay start warning siren below.

Page 9 of 13
Motor Control Ladder Diagram – Delay Start Warning Siren
The first rung works the same as the standard motor control latching logic.
The difference is we replace the M1 Run output with an internal variable called Start
Command. So now we can use the Start Command latch to trigger multiple actions.
After the first rung is scanned it moves to the second rung. If the Start Command is TRUE from
the motor control latching logic on the first rung and the M1 Run output is FALSE (motor is
not running) then the Siren output is activated.
Please Note – The M1 Run symbol is triggered from the third rung.
The scan then jumps to the last rung and if the Start Command is TRUE then timer T1 is
activated.
After the Start Command is TRUE for ten seconds (PRESET time) the T1 ON delay timer will
activate the M1 Run output. Therefore Motor No.1 will start running.
That’s not the end of the story, because the siren is still activated. So, when the PLC scan cycles
back to the top and moves through the rungs.
If the stop inputs have NOT been triggered, the Start Command latch will still be active.
So, when the scan gets to the second rung the Start Command is still TRUE and the M1 Run
output is also TRUE (the motor is running).

Page 10 of 13
On the second rung the M1 Run output is normally Closed (NC). So when it is TRUE no logic
flows and the Siren output goes FALSE and switches off.
If either of the stop inputs are activated then logic flow is broken in the latching logic of the
first rung and the Start Command goes FALSE. This also breaks the logic flow in the second
and third rungs resulting in the motor stopping.
If either of the stop inputs are activated during the ten second starting time, while the siren is
activated, then the logic flow to the Siren output is also broken and the siren de-activates.

ON OFF Timer
ON OFF timer logic is often referred to as flasher logic. Why? Because, among other things,
we can use it to make lights flash on and off. It is basically a two-step cyclic sequence based
on time. Both the ON and OFF times are adjustable.
We can develop this code with two ON delay timers and two rungs of ladder logic
programming. The PRESET time of the first timer dictates the OFF time and the PRESET time
of the second timer dictates the ON time.
This can prove handy when you have an application that requires two different cycle times.
Such as a plastic shredder that runs forward for 60 seconds and then reverses for 5 seconds
cyclically to reduce jamming.

ON OFF Timer Example


Let’s use the motor control ladder diagram example above and add a flashing warning light. It
will activate after the siren has finished and the motor starts running. In this case we would use
the M1 Run output to trigger our timing circuit.
We need to add an extra output, internal variable and two ON delay timers.
Below is the list of required inputs, no change.

Next let’s add the extra light output.

Page 11 of 13
We need an extra internal variable for the timers.

Finally let’s add the two extra ON delay timers.

Check out the PLC on off timer ladder diagram which we can tack onto the bottom of the
previous ladder diagram.

On Off Timer Ladder Diagram – Delay Start Warning Siren and Flashing Warning Light
When the PLC scan hits the first rung it comes across the M1 Run output symbol.
If the motor is running this symbol will be TRUE and the logic will flow to the next symbol
M1 Light Timer.
The M1 Light Timer symbol is normally closed (NC) and will be FALSE because timer T3 (on
the second rung) is not active and done. This means the M1 Light Timer symbol allows logic
flow to timer T2.
Timer T2 starts timing and after 1 second timer T2 done output goes TRUE. So then logic
flows to M1 Light output and it too goes TRUE.

Page 12 of 13
Then the PLC scan moves to the second rung where M1 Light output is now TRUE allowing
timer T3 to start timing.
While timer T3 is timing the logic flow is broken therefore M1 Light output is FALSE.
The scan keeps cycling through the rungs until the 1 second PRESET time for timer T3 has
expired. Then time T3 done output goes TRUE. Logic flows to M1 Light Timer output and it
too goes true.
When again the scan cycles back to the top and moves through the first rung we notice that M1
Light Timer has changed state from FALSE to TRUE. Thus breaking the logic flow.
As the scan progresses through the rungs M1 Light output, timer T3 and M1 Light Timer all
go back to a FALSE state. Effectively resetting the timer sequence.
So when the scan cycles back to the top it starts the timing cycle once again.
M1 Light will be OFF for T1 time PRESET and ON for T2 timer PRESET.
The timing cycle will continue until the motor stops running, when the M1 Run symbol changes
state to FALSE.

Page 13 of 13

You might also like