C S O I F: Hapter IX Ther Mportant Unctions
C S O I F: Hapter IX Ther Mportant Unctions
1
Jump and Call
1. Jump
The jump instruction enables part of a program to be jumped over if
certain conditions are met. When there is an input to Input 1, its contacts
close and there is an output to the jump relay. This then results in the
program jumping to the rung in which the jump end occurs and skipping
the intermediate program.
2
In Mitsubishi program, the condition that the jump will occur is that
there is an input to X400. When that happens, the rungs involving inputs
X401 and X403 are ignored and the program jumps to continue with the
rungs following the end-jump instruction with the same number as the
start-jump instruction—in this case, EJP 700.
3
Jumps Within Jumps
4
2. Subroutines
Subroutines are small programs to perform specific tasks that can be
called for use in larger programs. The advantage of using subroutines is
that they can be called repetitively to perform specific tasks without
having to be written out in full in the larger program.
5
With a Mitsubishi program, when input 1 occurs, the subroutine P is
called. This is then executed, the instruction SRET indicating its end and
the point at which the program returns to the main program.
6
Timers
In many control tasks there is a need to control time. For example, a motor
or a pump might need to be controlled to operate for a particular interval of
time or perhaps be switched on after some time interval. PLCs thus have
timers as built-in devices. Timers count seconds or fractions of seconds
using the internal CPU clock.
7
Types of Timers
There are a number of different forms of timers that can be found with
PLCs:
On-delay timer,
Off-delay timer,
Pulse timer.
On-Delay Timers
On-delay timers (TON) come on after a
particular time delay. Thus as the input IN
goes from 0 to 1, the elapsed time starts to
increase, and when it reaches the time
specified by the input PT, the output Q goes
to 1.
Siemens
9
Toshiba
Telemecanique
Allen-Bradley 10
Example 1: Sequencing
The figure shows how timers
can be used to start three
outputs, such as three motors,
in sequence following a single
start button being pressed.
When the start push button is
pressed, there is an output
from internal relay IR1. This
latches the start input. It also
starts both timers, T1 and T2,
and motor 1. When the preset
time for timer 1 has elapsed,
its contacts close and motor 2
starts. When the preset time
for timer 2 has elapsed, its
contacts close and motor 3
starts. The three motors are all
stopped by pressing the stop
push button. Since this is seen 11
as a complete program, the end
instruction has been used.
Example 2: On/Off Cycle Timer
The figure shows how on-delay timers can be used to produce an on/off
cycle timer. The timer is designed to switch on an output for 5 s, then off
for 5 s, then on for 5 s, then off for 5 s, and so on. When there is an input to
In 1 and its contacts close, timer 1 starts. Timer 1 is set for a delay of 5 s.
After 5 s, it switches on timer 2 and the output Out 1. Timer 2 has a delay of
5 s. After 5 s, the contacts for timer 2, which are normally closed, open. This
results in timer 1 in the first rung being switched off. This then causes its
contacts in the second rung to open and switch off timer 2. This results in
the timer 2 contacts resuming their normally closed state, and so the input
to In 1 causes the cycle to start all over again.
12
Off-Delay Timers
13
Pulse Timers
Pulse timers are used to produce a fixed-
duration output from some initiating input.
This timer gives an output of 1 for a fixed
period of time, starting when the input goes
from 0 to 1 and switching back to 0 when the
set time PT has elapsed. The figure shows
the IEC symbol.
The figure shows how a on-delay timer can be used to produce a pulse timer.
There are two outputs for the input In 1. When there is an input to In 1,
there is an output from Out 1 and the timer starts. When the predetermined
time has elapsed, the timer contacts open. This switches off the output.
14
Example 3: Flashing light
Consider a program that could be used to flash a light on and off as long as
there is some output occurring. Thus we might have both timer 0 and timer
1 set to 1 s. When the output occurs, timer 0 starts and switches on after 1
s. This closes the timer 0 contacts and starts timer 1. This switches on after
1 s and, in doing so, switches off timer 0. In so doing, it switches off itself.
The lamp is on only when timer 0 is on, and so we have a program to flash
the lamp on and off as long as there is an output.
Input
15
Counters
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.
Forms of Counter
There are two basic types of counter:
down-counters
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.
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. 16
17
Different PLC manufacturers deal with counters in slightly different ways.
Some treat the counter as though it is a relay coil and so a rung output
(Mitsubishi). In this way, counters can be considered to consist of two basic
elements: one relay coil to count input pulses and one to reset the counter,
the associated contacts of the counter being used in other rungs.
18
The figure shows a basic counting circuit. Each time there is a transition
from 0 to 1 at input In 1, the counter is reset. When there is an input to In 2
and a transition from 0 to 1, the counter starts counting. If the counter is
set for, say, 10 pulses, then when 10 pulse inputs, that is, 10 transitions
from 0 to 1, have been received at In 2, the counter’s contacts will close and
there will be an output from Out 1. If at any time during the counting there
is an input to In 1, the counter will be reset, start all over again, and count
for 10 pulses.
19
The figure shows how the preceding program would appear with
Mitsubishi, Siemens, and Toshiba PLCs.
20
Example: Counting products
Consider the problem of the control of a mach-
ine that is required to direct six tins along one
path for packaging in a box and then 12 tins
along another path for packaging in another
box.
21
When there is a pulse input to X400, both the counters are reset. The
input to X400 could be the push-button switch used to start the
conveyor moving. The input that is counted is X401. This might be an
input from a photocell sensor that detects the presence of tins passing
along the conveyor. C460 starts counting after X400 is momentarily
closed. When C460 has counted six items, it closes its contacts and so
gives an output at Y430. This might be a solenoid that is used to
activate a deflector to deflect items into one box or another. Thus the
deflector might be in such a position that the first six tins passing along
the conveyor are deflected into the six-pack box; then the deflector plate
is moved to allow tins to pass to the 12-pack box. When C460 stops
counting, it closes its contacts and so allows C461 to start counting.
C461 counts for 12 pulses to X401 and then closes its contacts. This
results in both counters being reset, and the entire process can repeat
itself.
22
Example: Up- and Down-Counting
Consider the task of counting products as they enter a conveyor line and as
they leave it, or perhaps cars as they enter a multistorage parking lot and
as they leave it. An output is to be triggered if the number of items/cars
entering is some number greater than the number leaving, that is, the
number in the parking lot has reached a “saturation” value. The output
might be to illuminate a “No empty spaces” sign.
25
Homework: three-cylinder, double solenoid-
controlled arrangement
It is required to design a program to enable a three-cylinder, double
solenoid-controlled arrangement to give the sequence A+, A–, A+, A–, A+, A–
, B+,C+, B–, C–. The A+, A– sequence is repeated three times before B+,C+,
B–, C– occur.
26
Shift Registers
A register is a number of internal relays grouped together, normally 8,
16, or 32. Each internal relay is either open or closed, these states being
designated 0 and 1. The term bit is used for each such binary digit.
Therefore, if we have eight internal relays in the register, we can store
eight 0/1 states. Thus we might have, for internal relays:
and each relay might store an on/off signal such that the state of the
register at some instant is:
With the shift register it is possible to shift stored bits. Shift registers
require three inputs: one to load data into the first location of the
register, one as the command to shift data along by one location, and one
to reset or clear the register of data.
27
To illustrate this idea, consider
the following situation where we
start with an 8-bit register in the
following state:
Suppose we now receive the inp-
ut signal 0. This is an input sig-
nal to the first internal relay. If
we also receive the shift signal,
the input signal enters the first
location in the register, and all
the bits shift along one location.
The last bit overflows and is lost.
The figure shows the IEC 1131-3 standard symbol for a shift register. The
value to be shifted is at input IN and the number of places it is to be shift-
ed is at input N.
28
Ladder Programs
29
The figure shows a shift register ladder program
for a Toshiba PLC. With the Toshiba, R016 is the
address of the first relay in the register. The (08)
indicates that there are eight such relays. D is
used for the data input, S for shift input, E for
enable or reset input, and Q for output.
30