4 Basic PLC Programming
4 Basic PLC Programming
Ladder diagram:
Ladder diagrams are the most commonly used diagrams for nonelectronic control
circuits. They are sometimes called elementary diagrams or line diagrams. Two types
of ladder diagrams are used in control system: the control ladder diagram and the
power ladder diagram. The control ladder diagram has two active functional lines.
Some of the common practices for the format of control ladder diagram are
illustrated by this figure. Those practices are as follows: refer fig 4.1
Fig. 4.1
All coils, pilot lights and other outputs are on the right.
An input line can feed more than one output. If it does the output are
connected in parallel.
Switches, contacts and other devices are inserted in the ladder line starting
on the left.
Sequence listing:
The control ladder diagram in fig 4.1 has an operating sequence as follows:
OR
4. Add sensor on the sketch as needed to carry out the control sequence.
6. Consider the safety of the operating personnel and make additions and
adjustments as needed.
8. Create the ladder logic diagram that will be used as a basis for the PLC
program.
9. Consider the what ifs where the process sequence may go astray.
3. The flowchart shows the points of decision, relevant operations, and the
sequence in which they should take place to solve the problem.
5. Most flowcharts use four basic symbols: oval, diamond, rectangle, and
parallelogram. In addition, connection arrows are used to connect the various
symbols.
a. The oval symbol indicates either the beginning or end of the program.
Q. List the five major type of registers. Use a block diagram to show where
each type fits into the PLC scheme of operation.
Holding registers
Input registers
Input Group registers
Output registers
Output Group registers
Though there are many types of timer functions available in PLCs, the following
three are most commonly found:
The Timer On Delay instruction begins to count time base intervals when rung
conditions become true.
As long as rung conditions remain true, the timer increments its accumulated
value (ACC) according to time base interval until the accumulated value
reaches the preset value (PRE).
The accumulated value is reset when rung conditions go false, regardless of
whether the timer has timed out.
The Timer On Delay has three control bits.
o Done (DN): This bit is on when the Accumulated value = Preset Value
o Timer Timing (TT): This bit is on when the timer is timing.
(Accumulated value < Preset Value)
o Enabled (EN): This bit is on when the timer is energized.
For a grinding operation on a metal part, the coolant flow on the part must be
on for an interval before the grinding process starts.
When the process circuit is turned on, the coolant motor (CM) is turned ON.
Eight seconds later the grinding process (GM) starts.
The Timer Off Delay instruction begins to count time base intervals when the
rung makes a true to false transition.
As long as rung conditions remain false, the timer increments its accumulated
value (ACC) until it reaches the preset value (PRE).
The accumulated value is reset when rung conditions go true regardless of
whether the timer has timed out.
Similar to TON, The Timer Off Delay has three control bits.
o Done (DN): This bit is on when the Accumulated value = Preset Value
o Timer Timing (TT): This bit is on when the timer is timing.
(Accumulated value < Preset Value)
o Enabled (EN): This bit is on when the timer is energized.
A motor and its lubrication pump motor are both running when the switch is
turned ON. Lubrication for the main motor bearings is required during motor
coast-down.
After the main motor is shut OFF, the lubricating pump remains ON for a time
corresponding to coast-down time. In this example, the lubricating pump
remains ON for 15 seconds after main switch is shut down.
Rung 1: When start button is pressed main motor output O: 0/0 is ON.
Rung 2: When output O: 0/0 is ON, its auxiliary contact with same address gets
closed which starts the Off Delay Timer T4:0.
Rung 3: When OFF delay timer gets supply its DN bit is set which turn ON the
output O: 0/1 i.e. lubrication motor.
When stop button is pressed then main motor will shut down immediately i.e.
output O:0/0 turn OFF and its contact gets open. Now supply to Off Delay Timer
goes OFF but its DN bit gets open after 15 seconds so lubrication motor remains
ON for 15 seconds when main motor is OFF during coast down time.
Counters are provided as built-in elements in PLCs and allow the number of
occurrences of input signals to be counted. Some uses might include where
items have to be counted as they pass along a conveyor belt, the number of
revolutions of a shaft, or perhaps the number of people passing through a
door.
A counter is set to some preset number value and, when this value of input
pulses has been received, it will operate its contacts. Normally open contacts
would be closed, normally closed contacts get opened.
There are two basic types of counter: down-counters and up-counters. Down-
counters count down from the preset value to zero, that is, events are
subtracted from the set value. When the counter reaches the zero value, its
contacts change state. Most PLCs offer down-counting.
Up-counters count from zero up to the preset value, that is, events are added
until the number reaches the preset value. When the counter reaches the set
value, its contacts change state.
Counter Number: For the example shown, the counter number is C5: 0
which represents counter file 5, counter 0 in that file. Subsequent counters
will be numbered as C5:1, C5:2, etc.
Preset Value: The preset value can range from -32768 to + 32767. In the
example shown the preset value is 10.
Accumulated Value: The accumulated value can also range from 32768
through +32767. Regardless of what value is entered, the reset instruction
will reset the accumulated value to 0.
Arithmetic instructions:
1. Addition (ADD):
ADD instruction will retrieve values from source A and source B convert both
values to the type of destination address, then value of source A is added to
the value of source B and store the result in destination address.
Therefore, ADD instruction first convert values of both the sources to floating
point number.
Then add both the values and result is floating point number which stored in
the destination address.
2. Subtraction (SUB):
Instruction retrieve values from source A and source B, convert both values to
the type of destination address, then value at source B is subtracted from the
value of source A and then store the result in the destination.
The shortened notation for this instruction is SUB (value, value, destination)
3. Multiply (MUL):
Instruction convert both the values to the type of destination address and
then value of source A is multiplied by the value of source B and store the
result in destination address.
The shortened notation for this instruction is MUL (value, value, destination)
4. Divide (DIV):
Instruction convert both the values of source A and source B to the type of
destination address and then value of source A is divided by the value of
source B and store the result in destination address.
The shortened notation for this instruction is DIV (value, value, destination)
5. Negate (NEG):
The value of source is subtracted from zero and then result is stored in
destination address.
The first SUB function retrieve the values from N7:0 and N7:1 then subtract
value of N7:1 from value of N7:0 and store the result in N7:2
The second NEG function change the sign of result of first function in N7:2
and store the result in N7:3
The third MUL function multiply the value of N7:0 by the value of N7:1 and
store the result in N7:4
Next DIV instruction divide the integer value in N7:1 by the integer value in
N7:0, the result is rounded to the nearest integer and store in N7:5
For example if the values of N7:0=5 and N7:1=25 then results are,
N7:2=-20, N7:3=20, N7:4=125 and N7:5=5.
A= Log B + Sin C.
Assign A= F8:0, B=F8:1 and C=F8:2. This equation can be expressed by CPT
function as shown in figure.
Many PLCs have only two COMPARE functions: equal (EQ) and greater than
or equal to (GE). To perform any one of the other four functions (not equal,
less than, greater than, and less than or equal to), combinations of the basic
two are used.
Sr. No. Function Equation Symbol
1 Equal A=B EQ
Greater than or
3 AB GE
equal to
Less than or
6 AB LEQ
equal to
We are banding dowel pins into bundles of 40. A counter function (not
shown) keeps track of the count of the number of dowel pins in the bundle
as they are added.
The dowel pin counters count number is kept in HR0005.
The running count is compared to 40, as shown in figure. When the count
reaches 40, the comparison is true, and the output, CR0019, goes on.
Output CR0019 is connected to a bander that operates when 40 is reached.
As the bottle starts filling, as long as the pill count is less than 225, the
comparison is untrue and output CR0030 is OFF.
Once the pill count reaches 225, CR0030 goes ON. Output CR0030 is
connected to a cap-and-remove operation. The bottle is capped and
removed, and the process is reset and can be repeated.
Why not use an equal-to function for this example? EQ would probably work,
but what if the process overshoots? Suppose the count somehow got to 226.
The fill would go on unabated. However if we use the GE function, the fill
process would not erroneously continue even if the count got to 226.
When the SKIP function (set at 3) is turned on, the first two lines will function
as usual. However, the next three lines, 4 through 6, will stay on or off in
their previous state. With SKIP on, changing the input on-off status feeding
the coils on lines on lines 4 through 6 will have no effect on output coils 4
through 6. Coils on lines 4 through 6 will retain their previous states.
Lines 7 and 8 could also be skipped if we had inserted a 5 in place of 3 as the
number of lines to be skipped by the function. When SKIP is turned off, the
ladder will operate normally.
Figure shows how the MCR function operates in a program. There are eight
lines. The third line is the MCR function. The other seven lines are contact-coil
functions.
When MCR is on, the other seven lines operate normally. When MCR is off,
the next three lines, 4 through 6, are turned off. Lines 1, 2, 7 and 8 are
unaffected.
With MCR off, there is no way to turn on coils 4 through 6 by energizing their
enable lines. When MCR is turned on, the ladder operates in the normal
manner.
For a jump to take place there must be a place to jump from and a
place to jump to. For this, the jump (JMP) and label (LBL) instructions
go together. The JMP is placed in the rung where the leap is to occur;
while LBL is the target of the leap. Thus a jump jumps to a label. Both
the jump and label must have the same address.
Figure shows the nonreturn JUMP function. If input 121 (line 17) is on
(true), the program will jump to the next line where an LBL is found (line
22). Since lines 18 through 21 are not scanned by the processor, input
conditions are not examined and outputs controlled by these rungs remain
in their last state. If input 121 is off (false), the program continues directly
to line 18.
It is possible to jump to the same label from multiple jump locations.
is true, the subroutine is called. Where is the subroutine? At the label (LBL) in
the subroutine area.
Note that JSR and LBL addresses are the same. When the subroutine is
completed, an unconditional return to the main program must take place. The
return is always to the rung following the JSR in the main program.
As shown in figure, lines 21 through 23 are part of the main program. When
input 121 is true, a jump to a subroutine at LBL, on line 107, takes place.
Lines 107 through 110 contain the subroutine. When the return command
(RET) is encountered, the subroutine returns to line 23 in the main program.
MOVE function
BLOCK TRANSFER function or TABLE-TO-TABLE function
TABLE-TO-REGISTER (TR) function
REGISTER-TO-TABLE (RT) function
It is sometimes necessary to move more data than the quantity that will fit
into one address. One option is to use a number of individuals MOVE
functions.
But instead of that we can use a single BLOCK TRANSFER function that will
move many consecutive registers data at once.
Suppose we need to move 147 bits from one location to another but we only
have 16-bit registers available. We would need to use nine full 16-bit registers
(16x9=144 bits) plus part of another register (3 bits). In this case, one BLOCK
TRANSFER function does the work of ten MOVE functions.
Figure illustrates the BLOCK TRANSFER function. In the functional block
following things are specified.
o Number of registers to be moved
o Source end register
o Destination end register
The function is enabled when the lower input line is on. When the middle line,
Reset is turned off, the function is reset to first register. When the reset is on,
the function is operational and can be stepped. The top line is step line.
Whenever step line is turned on, the function transfers data and moves down
one register.
The function is enabled when the lower input line is on. When the middle
line, Reset is turned off, the function is reset to first register. When the
reset is on, the function is operational and can be stepped. The top line is
step line. Whenever step line is turned on, the function transfers data and
moves down one register.
The FIFO function retrieves the data in the order in which it was stored.
The FIFO function consists of two subfunctions. To put data into a stack, a
function denoted FIFO Load (FFL) is used. To take data out of the stack, a
function denoted FIFO Unload (FFU) is used.
Both FFL and FFU functions are used in combination to accomplish FIFO.
The first time FFL is activated, it will grab the word (16 bits) from the input
card I:001 and store them on the stack, at N7:0. The next value would be
stored at N7:1, and so on until the stack length is reached at N7:4.
When the FFU is activated the word at N7:0 will be moved to the output card
O:003. The values on the stack will be shifted up so that the value previously
in N7:1 moves to N7:0, N7:2 moves to N7:1, etc.
If the stack is full or empty, and a load or unload occurs the error bit will be
set R6:0/ER.
The LIFO function retrieves the data in the reverse order in which it was
stored.
The LIFO function consists of two subfunctions. To put data into a stack, a
function denoted LIFO Load (LFL) is used. To take data out of the stack, a
function denoted LIFO Unload (LFU) is used.
Both LFL and LFU functions are used in combination to accomplish LIFO.
As values are loaded on the stack, they will be added sequentially N7:0, N7:1,
N7:2, N7:3 then N7:4. When values are unloaded they will be taken from the
last loaded position, so if the stack is full the value of N7:4 will be removed
first.
The FILE ARITHMETIC AND LOGIC (FAL) function is useful when a complex
computation is performed on a series of data values.
Instead of programming a COMPUTE (CPT) function repetitively for each
group of data, we program only once for FAL function.
Then, for FAL, we specify the number of times the calculation should run
(length) and where the calculation process should start in a stack of data
values.
The FAL function is essentially a multiple, sequential CPT function which saves
programming time and program space.
N7:10=N7:0 - N7:21,
N7:11=N7:1 - N7:21,
N7:19=N7:9 - N7:21.
In the above example, if mode is SINGLE then one scan will perform one
calculation.