100% found this document useful (1 vote)
205 views

PLC Programming

The document discusses different types of programming languages used in programmable logic controllers (PLCs), focusing on ladder programming. It describes the basic format and components of ladder diagrams, including rungs, contacts, and coils. It also explains common ladder instructions for relays, timers, counters, and other functions.

Uploaded by

Muhammad Bilal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
205 views

PLC Programming

The document discusses different types of programming languages used in programmable logic controllers (PLCs), focusing on ladder programming. It describes the basic format and components of ladder diagrams, including rungs, contacts, and coils. It also explains common ladder instructions for relays, timers, counters, and other functions.

Uploaded by

Muhammad Bilal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

PLC Programming

Dr. Tarek A. Tutunji


PLC Programming
► As PLCs developed and expanded, programming
languages have developed with them.

► The three types of programming languages used


in PLCs are:
 ladder
 Boolean
 Grafcet

► In this chapter, we will concentrate on ladder


programming
Ladder Language
Boolean Language
Grafcet
Ladder Diagram Format
► The main functions of a ladder diagram program are to control outputs
and perform functional operations based on input conditions.

► Ladder diagrams use rungs to accomplish this control.

► A rung consists of a set of input conditions (represented by contact


instructions) and an output instruction at the end of the rung
(represented by a coil symbol).
Ladder Diagram Format
►A ladder rung is TRUE
(i.e., energizing an
output or functional
instruction block) when
it has logic continuity.

► Logic continuity exists


when power flows
through the rung from
left to right.
Ladder Diagram Format
► When a ladder
diagram contains a
functional block,
contact instructions
are used to represent
the input conditions
that drive (or enable)
the block’s logic.
Ladder Instructions
1. Ladder relay
2. Timing
3. Counting
4. Program/flow control
5. Arithmetic
6. Data manipulation
7. Data transfer
8. Special function (sequencers)
9. Network communication
Relay Ladder Instructions
► Ladder relay instructions are the most basic
instructions in the ladder diagram instruction set.

► Theseinstructions represent the ON/OFF status of


connected inputs and outputs.

► Ladder
relay instructions use two types of
symbols: contacts and coils.
 Contacts represent the input conditions that must be
evaluated in a given rung to determine the control of
the output.
 Coils represent a rung’s outputs
Ladder Relay Instructions
Examine ON / Normally Open
Examine OFF / Normally Closed
Output Coil
Output Coil
Not Output Coil
Latch and Unlatch Output Coil
► A latch coil instruction causes an
output to remain energized even
if the status of the contacts that
caused the output to energize
changes.

► The latched output will remain


ON until it is unlatched by an
unlatch output instruction.

► An unlatch coil instruction resets


a latched output with the same
reference address.
One--Shot Output
One
► A one-shot output instruction operates in a manner similar to an
output coil instruction—if the ladder rung has continuity, the one-shot
output will be energized (ON). However, the length of time that a one-
shot output is ON is one scan
Transitional Contact
Ladder Scan Evaluation
► The processor starts solving a ladder program after it has
read the status of all inputs and stored this information in
the input table.

► The solution starts at the top of the ladder program,


beginning with the first rung and proceeding one rung at a
time.

► As the processor solves the control program, it examines


the reference address of each programmed instruction, so
that it can assess logic continuity for the rung being
solved.

► Even if the output conditions in the rung being solved


affect previous rungs, the processor will not return to the
previous rung to resolve it.
Scan Evaluation
Normally Open / Normally Closed
Normally closed stop push button
programmed as normally open
Normally open stop push button
programmed as normally closed
Timers and Counters
► PLC timers and counters are internal instructions
that provide the same functions as hardware
timers and counters.

► They activate or deactivate a device after a time


interval has expired or a count has reached a
preset value.

► Timerand counter instructions are generally


considered internal outputs.
Timers and Counters
► Timer instructions may have one or more time
bases (TB) which they use to time an event.

► The time base is the resolution, or accuracy, of


the timer.
Timers and Counters
► Timers are used in applications to add a specific amount of
delay to an output in the program.

► Counter instructions are used to count events, such as


parts passing on a conveyor belt.

► Counters, along with timers, must have two values:


 Preset value is the target number of ticks or counting numbers that
must be achieved before the timer or counter turns its output ON.
 Accumulated value is the current number of ticks (timer) or counts
(counter) that have elapsed during the timer or counter operation.
Timers and Counters
► Suppose a three AC cycle
(60 Hz) is needed

► The estimated delay of the


three cycles is
 3/60 = 50 msec

► The PLC program can use


a time base of 0.01 second
and count 5 ticks
Timers Instructions
Timer Instructions
On--Delay Energize Timer
On
► An ON-delay energize timer (TON) output instruction either provides
time-delayed action or measures the duration for which some event
occurs.

► Once the rung has continuity, the timer begins counting time-based
intervals (ticks) and counts down until the accumulated time equals
the preset time.

► When these two values are equal, the timer energizes the output and
closes the timed-out contact associated with the output.

► The timed contact can be used throughout the program as either a


normally open or normally closed contact.

► If logic continuity is lost before the timer times out, the timer resets
the accumulated register to zero.
On--Delay Energize Timer
On
On--Delay Timers
On
Off--Delay Energize Timer
Off
► An OFF-delay energize timer (TOF) output instruction
provides time-delayed action.

► If the control line rung does not have continuity, the timer
begins counting time-based intervals until the accumulated
time value equals the programmed preset value.

► When these values are equal, the timer energizes the


output and closes the timed-out contact associated with
the output.

► If logic continuity occurs before the timer times out, the


accumulated value resets to zero.
Off--Delay Energize Timer
Off
Off--Delay Timers
Off
Retentive On-
On-Delay Timer
► A retentive ON-delay timer (RTO) output instruction is used
if the timer’s accumulated value must be retained even if
logic continuity or system power is lost.

► If any rung path has logic continuity, the timer begins


counting time-based intervals until the accumulated time
equals the preset value.

► The accumulated register retains this accumulated value,


even if power or logic continuity is lost before the timer
has timed out.
Retentive Timer Reset
►A retentive timer reset (RTR) output instruction is
the only way to automatically reset the
accumulated value of a retentive timer.

► Ifany rung path has logic continuity, then this


instruction resets the accumulated value of its
referenced retentive timer to zero.

► Note that the retentive timer reset address will be


the same as the retentive timer output instruction
it is resetting.
Counter Instructions
► There are two
basic types of
counters: those
that can count
up and those
that can count
down.
Counter Instructions
Up Counter
► An up counter (CTU) output instruction adds a count, in
increments of one, every time its referenced event occurs.

► An up counter increases its accumulated value (the count


value in its accumulated register) each time the up-count
event makes an OFF-to-ON transition.

► When the accumulated value reaches the preset value, the


counter turns ON the output, finishes the count, and closes
the contact associated with the referenced output.
Down Counter
► A down counter (CTD) output instruction decreases the
count value in its accumulated register by one every time a
certain event occurs.

► Sometimes, a down counter is used in conjunction with an


up counter to form an up/ down counter, given that both
counters have the same reference registers.

► For example, while an up counter counts the number of


filled bottles that pass a certain point, a down counter with
the same reference address can subtract one from the
accumulated count value every time it senses an empty or
improperly filled bottle
Counter Reset
►A counter reset (CTR) output instruction resets up
counter and down counter accumulated values to
zero.

► When programmed, a counter reset coil has the


same reference address as the corresponding
up/down counter coils.

► Ifthe counter reset rung condition is TRUE, the


reset instruction will clear the referenced address.
Counters

► The counter will count up when contact 10 closes, count down when
contact 11 closes, and reset register 1003 to 0 when contact 12 closes.
► If the count is equal to 15 as a result of either an up or down count,
output 100 will be ON.
► If contents of register 1003 are greater than 15, output 101 will be ON.
► Output 102 will be ON if the accumulated count value is less than 15
Counter Example
► A block counter instruction
being used to count parts as
detected by a photoelectric eye
(PE) input.
► The preset value of counts is
500.
► Modify this circuit so that it will
automatically reset every time
the counter reaches 500.
► Also, add the instructions
necessary to implement an
output coil that indicates that
the count has reached 500.
Counter Example
Program / Flow Control Instructions
► Program/flow control
instructions direct the
flow of operations, as well
as the execution of
instructions, within a
ladder program.

► They perform these


functions using branching
and return instructions,
which are executed when
certain already
programmed control logic
conditions occur.
Program / Flow Control Instructions

► These Instructions are usually used in pairs


Master Control Relay
► Activates or
deactivates the
execution of a group
or zone of ladder
rungs.
► An MCR rung is used in
conjunction with an
END rung to fence a
group of rungs
Jump To
► A jump to (JMP)
instruction allows the
control program sequence
to be altered if certain
conditions exist.

► If the rung condition is


TRUE, the jump to coil
reference address tells the
processor to jump forward
and execute the target
rung.
Go To Subroutine
► A go to subroutine (GOSUB) output instruction also allows
normal program execution to be altered if certain
conditions exist.

► A label (LBL) instruction identifies the ladder rung that is


the target destination of a jump to or GOSUB instruction.

► A return (RET) instruction terminates a ladder subroutine


and is programmed with no conditional inputs. When the
control program encounters this instruction, it returns to
the main program.
Go To Subroutine
Arithmetic Instructions
Addition
Addition Example
► Two ingredients are added to a
reactor tank for mixing.
► Analog input modules, which
provide 12-bit information in
BCD, send data about the two
ingredients’ flows to the PLC.
► The values are stored in
registers 1000 and 1001.
► Implement instructions to keep
track of the total amount of the
combined ingredients, so that
this information can be
displayed on a monitor for the
operator.
Addition Example
Subtraction
Multiplication
Division
Square Root
Data Manipulation Instructions
► Relay-type instructions are limited to the
control of internal and external outputs
based on the status of specific bit
addresses, data manipulation instructions
allow multi-bit operations.

► Datamanipulation instructions handle


operations that take place within one, two,
or more registers.
Data Manipulation Instructions
Data Comparison
► Data comparison (CMP)
instructions compare the values
stored in two registers.
► These instructions are useful
when checking for values in the
application program.
► There are three basic data
comparisons: compare equal to,
compare greater than, and
compare less than.
► Based on the results of these
comparisons, the processor can
turn outputs ON or OFF and
perform other operations.
Data Comparison
► The compare functional block
compares the contents of two
registers, register 2000 and
register 2001, for a specific
comparison, in this case, equal
to.

► The block instruction energizes


output coil 100 when the
comparison occurs, and it
energizes output coil 101 if the
comparison has been satisfied.
Data Comparison
► Some PLCs may also have one
comparison block, which has
several outputs, that performs
multiple compare functions at
the same time.

► This type of comparison block


compares the data in the
registers and then turns ON the
output corresponding to the
outcome of the comparison (i.e.,
less than, greater than, equal
to).
Example
► Two ingredients are being
poured into a reactor tank.

► The first two ladder rungs open


the valves for ingredients A and
B, allowing them to be poured
into the tank.

► Implement an instruction block


that ensures that the valves
close when ingredient A reaches
500 gallons and ingredient B
reaches 750 gallons.
Example
Logic Matrix
► A logic matrix functional block
performs AND, OR, exclusive-
OR, NAND, NOR, and NOT logic
operations on two or more
registers.
► The block specifies the type of
logic function to be performed,
while the user specifies the
registers inside the block.
► In this example, registers 1000
and 1100 hold the operand
values, while register 2000
holds the result of the
operation.
Logic Matrix
Logic Matrix
Data Conversion
► Data conversion
instructions change the
contents of a given
register from one
format to another.
► Typical data
conversion instructions
include BCD-to-binary,
binary-to-BCD,
absolute, complement,
and inversion.
Set Constant Parameter
Increment
Shift and Rotate
Shift and Rotate
Shift and Rotate
Examine Bit
Example
► A PLC application controls a
batching process where the
reading of a temperature input
(Batch Temp) is critical to the
process.
► The process’s temperature
transducer is connected to a
four-channel, 0–10 VDC analog
input module with a 12-bit
resolution.
► The remaining four bits of each
channel are used as status
indicators for the module.
► Illustrate how to test for a fault
in this analog input interface’s
critical temperature
measurement.
Example
► By testing bit 17 of
register 1000 (which is
the destination of the
critical temperature
reading channel) for
an OFF condition
► If bit 17 is OFF, a fault
has occurred; if it is
ON, the channel is OK.
Data Transfer Instructions
► Data transfer
instructions move, or
transfer, numerical data
within a PLC, either in
single register units or in
blocks (a group of
registers).

► A GET data transfer


instruction accesses data
from a certain register,
whereas a PUT instruction
stores data in a specified
register.
Data Transfer Instructions
MOVE
MOVE Mask
MOVE Block
Special Functions Instructions
Network Communication Instructions

You might also like