UNIT III PLC PROGRAMMING
Different types of PLC program, Basic Ladder logic, logic functions, PLC module addressing,
registers basics, basic relay instructions, Latching Relays, arithmetic functions, comparison
functions, data handling, data move functions, timer-counter instructions, input-output
instructions, sequencer instructions.
DIFFERNENT TYPE OF PLC PROGRAMM:
The 5 most popular types of PLC Programming Languages are:
Ladder Diagram (LD)
Sequential Function Charts (SFC)
Function Block Diagram (FBD)
Structured Text (ST)
Instruction List (IL)
Ladder Diagram (LD)
Ladder logic is the simplest form of PLC programming. It is also known as “relay logic”. The
relay contacts used in relay controlled systems are represented using ladder logic.
Advantages of the Ladder Diagram (LD)
It is easily programmed and has an easily understood programming language.
It has flexibility in programming and reprogramming.
Troubleshooting is easier and faster
Sequential Function Charts (SFC)
Sequential function chart (SFC) is a visual programming language used for programmable
logic controllers (PLCs). It is one of the five languages defined by IEC 61131-3 standard.
The SFC standard is defined as Preparation of function charts for control systems, and was
based on GRAFCET.
In SFC programming, states or steps are represented by rectangular boxes.
A vertical straight line connects the different steps, and each step has a
corresponding output. There is a transition condition between steps. Figure
1 below shows the general diagram for the sequential function chart.
The first box represents the start of the operation. Two states are connected
with a vertical line. The horizontal lines between boxes represent transition
conditions. Sometimes, transition conditions can be denoted by a much
smaller rectangle between the larger states.
After a step is completed, the process moves on to the next state only if the
transition condition(s) is also satisfied.
Each of the states also has corresponding outputs. Outputs are represented
as rectangular boxes linked horizontally to their respective state.
Two conditions must be followed for every SFC:
1. There should be a transition condition between two steps.
2. A step should always separate two transition conditions.
Function Block Diagram (FBD):
The function block diagram (FBD) is a graphical language for
programmable logic controller design, that can describe the function
between input variables and output variables.
The function block is a block of code that performs certain
functionality. FBs will store their input, output, and in-out parameters
permanently in a data block so that they remain available even after
the block has been executed. A function block can also be called
several times at different points in a PLC program.
FBD offers many predefined function blocks, but you also have the
flexibility to create your own. This is particularly useful when you
need to reuse code, like controlling a motor or valve. Custom
function blocks let you tailor your program efficiently, using the
same block multiple times.
Structured Text (ST) :
Structured text, abbreviated as ST or STX, is one of the five
languages supported by the IEC 61131-3 standard, designed for
programmable logic controllers (PLCs). It is a high level language
that is block structured and syntactically resembles Pascal, on which
it is based.
Instruction List (IL) :
A program written in IL. "Instruction list" This is a low-level language
and resembles assembly language is a list of instructions. Each
instruction is written on one line of text. An instruction can have one
or more operands. Operands are variables or constant expressions.
Some other PLC Instructions are :
Relay-type (Basic) instructions: I, O, OSR, SET, RES, T, C.
Data Handling Instructions:
Data move Instructions: MOV, COP, FLL, TOD, FRD, DEG, RAD (degrees to
radian).
Comparison instructions: EQU (equal), NEQ (not equal), GEQ (greater than or
equal), GRT (greater than).
Basic Ladder Logic :
Ladder logic is a programming language that is used to program a PLC
(Programmable Logic Controller). It is a graphical PLC programming
language which expresses logic operations with symbolic notation using
ladder diagrams, much like the rails and rungs of a traditional relay logic
circuit.
Ladder logic is a fast and simple way of creating logic expressions for a PLC in
order to automate repetitive machine tasks and sequences. It is used in a
multitude of industrial automation applications. Some industrial automation
application examples where PLC ladder logic is used include….
Material Handling Conveyor System.
Pallet Packing and Strapping.
Ball Mill Lubrication System.
Logistics Package Conveying and Sorting.
Cement Batching.
Beverage Bottling and Labeling.
To help understand how to draw ladder logic diagrams the seven basic parts
of a ladder diagram are detailed below…..
1. Rails – There are two rails in a ladder diagram which are drawn as vertical
lines running down the far most ends of the page. If they were in a relay
logic circuit they would represent the active and zero volt connections of
the power supply where the power flow goes from the left hand side to
the right hand side.
2. Rungs – The rungs are drawn as horizontal lines and connect the rails to
the logic expressions. If they were in a relay logic circuit they would
represent the wires that connect the power supply to the switching and
relay components. Each rung is numbered in ascending sequential order.
3. Inputs – The inputs are external control actions such as a push button
being pressed or a limit switch being triggered. The inputs are actually
hardwired to the PLC terminals and represented in the ladder diagram by
a normally open (NO) or normally closed (NC) contact symbol.
4. Outputs – The outputs are external devices that are being turned on and
off, such as an electric motor or a solenoid valve. The outputs are also
hardwired to the PLC terminals and are represented in the ladder diagram
by a relay coil symbol.
5. Logic Expressions – The logic expressions are used in combination with
the inputs and outputs to formulate the desired control operations.
6. Address Notation & Tag Names – The address notation describes the
input, output and logic expression memory addressing structure of the
PLC. The tag names are the descriptions allocated to the addresses.
7. Comments – Last but by not least, the comments are an extremely
important part of a ladder diagram. Comments are displayed at the start
of each rung and are used to describe the logical expressions and control
operations being executed in that rung, or groups of rungs.
Understanding ladder diagrams is made a lot easier by using comments.
The normally open contact (NO) is TRUE when the event is active and
FALSE when the event is NOT active. While the normally closed contact
(NC) is FALSE when the event is active and TRUE when the event is NOT
active.
Green indication shows it is active and high.
Ladder Logic AND Function
The AND function examines multiple PLC inputs and has one resulting output.
If we translate an AND function into a ladder diagram we can express it
symbolically in the form of two PLC inputs A and B using normally open (NO)
contacts and a PLC output Y using a relay coil.
They are all connected in line, just like a series connection in an electric circuit.
This time we have also highlighted the hidden AND function to illustrate the
relationship between the ladder logic functions and the ladder diagram rung
structure….
Ladder Logic Basics – AND Function
We can write out the logic expression above as IF A AND B THEN Y. The AND
function examines if all the PLC inputs are TRUE, then the corresponding result
is also TRUE. However if any one of the PLC inputs is FALSE then the
corresponding result is also FALSE.
Ladder Logic OR Function
The OR function examines multiple PLC inputs and has one resulting output. If
we translate an OR function into a ladder diagram we can express it symbolically
in the form of two PLC inputs A and B using normally open contacts (NO) and a
PLC output Y using relay coil.
The inputs are placed in the rung in what is known as a branch. This is the
equivalent of a parallel connection in an electric circuit. The output is then
connected in line with the rung. This time we have also highlighted the hidden
OR function when we create a branch (parallel connection) with PLC input B
across PLC input A….
Ladder Logic Basics – OR Function
We can write out the logic expression above as IF A OR B THEN Y. The OR
function examines if any of the PLC inputs are TRUE, then the corresponding
result is also TRUE. However, all the PLC inputs must be FALSE in order for the
corresponding result is also be FALSE.
Because PLC input A and B follows the binary concept and are part of the OR
function there are four possible logic iterations. Check out the truth table
below….
Truth Table – OR Function
PLC Module Addressing:
The addressing for a fixed PLC is as follows: I: 0 / 3 for input screw
terminal 3. I: 0 / 8 for input screw terminal 8. O: 0 / 7 for output screw
terminal 7.
PLC Input Output modules are one of the core functional
components that exist within a programmable logic controller system,
in simple terms PLC I/O modules act as messengers between the
CPU and process control devices.
Direct addressing means that when a PLC memory item is
referenced by an instruction there is only one location in memory
being targeted. The following are some examples of direct
addressing: WX3 (analog input #3) WY26 (analog output #26) T17
(Timer #17)
Indirect Addressing:
Indirect addressing allows the memory address used by an
instruction to be varied so that it can point to more than one location
at runtime. Used this way, one memory location stores a ”pointer” to
another memory location. For example, if V17 has the value "37",
then referencing D[V17] will return the value in the memory location
D37. While this may initially increase the difficulty of troubleshooting,
it has the advantage of greatly reducing the number of rungs and
instructions needed to control a process.
The Do-more operating system implements all of the built-in and
user-created data blocks as arrays, meaning that any of these data
blocks can be indirectly addressed. All of the data blocks in the CPU's
memory are limited to 65536 elements per block, so the array index
value must be in the range of 0 to 65535. The array index can be
either a single parameter stored in a V memory location ( e.g D[V17]
), or a math expression ( e.g. D[V17 + 16], or D[V17 + D18], or
D[SQRT(D18)] ).
Both indirect addressing mechanisms (REF - Read Value
Indirectly function and REFWRITE - Write Value Indirectly instruction)
allow the use of any numeric value (or even any expression for REF
function parameters) for the array index.
The indirect address can optionally include an offset value. For
example, if V17 has the value "37", then referencing D[V17 + 3] will
return the value in the memory location D40. The Offset value is
limited to a maximum of 63.
Indirectly Addressing Bit Locations
All of the bit-memory data blocks in the CPU can be indirectly
addresses. For example, if V17 has the value "37", then referencing
C[V17] will return the value in bit location C37.
Indirectly Addressing Numeric Locations
PLC Registers :
The term PLC register is used for the area of memory within the PLC
used for data exchange with the OP--406. PLC registers (addresses)
are sometimes known as data registers, internal registers or 16-bit
(word) addresses.
PLC Register – Let us consider a simple example and compare the
ladder diagram with its real world external physically connected relay
circuit. In Fig. 21.32 (a), the coil circuit will be energized when there
is a closed loop between the ‘+’ and ‘—’ terminals of the battery. The
same circuit can be drawn using ladder diagram. A ladder
diagram consists of individual rungs. Each rung must contain one or
more inputs and one or more outputs. The first instruction on a rung
must always be an input instruction and last instruction on a rung
should always be an output coil. The ladder diagram of Fig. 21.32(a)
is shown in Fig. 21.32(b).
The PLC Register in use can be explained by using Fig. 21.32(b) and
changing SW2 from normally open to normally closed as shown in
Fig. 21.32(c).
Hence, in Fig. 21.32(c), SW1 will be physically OFF and SW2 will be
physically ON initially. Each symbol or instruction has been given an
address. This address sets aside a certain storage area in the PLC
data files so that the status of the instruction (i.e. true/false) can be
stored. Most PLCs uses 16 slots or bit storage locations. In the
example given above, two different storage locations or PLC Register
are used.
In the tables of two registers 00 and 05 shown in Fig. 21.32(d), we
can see that in register 00, bit 00 corresponding to input 0000 was a
logic 0 and bit 01 corresponding to input 0001 was a logic 1. Register
05 shows that bit 00 corresponding to output 0500 was a logic 0. The
logic 0 or 1 indicate whether an instruction is False or True.
The PLC will only energise an output when all conditions on the rung
are TRUE. Hence, in the above example, SW1 must be logic 1 and
SW2 must be logic 0, then and only then the output (coil) will be True,
that is energized.
If any instruction on the rung before the output (coil) is false, then the
output (coil) will be false (not energized).
PLC BASIC Relay Instructions
RELAY-TYPE INSTRUCTIONS
The ladder diagram language is basically a symbolic set of instructions used to create the
controller program.
The three fundamental symbols that are used to translate relay control logic to contact Symbolic
logic are EXAMINE IF CLOSED,EXAMINE IF OPEN, and OUTPUT ENERGIZE
Normally open
Analogous to the normally open relay contact. For this instruction we ask the processor to
EXAMINE IF (the contact is) CLOSED.
The status bit will be either 1(ON) or 0 (OFF). The status bit is examined for an ON condition.
If the status bit is I (ON). Then the instruction is TRUE. If the status bit is 0 (OFF). Then the
instruction is FALSE.
Normally closed
Instruction, we ask the processor to EXAMINE IF (the contact is) OPEN. The status bit will
be either 1 (ON) or 0 (OFF). The status bit is examined for an OFF condition. If the status bit
is 0 (OFF), then the instruction is TRUE. It the status bit is 1 (ON), then the Instruction is
FALSE.
Relay coil (OTE)
The processor ( makes it is Instruction true (analogous to energizing a coil) when there is a
path 01 true XIC and XIO instructions in the rung. If any left to right path of input conditions
is TRUE, the output is energized (turned ON). The status bit 01 the addressed OUTPUT
Energize instruction is set to 1 (ON) when the rung is TRUE.
The status bit 01 the addressed OUTPUT Energize instruction is reset 10 0 (OFF) when the
rung is FALSE.
LATCH Type Instructions:
PLC ARITHMATIC INSTRUCTIONS:
Most PLCs have arithmetic function capabilities. Basic PLC math
instructions include add, sub- tract, multiply and divide to calculate
the sum, difference, product, and quotient of the content of word
registers. The PLC is capable of doing many arithmetic operations
per scan period for fast updating of data.
Depending on what type of processor is used, various math
instructions can be programmed. The basic four mathematical
functions performed by PLCs are: Addition —The capability to add
one piece of data to another. Subtraction —The capability to subtract
one piece of data from another. Multiplication —The capability to
multiply one piece of data by another. Division —The capability to
divide one piece of data by another.
Addition Instruction: Most math instructions take two input values,
perform the specifi ed arithmetic function, and output the result to an
assigned memory location. For example, the ADD instruction performs
the addition of two values stored in the referenced memory locations.
How these values are accessed depends on the controller. Figure 11-
3 shows the ADD instruction used with the SLC 500 controllers. The
operation of the logic rung can be summarized as follows: • When
input switch SW is closed the rung will be true. • The value stored at
the source A address, N7:0 (25), is added to the value stored at the
source B address, N7:1 (50). • The answer (75) is stored at the
destination address N7:2. • Source A and source B can be either values
or addresses that contain values, but A and B cannot both be
constants.
Subtraction Instruction: The SUB (subtract) instruction is an output
instruction that subtracts one value from another and stores the result in the
destination address. When rung conditions are true, the subtract instruction
subtracts source B from source A and stores the result in the destination.
Figure 11-6 shows the SUB instruction used with the SLC 500 controllers. The
operation of the logic rung can be summarized as follows: • When input switch
SW is closed the rung will be true. • The value stored at the source B address,
N7:05 (322), is subtracted from the value stored at the source A address, N7:10
(520). The answer (198) is stored at the destination address, N7:20. • Source A
and source B can be either values or addresses that contain values, but A and B
cannot both be constants.
Multiplication Instruction: The multiply (MUL) instruction is an output
instruction that multiplies two values and stores the result in the destination
address. Figure 11-8 shows the MUL instruction used with the SLC 500
controllers. The operation of the logic rung can be summarized as follows: •
When input switch SW is closed the rung will be true. The data in source A
(constant 20) will be multiplied by the data in source B (accumulated value of
counter C5:10). • The resultant answer is placed in the destination N7:2. •
Similar to previous math instructions, source A and B in multiplication
instructions can be values (constants) or addresses that contain values, but A
and B cannot both be constants.
Division Instruction: The divide (DIV) instruction divides the value in source
A by the value in source B and stores the result in the destination and math
register. Figure 11-11 shows an example of the DIV instruction. The operation of
the logic rung can be summarized as follows: • When input switch SW is closed
the rung will be true. • The data in source A (the accumulated value of counter
C5:10) is then divided by the data in source B (the constant 2). • The result is
placed in the destination N7:3. • If the remainder is 0.5 or greater, a roundup
occurs in the integer destination. • The value stored in the math register consists
of the unrounded quotient (placed in the most signifi cant word) and the
remainder (placed in the least signifi - cant word). • Some PLCs support the use
of fl oating-decimal as well as integer (whole number) values. As an example, 10
divided by 3 may be expressed as 3.333333 (fl oating-decimal notation) or 3 with
a remainder of 1.
Comparision Function :
Refer the following link for Up down counter, timer and PLC
instructions:
https://instrumentationtools.com/plc-data-comparison-instructions/
PLCs generally can make comparisons for less than (< or LT or LES), equal to (=
or = = or EQ or EQU), less than or equal to (≤ or <= or LE or LEQ), greater than (>
or GT or GRT), greater than or equal to (≥ or >= or GE or GEQ), and not equal to
(≠ or <> or NE or NEQ). The six comparison functions are Less Than ( < ), Less
Than or Equal ( ≤ ), Equal to ( = ), Greater Than or Equal ( ≥ ), Greater Than ( > ),
and Not Equal to ( ≠ ).
The Q output for each instruction “box” activates whenever the
evaluated comparison function is “true” and the enable input (EN) is
active.
If the enable input remains active but the comparison function is
false, the Q output de-activates. If the enable input de-de-activates,
the Q output retains its last state.
A practical application for a comparative function is something called
alternating motor control, where the run-times of two redundant
electric motors are monitored, with the PLC determining which motor
to turn on next based on which motor has run the least:
Similarly for all functions the plc programm can be written
DATA HANDLING INSTRUCTIONS/DATA MOVE INSTRUCTION:
The MVM instruction is a word instruction that moves data from a
source location to a destination and allows portions of the destination
data to be masked by a separate word. As long as the rung remains
true, the instruction moves the data on each scan. Source is the
address of the data you want to move.
As long as the rung remains true, the instruction moves the data on
each scan.
Entering Parameters
Source is the address of the data you want to move.
Mask is the address of the mask through which the instruction
moves data; the mask can be a hexadecimal value (constant).
Destination is the address where the instruction moves the data.
Data movement is the process of transferring data from one place to
another. This process is typically initiated when there are system
upgrades, consolidations, or when there is a need to synchronize data
across different platforms for business intelligence or other operational
purposes.
COUNTER INSTRUCTION:
A counter is a PLC instruction that either increments (counts up) or
decrements (counts down) an integer number value when
prompted by the transition of a bit from 0 to 1 (“false” to “true”).
Counter instructions come in three basic types:
1. up counters,
2. down counters, and
3. up/down counters.
Both “up” and “down” counter instructions have single inputs for
triggering counts, whereas “up/down” counters have two trigger
inputs: one to make the counter increment and one to make the
counter decrement.
A push-button switch connected to activate discrete input IN5 when
pressed will serve as a manual “reset” of the count value.
An indicator lamp connected to one of the discrete output channels
will serve as an indicator of when the object count value has
exceeded some pre-set limit.
We will now analyze a simple Ladder Diagram program designed to
increment a counter instruction each time the light beam breaks:
This particular counter instruction (CTU) is an incrementing counter,
which means it counts “up” with each off-to-on transition input to
its “CU” input.
The normally-closed virtual contact (IN sensor object) is typically held
in the “open” state when the light beam is continuous, by virtue of
the fact the sensor holds that discrete input channel energized while
the beam is continuous.
When the beam is broken by a passing object on the conveyor belt,
the input channel de-energizes, causing the virtual contact IN sensor
object to “close” and send virtual power to the “CU” input of the
counter instruction.
This increments the counter just as the leading edge of the object
breaks the beam. The second input of the counter instruction box
(“R”) is the reset input, receiving virtual power from the contact IN
switch reset whenever the reset pushbutton is pressed. If this input is
activated, the counter immediately resets its current value (CV) to
zero.
Status indication is shown in this Ladder Diagram program, with the
counter’s preset value (PV) of 25 and the counter’s current value (CV)
of 0 shown highlighted in blue.
The preset value is something programmed into the counter
instruction before the system put into service, and it serves as a
threshold for activating the counter’s output (Q), which in this case
turns on the count indicator lamp (the OUT counts reached coil).
According to the IEC 61131-3 programming standard, this counter
output should activate whenever the current value is equal to or
greater than the preset value (Q is active if CV ≥ PV).
we could also use a down counter instruction preset to a value of
25, which turns on an output coil when the count reaches zero:
With each sensor pulse received, the counter instruction decrements.
When it reaches zero, the Q output activates.
A potential problem in either version of this object-counting system
is that the PLC cannot discriminate between forward and reverse
motion on the conveyor belt. If, for instance, the conveyor belt were
ever reversed in direction, the sensor would continue to count objects
that had already passed by before (in the forward direction) as those
objects retreated on the belt. We can use these two phase-shifted
signals to increment or decrement an up/down counter instruction,
depending on which pulse leads and which pulse lags.A Ladder
Diagram PLC program designed to interpret the quadrature pulse
signals is shown here, making use of negative-transition contacts as
well as standard contacts:
The counter will increment (count up) when sensor B de-energizes
only if sensor A is already in the de-energized state (i.e. light beam A
breaks before B).
Counter will decrement (count down) when sensor A de-energizes
only if sensor B is already in the de-energized state (i.e. light beam B
breaks before A).
Note that the up/down counter has both a “reset” (R) input and a
“load” input (“LD”) to force the current value.
PLC Timer Instructions
A timer is a PLC instruction measuring the amount of time elapsed
following an event.
Timer instructions come in two basic types: on-delay timers and off-
delay timers. Both “on-delay” and “off-delay” timer instructions have
single inputs triggering the timed function.
An “on-delay” timer activates an output only when the input has
been active for a minimum amount of time.
ake for instance this PLC program, designed to sound an audio
alarm siren prior to starting a conveyor belt.
To start the conveyor belt motor, the operator must press and hold
the “Start” push-button for 10 seconds, during which time the siren
sounds, warning people to clear away from the conveyor belt that is
about to start.
Only after this 10-second start delay does the motor actually start
(and latch “on”):
Similar to an “up” counter, the on-delay timer’s elapsed time (ET)
value increments once per second until the preset time (PT) is
reached, at which time its output (Q) activates.
In this program, the preset time value is 10 seconds, which means
the Q output will not activate until the “Start” switch has been
depressed for 10 seconds.
The alarm siren output, which is not activated by the timer,
energizes immediately when the “Start” push-button is pressed.
An important detail regarding this particular timer’s operation is
that it be non-retentive.
This means the timer instruction should not retain its elapsed time
value when the input is de-activated.
Instead, the elapsed time value should reset back to zero every time
the input de-activates. This ensures the timer resets itself when the
operator releases the “Start” push-button.
A retentive ondelay timer, by contrast, maintains its elapsed time
value even when the input is de-activated. This makes it useful for
keeping “running total” times for some event.
Most PLCs provide retentive and non-retentive versions of on-
delay timer instructions, such that the programmer may choose the
proper form of on-delay timer for any particular application.
OFF DELAY TIMER:
When the input (IN) to this timer instruction is activated, the output
(Q) immediately activates (with no time delay at all) to turn on the
cooling fan motor contactor.
This provides the engine with cooling as soon as it begins to rotate
(as detected by the speed switch connected to the PLC’s discrete
input).
When the engine stops rotating, the speed switch returns to its
normally-open position, de-activating the timer’s input signal which
starts the timing sequence.
The Q output remains active while the timer counts from 0 seconds
to 120 seconds.
As soon as it reaches 120 seconds, the output de-activates (shutting
off the cooling fan motor) and the elapsed time value remains at
120 seconds until the input re-activates, at which time it resets back
to zero.
The following timing diagrams compare and contrast on-delay with
off-delay timers:
PLC INPUT AND OUTPUT INSTRUCTIONS:
Types of Instructions in PLC
1. Input instructions: These instructions read the status of input devices,
such as sensors or switches, and store the data in memory.
2. Output instructions: These instructions control output devices, such as
motors or valves, based on the data stored in memory.
PLC SEQUENCE INSTRUCTION:
Programming a Sequencer in Ladder Logic on a PLC is an
advanced skill. It's a technique that utilizes SQO instructions in
order to create a sequence of events that is based on specific
steps & allows the PLC to follow a prescribed sequence of
events.
The PLC Sequencer Instruction (SQO) is an output instruction. SQO
instructions can perform the same specific “ON” or “OFF” patterns of
outputs that are continuously repeated. The sequencer output (SQO)
instruction can be used to control output devices sequentially. The
desired sequence of operation is stored in a data file or array, and
this information is then transferred sequentially to the outputs.
File :
Address of the reference sequencer file
Mask :
The address of the mask word or file through which the instruction
moves data.
Dest :
Address of the output word or file for a SQO to which the
instruction moves data from its sequencer file
Control :
Instruction’s address and control element (3 words) that stores the
status byte of the instruction, the length of the file, and the position
in the file.
Length :
Number of steps of the sequencer file starting at position 1.
Position :
The word location or step in the sequencer file from/to which the
instruction moves data.
Refer the below Block,
On successive false-to-true transitions, the SQO instruction moves a
step through the programmed sequencer file, transferring step data
through a mask to a destination word. The done bit is set when the
last word of the sequencer file is transferred. On the next false-to-
true transition, the instruction resets the position to step one.