You are on page 1of 121

PLC Hardware

The Programmable Logic Controller abbreviated by PLC is a special microprocessor


based controlled system. Also it is a special type of computer capable of withstanding
vibration, higher temperature , higher humidity and optimized for control tasks in industrial
environment rather than calculation and display tasks assigned to the normal computer.
From the point of view of operation, the PLC uses battery supported programmable
memory to store user program’s instructions and to implement logic functions, arithmetic
functions, timing functions, counting functions, sequencing functions in addition to special
control functions like PID controller , high speed counting, and position control. To do the
application the PLC has being programmed to, the PLC reads the states of the field input
devices connected to its input strip, uses these information as the independent variables of
the user program function and updates the commands directed to the field output devices
connected to the its output strip.

The PLC system basically consists of seven functional components. As shown in fig.1,
these are the central processing unit , the memory, the input interface unit, the output
interface unit, the communication interface circuit. All communications between these PLC’s
main units take place via four buses: These are:

The data bus: This bus is used to transfer the data between the CPU , the memory, and the
input / output units.

The address bus: This one is responsible for transferring the address of the memory the data
will be send to or fetched from.

The control bus : The control bus controls and synchronize all the traffic between the PLC
main units.

The I/O System bus: This last bus is used for I/O communication.

Programming Input / Output


interface units
Unit Memory unit CPU

Communication
Power Supply
Unit
Unit

Fig.1: PLC System’s Functional Components


Central Processing Unit:

The CPU is considered as the PLC’s brain. It has the following items :

1- An arithmetic and control unit (ALU) responsible for carrying out arithmetic , logical
operations, and data manipulation on the data held in the memory according to
the instruction of the user program.

2- Memory registers to store information accompanied to the program execution.

3- Control unit to generate the timing signal required to synchronize and control all the PLC
activities.

Memory Unit :

It is the place where the program containing the control instructions is stored. Also it is
the place where data from inputs terminals and data for output terminals are stored. In
general , the PLC may have :

- Read only memory (ROM) to permanently store the PLC operating system .

- Random access memory (RAM) to store the user created program.

- Random access memory (RAM) to store data related to the input and output devices in
addition to that of timers, counters , and other internal devices.

As an illustrative example, Tables 1 and 2 show the random access memories embedded in
the high performance XGB basic unit .

To prevent the loss of the program and certain type of data when the power supply is
switched off , a battery is used in the PLC to maintain the user program RAM area and also
the data RAM marked as retain .
Table 1 : The user program memory embedded in the high performance XGB PLC

Item Size (KB) Details


Parameter Setting Area 120 - Basic Parameters
- I/O parameter Area
-Special Communication Module Parameter Area
-User Event, Trace Parameter Area
Program Saving Area 1024 -Scan Program Area 1,2
- Variable / Comment Area
System Area 156 - User Event Trace Data Area
- System Log Area
- Device Backup Area
Program Backup Area 1362 - Scan Program Area
- Task Program Area
- Upload Area
-Parameter Initialization Area
- Retain Parameter Assignment Area

Table 2 : Data memory embedded in the high performance XGB PLC

System Area: 20KB


- I/O information Table
- Forced I/O Table
- Reserved Area
Flag Area: 4KB
- System Flag (F) 768B
- Analog Image Flag (U) 16KB
- Internal Special Flag (K) 8KB
- High Speed Link (L)
Input Image Area (%I) 2KB
Output Image Area (%Q) 2KB
R Area (%R) 32KB
*2block
Direct Variable Area (%M) 32KB
Symbolic Variable Area 64KB
Input / Output Interface Units :

These units take mid position between the PLC internal digital circuitry and the outside
environment. They allow field input devices ( on/off switches, limit switches, proximity
switches, shift encoders, temperature transmitters, level transmitters, pressure transmitters,
etc ) to control the PLC digital inputs . They allow the PLC digital outputs to control the
field output devices (solenoid valves, magnetic relays, solid state relays, AC drives, stepper
drive, servo drives, etc). In addition to the above, these interface circuits provide signal
conditioning and isolation functions to protect the PLC and allow the input and output
signals to be directly connected without the need for any extra electronic circuitry. From the
point of view of PLC memory, each PLC input or output device has its unique address .
These addresses are what dealt with in the user program instructions.

PLC Digital Input Interface Circuit:

The signals applied to the PLC input strip points may be AC voltage signals ( 24VAC,
220VAC) may be DC voltage signals ( 12VDC , 24VDC) depending upon the PLC brand
selected. But the PLC internal voltage logic is 5VDC irrespective of the PLC brand so there
is a need for an electronic circuits to map the voltage signal applied to the PLC input strip
into the PLC internal 5VDC logic level. This is the function of the PLC digital input
interface circuits. Figs 2 to 5 display illustrative samples of PLC input interface unit
channels. Fig.2 represents an AC input channel which is fed from an AC type field input
device. Fig3 stands for sink type DC input channel which is supplied from source type DC
field input device. It is called so because the current flow from the field input device toward
the channel .Fig.4 is also DC input channel but this one is considered as source DC input
channel because of the current flow from the channel toward the field input device. Fig5
shows a DC channel which can works with both types of DC field devices.

SW

5VDC
R1 R2
AC R3 buffer
R4
Voltage C1 TO PLC Processor
Signal
C2

Fig. 2: AC Input Chanel


SW
5VDC

R1
buffer
R3

R2 C1

Fig. 3: DC Sink type Input Chanel

SW
5VDC

R1
R3 buffer

R2 C1

Fig. 4: DC Source type Input Chanel

SW

5VDC
DC R1
Voltage R3
buffer
Signal
R2 C1

Fig. 5: DC Source / Sink type Input Chanel


PLC Digital Output Interface Circuit:

The PLC internal output logic is restricted to the 5VDC logic which means the output
terminals of the PLC processor (output image register ) may be 0 or 5VDC irrespective of
the brand of the PLC used. The field output devices differ in their voltage need, some of
them must be powered using 12VDC source, some must be powered via 24VDC source,
some must be powered from 24VAC source, some from 220VAC source, some require
slow ON/OFF switching and some need fast ON/OFF switching, some has no surge current,
some has large surge current. The PLC processor digital output circuits have no problem
with the switching speed because of their dependence on transistor switches, the only
problems they have are the voltage type and current rating. As mentioned above ,they can
only supply low level discrete DC voltage output signal (0 or 5VDC). so there is a need for
an electronic circuits to map the processor digital output voltages in to that required by the
field output devices. To achieve such mapping and to provide some form of isolation barrier,
the PLC manufacturers supported their PLCs with digital output interface circuits. In this
context, there are three main types as shown in Fig6 to Fig9. Fig6 displays the relay type
output circuit. This type of output circuits are characterized by:

- Isolate the PLC processor output circuit from the external load circuit.

- Can be used with AC and DC external load circuits.

- It s switching frequency is low because of the mechanical nature of the relay.

- Can withstand high surge current and voltage transient because the element in contact with
the load circuit is metallic contact.

Fig7 and Fig8 show Source and sink type output circuits. both uses transistor to control
current flow in the field output devices. These output interface circuits are characterized by:

- Isolate the PLC processor output circuit from the external load circuit.

- Can only be used with DC circuits, because the transistor based switch allows one
current flow direction.

- Load over current and high reverse voltages may destroy such type of output interface
circuits.

Fig9 belong to the triac output interface circuit. It is characterized by:

- - Isolate the PLC processor output circuit from the external load circuit.

- Can only be used with AC circuits because of the triac type switching element.

- Load over current may easily destroy this type of output interface circuits.
5VDC 5VDC

Relay 220V/50Hz Relay 24VDC

%QX0.0.0
Load
˜ %QX0.0.1
Load

0V 0V
( a) (b)

Fig. 6: Relay type Input Chanel . a): AC Load. B): DC load

5VDC

12/24VDC

%QX0.0.1
Load

Fig. 7: Source type Output Interface


0V Circuit

5VDC Load

12/24VDC

%QX0.0.1

Fig. 8: Sink type Output Interface Circuit


0V
C
5VDC
220V / 50Hz

%QX0.0.1 Load

Fig. 9: Triac type Output Interface Circuit


0V

PLC Analog To Digital Input Interface Circuit:

The PLC analog input interfacing circuits convert current or voltage input signals
coming from field analog input devices (like voltage, current, temperature , speed, pressure,
flow, level, vibration, weight, and position transmitters) into digital data usually word data
types and assign these data to the PLC memory allocated for the analog input channels (in
case of XGB-XECU PLC type, this is defined by the prefix %UW ).

The typical nominal range for the accepted analog signals in XGB-XECU PLC are :

1: 0 – 20mA

2: 4 – 20mA

3: 0 – 5V

4: 1 – 5V

5: 0 – 10V

6: -10 – +10V

The digital data range representing the analog signals over their entire span can be selected
from more than one options. For example, in case of XGB-XECU PLC these are:

1: 0 – 16000
2: -8000 – 8000

3: 4000 – 20000

4: 0 – 10000%

Fig. 10 and Fig11 show how the 2 wire and four wire field transmitters are connected to
the PLC analog input channels .

A/D A/D
2 Wires Sensor / V0+ 2 Wires Sensor / V0+
Transmitter I0+ Transmitter I0+
COM COM
V1+ V1+
2 Wires Sensor / 2 Wires Sensor /
Transmitter I2+ Transmitter I2+
COM COM
V3+ V3+
2 Wires Sensor / 2 Wires Sensor /
Transmitter I3+ Transmitter I3+
COM COM
V4+ V4+
2 Wires Sensor / 2 Wires Sensor /
Transmitter I4+ Transmitter I4+
COM COM

(a) (b)

Fig.10: 2-Wire sensor/transmitter wiring. A: Current type. B: Voltage type


A/D A/D
4 Wires Sensor / V0+ 4 Wires Sensor / V0+
Transmitter I0+ Transmitter I0+
COM COM
V1+ V1+
4 Wires Sensor / 4 Wires Sensor /
Transmitter I2+ Transmitter I2+
COM COM
V3+ V3+
4 Wires Sensor / 4 Wires Sensor /
Transmitter I3+ Transmitter I3+
COM COM
V4+ V4+
4 Wires Sensor / 4 Wires Sensor /
Transmitter I4+ Transmitter I4+
COM COM

(a) (b)

Fig.11: 4-Wire sensor/transmitter wiring. A: Current type. B: Voltage type

PLC Digital To Analog Output Interface Circuit:

The PLC digital to analog output interfacing circuits convert the digital data stored in
the PLC memory allocated for the analog out channels (in case of XGB-XECU PLC type,
this is defined by the prefix %UW ) into analog output voltage or current signals.

The digital data range to be converted can be selected from more than one options. For
example, in case of XGB-XECU PLC these are:

1: 0 – 16000

2: -8000 – 8000

3: 1000 – 5000

4: 0 – 10000%

The typical nominal range for the generated analog signals in XGB-XECU PLC are :
1: 0 – 5V

2: 1 – 5V

3: 0 – 10V

4: -10 – +10V

Fig. 12 Show the analog voltage and current wiring.

A/D
V1
V0+ Analog Output Device
CM Input Resistance > 1KΩ
V0-
V1+ V1
Analog Output Device
V1- CM Input Resistance > 1KΩ

I0+
I1
I0- Analog Output Device
CM Input Resistance <600Ω
I1+
I1
I1- Analog Output Device
CM
NC Input Resistance <600Ω

NC
+
-

Fig.12:
BINARY STATE SENSORS & ACTUATORS

CHAPTER 4
.
BINARY STATE SENSORS & ACTUATORS

The universe of discourse includes a lot of what can be described by two states (0,1).
Read/write, start/stop, open/close, key/lock, forward/backward, up/down, left/right,
release/block, enter/exit, clockwise/counterclockwise, on/off, high/low,
full/empty, shine/dark, are all examples of two state expressions used to command two
values actions or express the state of binary entities. These are the words needed in the
construction of many process control algorithms. But as linguistic words neither the
machinery nor the process controllers can understand. So to create an automated
environment with full understanding between the human being, machinery, and process
controllers a certain type of translation or interfacing should be sandwiched between the
different entities. The binary state input devices ( sensors) are the translators that inform
the controller the states of the process whereas the binary output devices (actuators) play
the translation role between the controllers and the machinery.

4.1: Sensors

Sensors are input type devices have the ability to represent the value or state of a chosen
parameter in a form suitable for decision making in programmable controllers. Binary
sensors set includes many different types of switches ( too many to cover). Hand operated
switches, limit switches, inductive proximity switches, capacitive proximity switches, photo
electric switches, magnetic switches, temperature actuated switches, pressure actuated
switches, float switches, mercury switches, and shaft encoders are examples of the sensors
set items.

4.1.1 :Hand Actuated Switches.

Human operator actuated switches share the same opening and closing functions but they
differ in their shapes and activation / inactivation mechanism. The shape and activation /
inactivation determine the application area. From these points of view, these switches can be
classified into:

Shrouded Actuator Pushbuttons

These are finger tip actuated pushbuttons. They have an activation area surrounded or
shrouded by hard sleeve to prevent unintended depressing of the button. The depressing is
only possible by an object smaller than the sleeve. With finger tip it is possible to access the
activation area but with hand palm, the sleeve blocks the entrance and no activation can
take place. There are two types of these pushbuttons, the black or green colored
normally open pushbutton and the red colored normally closed one. For both of
them, the activation is done by depressing the actuator against the internal spring
whereas inactivation occurs when removing the depressing object and allowing the spring
to lift up the actuator. For the normally open one the activation bridges the button’s two
terminals where as the inactivation isolates these two terminals creating an open
BINARY STATE SENSORS & ACTUATORS

circuit between them. In the case of normally closed one the activation does the
reverse, it pushes away the metallic conducting bar creating an open circuit between the
button’s terminals and the inactivation returns the bar to its initial position and this in turn
leads to bridge the button terminal again. Figs. 4.1and 4.2 present the real pictures of
these pushbuttons, the schematic diagram of their internal configuration under pressed and
released situations, and their circuit symbols respectively.

(a) (b) (c) (d)


Fig. 4.1: Shrouded actuator ON pushbuttons. (a) : Real picture . (b): Behavior under
normal condition . (c): Behavior under pressed condition (d) : Circuit symbol

(a) (b) (c) (d)


Fig. 4.2: Shrouded actuator OFF pushbuttons. (a) : Real picture . (b): Behavior under
normal condition . (c): Behavior under pressed condition. (d) : Circuit symbol

Extended Actuator Pushbuttons

These are similar in operation to their predecessors and share the same circuit samples
but differ in their actuator shapes. Here the activation area is extended beyond the sleeve
and this lead to an easy activation. They can be activated by objects smaller than their
actuators like finger tip and also by object larger than their actuators like hand palm or
more than one finger. Figs 4.3 and 4.4 display the external appearance of this type of
pushbutton along with the operational behavior under pressed and released situations.
BINARY STATE SENSORS & ACTUATORS

(a) (b) (c)

Fig. 4.3: Extended actuator ON pushbuttons. (a) : Real picture . (b): Behavior
under normal condition . (c): Behavior under pressed condition

(a) (b) (c)

Fig. 4.4: Extended actuator OFF pushbuttons. (a) : Real picture . (b): Behavior
under normal condition . (c): Behavior under pressed condition

Palm Actuator Pushbuttons

The palm actuated ON/OFF switches or simply mushroom switches have mushroom
head like actuating shapes and internal springs to return them to their normal situations
after lifting the depressing objects. Their mushroom head activation area is wide enough
and smooth to be easily pressed by the operator. The operators can activates them
comfortably by their palms. Usually they are used for making or breaking electrical circuit
for short time periods. In general, their structure is suitable for ON/OFF applications that
occur tenth times per day. Fig4.5 shows the single circuit and double circuit versions of
these types of push buttons along with their circuit symbols.
BINARY STATE SENSORS & ACTUATORS

(a) (b)

Fig.4.5: Palm actuated pushbuttons. (a) : Single circuit type. (b): Double circuits type

Emergency Stop Pushbuttons

The emergency stop push buttons adopt the mushroom or palm type actuators to enable
their users to activate them easily and quickly using any part of their bodies they can use at
the time they need to activate these buttons. Always the mushroom type buttons used for
emergency stop purposes are red colored and provided with detention or position
maintaining mechanism to keep the switch in the active state ( after being depressed )
until later released by the operator by pulling its actuator up or rotating it in a specific
direction marked on the activation face. Fig. 4.6 display samples of these emergency stop
push buttons

(a) (b)

Fig.4.6:Emergency stop pushbuttons. (a): Rotate to release. (b): Pull up to release.


BINARY STATE SENSORS & ACTUATORS

Two and Three Selector Switches

These hand actuated switches are also called rotary switches because their operational
states depend upon the direction at which their lever are rotated. Some of these
switches take one of two positions where as the others can be turned right, center, or left to
open or close the electric contacts.

The first two position category is subdivided into two sub categories, one with one set of
contacts and the other with two sets of contacts. The one with one set of contacts (Fig.7-a)
behave either as short circuit through bridging its set’s two contacts or as an open circuit
through breaking the continuity between its set’s two contacts. The one with two sets of
contacts(Fig.7-b) has four connection points, two for the first contact set and two for the
second contact set. As stated earlier, this switch toggles between one of two position. In the
first position, one of the sets say “A” is forced to closes its two contacts to create short
circuit and the second say “B” is forced to open its two contacts to create open circuit

The three positions category one (Fig. 7-c) has two contact sets and can be positioned in
one of three positions left position, middle position, and right position. Here in the left
position one of contact sets say “A” is opened and the second one say “B” is closed, in
the middle position both A and B are opened, and in the right position A is opened and B is
closed.

(a) (b) (c)

Fig.4.7: Samples of Selector switches.


BINARY STATE SENSORS & ACTUATORS

4.1.2 : Mechanical Limit Switches.

Mechanical Limit switches are contact sensing devices used to detect the arrival or
departure of relatively low speed moving objects in industrial applications. They are called
so because when an object makes contact with the actuator of the switch , it eventually
moves the operating mechanism to the limit where the switch electrical contacts change
their states, the normally closed one becomes open and the normally open one becomes
closed. Most of the mechanical limit switches consist of four items. These are:

- The actuator : It is that part of the switch which comes in contact with the moving
object.

- Operating head : The operating head which is attached to the actuator allows the rotary,
linear, or perpendicular movement to open and close the switch’s contacts.

- Electrical Contacts and their terminals : Usually, the mechanical limit switches are
provided by two sets of contacts. One set is of normally open contact type, and the other
of normally closed contact type.

- The container : It is also called the switch body and it is where the contacts and their
connecting terminals are mounted.

Broadly, mechanical limit switches are classified into lever type actuator and plunger type
actuator. Fig.4.8 introduces samples of these two types.

(a): Lever type sample (a): Plunger type samples sample

Fig.4.8: Samples of Limit Switches


BINARY STATE SENSORS & ACTUATORS

4.1.3: Proximity Sensors.

Proximity sensors are solid state electronic devices used to detect the presence or
absence of an object without any real contact. They are activated/deactivated depending
upon the nearness or closeness of the object being detected to the sensor face. There are
four fundamental types of proximity sensors, the inductive proximity sensor, the capacitive
proximity sensor, the photoelectric proximity sensor, and the ultrasonic proximity sensor. All
these solid state devices are well protected against vibration, liquids, and corrosive agents
in the industrial environment.

Inductive Proximity sensors

As their names imply, inductive proximity sensors are used to detect the presence
or absence of metallic objects. The sensor as a package consists of LC oscillator,
signal evaluator, and switching amplifier ( see figure 4.9a). The operating principle is that
when a metallic object comes close to the changing magnetic field created by the LC
oscillator, eddy current will flow in the coming object causing an ohmic power loss. This
power loss loads the oscillator. As the object moves nearer, the loading effect increases
causing more reduction in the oscillator output. When the oscillator output reduction
drops below the threshold level, the signal evaluation circuit triggers the switching
output amplifier to change the binary state of the sensor. The label assigned to the
sensor depends upon the switching amplifier output transistor. If the output transistor is PNP
type, the sensor is called PNP or current-sourcing sensor ( figure 4.9b). If it is NPN
transistor, the sensor takes the label of current-sinking ( figure 4.9c).

Metallic LC Circuit Signal Switching

Object Oscillator Evaluator Amplifier

(a)

Proximity Sensor Proximity Sensor


Circuitry Circuitry
Load
Load

(b) (c)
Fig.4.9: Inductive Proximity Sensor.
BINARY STATE SENSORS & ACTUATORS

Capacitive Proximity sensors

Capacitive proximity sensors are similar to inductive proximity sensors except that
in capacitive type sensors the target material varies the capacitance of the RC oscillator
whereas in the inductive sensor metallic target varies the inductance of the LC oscillator.
Here the sensor package consists of

- An RC oscillating circuit for which the capacitor plates are part of the sensor itself ( Fig.
4.10a) or the capacitor plates are distributed between one plate at the sensor face and the
other is the earthed fixture (earthed machine cover or mounting bracket ) to which the sensor
is attached (Fig.10b).

- Capacitance change evaluation circuit: The capacitance of any plate type capacitor is
function of the area of the plates, the distance separating the plates, and the permittivity of
the dielectric sandwiched between the plates(C= εo εr A/d ). In general in this type of sensor,
the plates area is fixed so the only parameters that may change the capacitance are the
permittivity ( εr ) and separation distance (d). So any object that affect any one of these
parameters will causes change in oscillator capacitance. The capacitance increases as the
permittivity increases or the separation distance decreases. The capacitance decreases as the
permittivity decreases or the separation distance increases.

- Switching amplifier : when the change in the capacitance comes above certain value, the
evaluation circuit turns the output power transistor ON to connect the load either to the
positive terminal of the dc supply in case of PNP type sensor (Fig.4.10c) or connecting the
load to the negative terminal of the dc supply in case of NPN type sensor (Fig.4.10d).
When the capacitance change drops below a threshold limit, the switching amplifier is turned
OFF.

There are two types of capacitive sensors . These are the:

- dielectric type in which the capacitor plates are built in parts of the sensor. Here the target
object only affect the permittivity parameter because both the area and the separation
parameters are fixed. These types can be used for conductive and non conductive materials.

- Conductive type in which the sensor contributes only in one plate and the other belong to
the metallic structure to which the sensor is attached, here the target object is of conducting
nature (like metal, salt water, blood, acids, etc. ) and it affects the separation distance .
BINARY STATE SENSORS & ACTUATORS

Dielectric
RC Circuit Signal Switching
object
Oscillator Evaluator Amplifier

(a)

Sensor built in plate

Metallic object

Earthed fixture as second


plate
(b)

Proximity Sensor Proximity Sensor


Circuitry Circuitry
Load
Load

(b) (c)
Fig.4.10: Capacitive Proximity Sensor.

Photoelectric Proximity sensors

Photoelectric proximity sensors are also another type of position sensors. They are used
to sense the presence or absence of an object at predetermined positional point. They use
light-emitting diodes to generate modulated light waves, phototransistors or photodiodes
to detect the transmitted or reflected light waves, and switching electronic circuits to
manipulate and evaluate the detected signal to decide whether to switch ON or switch OFF
the burden connected to the sensors output. The light transmitter and receiver are
positioned in such a way that the presence of the object under monitoring either blocks
or reflects the emitted light beam. Fundamentally there are three types of optical
BINARY STATE SENSORS & ACTUATORS

sensors. These are the thru-beam optical sensor, the retro-reflective optical sensor, and the
diffuse-reflective optical sensor.

Thru-Beam optical sensor

The transmitter and receiver of the thru-beam sensor are housed in different cases that are
separated from each other ( figure 4.11). Both the transmitter and receiver are provided
with focusing lenses and are aligned in such a way that the greatest amount of pulsed light
reaches the receiving unit. The transmitter emits light pulses to the receiver. When the light
pulses are interrupted by the virtue of presence of opaque or reflective object, the switching
action in the receiving unit is fired.

When using this type of sensor the following should be observed:

- It cannot be used to detect transparent objects.

- Vibration may create alignment problems and causes malfunction.

- The target size should be greater or equal to the lenses diameter.

- The maximum sensing distant is module dependent but it may reach to meters.

Transmitter Receiver

Internal
Electronics
Load

(a)

Transmitter Receiver

Target
Internal
Electronics
Load

(b)
Fig.4.11: PNP Type Thru-Beam Optical Sensor. (a): No target. (b): Under presence of target
BINARY STATE SENSORS & ACTUATORS

Diffuse-reflective optical sensor

In diffuse-reflective optical sensor, the emitter and receiver are located in single
housing and the target itself is responsible for reflecting the light beam back to the
sensing unit. Here the emitter should be placed perpendicular to the target ( Fg.4.12),
whereas the receiver is positioned at some angle to be able to receive the reflected light.
Target presence reflects the transmitted light signal causing the triggering of the switching
function. Target absence allows the light beam to travel far from the receiver and generates
no switching signal.

When using this type of sensor the following should be observed:

- It cannot be used to detect transparent objects or objects with low reflectivity..

- It does not work if the background has lighter color than the object.

-The shape, the color of the object, and its background have an effect on how well it works. .

- The maximum sensing distant is small ( within one meter).

Transmitter
Internal
Electronics Receiver

Load

(a) : Target is absent

Transmitter
Internal
Electronics Receiver

Load

(b) : Target is present

Fig.4.12: PNP Type Diffuse-Reflective Optical Sensor.


BINARY STATE SENSORS & ACTUATORS

Retro-reflective optical sensor

the retro-reflective sensor has both the emitter and receiver housed in single housing like
the diffuse-reflective type. As it is clear from Fig.413, it has a reflecting item to reflect
the light beam toward the receiver . The target presence blocks the light being
received and fires the switching function. This type of sensors does not work well
with glossy and reflective objects. To overcome this problem with glossy and reflective
objects that reflect the light as if they were a reflectors, a linear polarizing filters are located
in front of the transmitter and the receiver. The polarization planes of these filters are
perpendicular to each other. With this modified structure, only light beams passing
through the transmitter polarization filter, reflector, and the receiver polarization filter can
reach the receiver unhindered.

- When using this type of sensor the following should be observed:

- The detecting distance is large and reaches 20 meters.

Transmitter
Internal
Electronics Receiver

Load

(a) : Target is absent

Transmitter
Internal
Electronics Receiver

Load

(b) : Target is present

Fig.4.13: PNP Type Retro-Reflective Optical Sensor.


BINARY STATE SENSORS & ACTUATORS

4.1.4 Reed Switch

The word "reed" refers to a piece of thin and upright cane and it also refers to electrical
contact used in magnetically operated switch. Here both meaning are of key importance, the
first refers to springy feature and the second to conductive feature and these are what the
reed switch contacts must be characterized with. The reed switch consists of two strips
of springy ferromagnetic materials (e.g. iron-nickel) with their contacting ends coated
with plating material (e.g. rhodium). These strips are sealed in inert gas filled glass or
plastic capsule and are available in different sizes and shapes ( Fig.4.14 ).

Fig4.14:

Functionally, these switches came to control the making and breaking of electric circuit, so
structurally they may be of normally open, may be of normally closed, and may be
combination of these two. All of these switches are activated or driven by either permanent
magnetic field or current carrying coil created field (electromagmatic field). Their behavior
depend upon the way the magnetic field moves toward them or leaves them.

To get an idea about the operation of reed switches, the following cases would be
introduced:

Case 1: Normally open reed switch behavior under forward and backward movement of
the permanent magnet with the movement direction is perpendicular to the switch
plan ( Fig.4.15).

When the permanent magnet reaches point B, the reed contacts close by snap close action
because the field force exceeded the Pull-in force. The returning back to point A opens the
contacts when field force drops below the pull-out value.
BINARY STATE SENSORS & ACTUATORS

N S A A

N S
B B

(a) (b)

Fig.4.15: Normally open reed switch . (a): Magnet is far. (b): Magnet is close.

Case 2: : Normally close reed switch behavior under forward and backward movement of
the permanent magnet with the movement direction is perpendicular to the switch
plan ( Fig.4.16).

When the permanent magnet reaches point B, the reed contacts open because the field
force cancels that of the built-in magnet. The returning back to point A closes the contacts.

N S A A

N S
B B

(a) S N (b) S
(b) N

Fig.4.16: Normally close reed switch . (a): Magnet is far. (b): Magnet is close.
BINARY STATE SENSORS & ACTUATORS

4.1.5 Pressure Actuated Switches

Pressure sensors are used to ensure the correct or safety operation of an industrial
applications like cooling system in which the compressor discharge side pressure should
not exceeds a preset high pressure level and at the same time the compressor suction side
pressure should not drops below a preset low pressure level.

Pressure sensor is a pressure-to-displacement converter ( like Bourdon tubes, Bellows


and diaphragms) followed by mechanical momentary type limit switch. Bellows and
diaphragm types are widely used . Bellow type is used for low pressure applications where
as diaphragm type is suitable for high pressure applications. With any one of them, the
pressure change causes the displacement of the bellow or diaphragm in the upward or
downward direction (depends on the pressure change direction) which in turn push or release
the plunger of the momentary limit switch . When the displacement reaches the set point, the
limit switch contacts are activated (Fig4.17).

Micro Switch Micro Switch

Bellow
Bellow

(a) (b)
Air pressure inlet

Fig.4.17: Bellow type switch. (a): Pressure is less than PS (b): Pressure is greater than PS

4.1.6 Temperature Sensors

Temperature sensors or commonly called thermostats are temperature actuated switches.


They are designed to make or break an electrical contact when their designated temperature
is reached. There are two popular types of these switches, the bi-metallic and the volatile
liquid driven thermostats.
BINARY STATE SENSORS & ACTUATORS

Bi-Metallic Thermostat

These are derived from the facts that when materials are heated they expand and the high
expansion coefficient material expands more than that with lower expansion coefficient.
From this origin, this type of binary switch is constructed by bounding two strips of
different materials with different coefficients of expansion. The lower coefficient strip is
placed on the top of the strips assembly to allow the bending or shrinking . The assembly
bends upward for an increase in temperature above the setting point and shrinks causing a
downward bending for temperature reduction. Figure 4.18 details these two movements.

Low Coefficient strip


Support Point NO

High Coefficient strip NC


(a) (b)

Fig.4.18: Bi-Metallic Thermostat. (a): Cool state. (b): Heated state.

Heated state
Volatile Liquid Operated Thermostat

The construction of this thermostat had been extracted from the fact that volatile liquids
try to occupy volumes proportional to their temperatures. As the temperature increases
these volatile liquids expand causing a pressure on their containers and the reveres gives the
reverse. From this, this type of thermostat is built by allowing the volatile liquid to expand or
shrink in a bellow through capillary tube ended with a bulb in contact with the temperature
source. Figure 4.19 displays a schematic diagram of such type.
Micro Micro
Switch Switch

(b
Bulb
)

capillary tube
(a) (b)
Fig.4.19: Bellow type switch. (a):Low temperature (b): High temperature
BINARY STATE SENSORS & ACTUATORS

4.1.7 Liquid Level Sensors

Liquid level sensors which are also called float sensors are used to monitor the level of
a liquid. They are made up of micro limit switch and level sensitive mechanism to control
the operation of the micro switch. What is shown in figure 4.20 is one type of such switches.
It consists of micro switch, solid ball, and pivoted lever encapsulated in one floating encloser
in addition to adjustable length suspending thread. The operating mechanism of such switch
is that when the liquid level drops below the minimum specified level ( figure 4.21a),
the floating encloser is hanged, the micro switch plunger is released, and the normally
closed contacts are bridged to close the electrical circuit. When the liquid height rises beyond
the free length of the thread, the floating encloser turns up down ( figure 4.21b), the solid
ball pushes the pivoted lever against the switch plunger, and the plunger under press takes
the bridge away from the contacts to stop or open the electrical circuit.

Micro switch Solid ball

Thread

Pivoted lever

Internal structure of Float level sensor.

Fig.4.20: Float level sensor.

(a) (b)

Fig.4.21: Float sensor extreme positions. (a): Lower position: (b) : Upper position.
BINARY STATE SENSORS & ACTUATORS

4.1.8 Digital Output Hall Effect Sensors

4.1.8.1 Hall Effect Concept

In 1870 Edwin Hall stated that when a flat current-carrying conductor of thickness “t” and
carrying current “I” is placed in a magnetic field with flux density B, a voltage will be
generated perpendicular to both the current and the field ( Fig.422). This Hall called voltage
is expressed as :

VH=KH.B.I/t where KH stands for Hall coefficient KH which is directly proportional to the
product of the charge mobility and conductor’s resistivity, B represent the field flux density,
I is the current flowing through the flat conductor, and t is the conductor thickness.

Magnetic flux
lines VH
t
B VH
I
VH
I

Thin sheet of semiconducting material B


(a) (b)
Fig.4.22:Hall effect principle. (a): Circuit configuration. (b): B-VH characteristics.

According to this equation, Hall effect is negligibly small in most of the metallic conductors
and also insulators because in the former the resistivity is low and in the later the charge
mobility is too low. Hall effect is noticeable in some semiconductors like Indium antimonide
in which KH approaches 20 V/T.

4.1.8.2 Hall Effect Proximity Switches or Sensors Basic Structure

As stated in Fig.4.23, Hall effect proximity switches or sensors basically consist of:
BINARY STATE SENSORS & ACTUATORS

- DC voltage regulator to provide well regulated dc voltage source for Hall element and
also to enlarge the external dc voltage required to supply the sensor as whole.

- Thin piece of semiconducting material carrying constant current to detect the


presence of magnetic field and generate Hall voltage.

- Differential amplifier to boost the Hall voltage from its micro volt range to applicable
range.

- Schmitt-trigger with built in hysteresis connected to the amplifier to generate the two
output states “0” and “1” of the senor.

- Switching transistor to enable the sensor to drive wide range of fans.

VS+

Regulator

Vout

Hall Differential Schmitt


Element Amplifier trigger

VS-

Fig.4.23: Digital output Hall effect sensor.

4.1.8.3 Hall Effect Proximity Sensors Operation

Digital output Hall effect sensors are designed to be in the “OFF” state when there is no
magnetic field passing through them and turn “ON” when subjected to magnetic field with
sufficient magnetic flux density and correct polarity.
BINARY STATE SENSORS & ACTUATORS

4.2: Actuators

Actuators are the output devices that are responsible to implements the actions decided
by the controllers or transform the actions into the forms the process machinery can
understand. Actuators are subdivided into electromagnetic output devices and solid state
output devices.

4.2.1 Electromagnetic Relays

The electromagnetic relays are magnetic actuated switches operated by relatively small
amount of electric current and capable to switch on/off much larger currents. They are still
used as an auxiliary device to switch on/off the field devices. The electromagnetic relay
consists of a multi-turn coil, wound on an iron core, to form an electromagnet. When the
coil is energized, by passing current through it, the core becomes magnetized as long as the
excitation source is present. The magnetized core attracts the iron armature. The armature is
pivoted which causes it to operate one or more sets of contacts. When the coil is de-
energized the armature and contacts are released. Each relay consists of magnetic coil,
movable armature, restraining spring, fixed set of electrical contacts, and movable set of
electrical contacts (Fig4.23).
Hinged armature Bounding strip
NC contact

Spring NO contact

Coil and iron core

Casing
Yoke Insulator
Fig,4.23: Magnetic Relay’s Components,
BINARY STATE SENSORS & ACTUATORS

Figure 4.24 shows an illustrative drawing for the electromagnetic relay construction and its
contacts configuration when its coil is excited and when its coil is not excited. As it is shown
in the figure, exciting the coil pulls down the movable armature, disconnect the movable
contacts from the fixed normally closed contacts and connects them to the fixed normally
open contact. The reverse occurs on de-energizing the relay coil. The relay's contacts are
usually rated between 5 and 10 amperes. The coil possible voltage ratings are 12, 24, 48,
120, 220 VDC or VAC. Also they come with different number of terminals (Fig.4.25).

NO NO
Com Com
NC NC

(a) (b)

Fig.4.25: Relay behavior. (a) : The coil is de-energized (b): The coil is energized

Fig 4.25: Symbols of relays :


BINARY STATE SENSORS & ACTUATORS

4.2.2 On Delay Relays

On delay relays are also called on delay timers. Functionally they are identical to the
normal electromagnetic relays except that they are provided with a certain types of
contacts close delay mechanism. In general they are a combination of normal
electromagnetic relays and delay timing units. The timing delays unit may be thermal, may
be mechanical, may be pneumatic, and may be electronic. With any type of on delay
relays the required delay time should be set before energizing the relay power terminals.
After power application, the movable contacts continue keeping contact with the fixed
normally closed contacts (NCs) for an extra time period equals to the selected preset
time then after the passage of that time, they move toward the fixed normally open contacts
and make contact with them. Deenergizing the unit power terminals returns the movable
contacts to their position when the relay is de-energized. Fig4.27 states the behavior of the
on delay relay contacts under the energization and de-energization states. Fig.4.28 display
symbol of market available timing units.

Relay Unit supply state signal

Preset Time Relay Coil supply state signal

Relay Contacts behavior Relay Contact behavior Relay Contacts behavior

NCs behave as short circuits NCs behave as open circuits NCs behave as short circuits

NOs behave as open circuits NOs behave as short circuits NOs behave as open circuits

Fig.4.27: ON delay relay behavior.


BINARY STATE SENSORS & ACTUATORS

(a)

(b)

Fig.4.28: Symbol of timing units. (a): Stand alone.

(b):Mounted on the top of magnetic contactors

4.2.3 Off Delay Relays

Off delay relays are also called off delay timers. Functionally they are identical to the
normal electromagnetic relays from the point of view of making and breaking electrical
circuits using normally open contacts and normally closed contacts. Their only difference is
that they are provided with a certain types of contacts open delay mechanism. In
general they are a combination of normal electromagnetic relays and off delay timing units.
As it is the case with on delay relays, in off delay relays the required off delay time should
also be set before energizing the relay power terminals. After power application, the
BINARY STATE SENSORS & ACTUATORS

movable contacts directly move toward the fixed normally open contacts and make contacts
with them. The time the power is switched off, the timing functions start running, as long as
the elapsed time is less than the preset one, the normally open contacts stay in contact with
the movable ones. Once the elapsed time exceeds the preset one the movable contacts leaves
the normally open ones and creates contact with the normally closed contacts (NCs). Fig4.29
states the behavior of the off delay relay contacts under the energization and de-energization
states. Fig.4.30 display two types of market available off delay timing units.

Relay Unit supply state signal

Relay Coil supply state signal Preset Time

Contacts behavior Contacts behavior Contacts behavior

NCs stay closed NCs are open circuited NCs return short circuited

NOs stay opened NOs are short circuited NOs return open circuited

Fig.4.29: Off delay relay behavior.

(a) (b)
Fig.4.30: Samples of off delay timers. (a): Standalone one. (b) : Contactor top mounted one
BINARY STATE SENSORS & ACTUATORS

4.2.4 Solenoid

The solenoid is an electromagnetic device used to convert an electrical signal ( voltage or


current ) into linear mechanical motion. As it is evident from schematic diagram shown
figure 4.31 the solenoid consists of coil surrounding movable iron core ( plunger) and one
spring assembly . The plunger is standing on the spring. The spring function is to keep the
plunger away from the magnetic circuit center. Power application to the solenoid terminal
creates a magnetic force opposing that exerted by the spring. This magnetic created force
nears the movable plunger to the center of the magnetic circuit ( middle of the coil).
Deenergizing the coil enables the spring to upward moves the plunger after the
disappearance of the magnetic force . Fig.4.32 shows samples of real solenoids.

∆X
Coupling bar

Spring

Plunger

Coil

Steel housing

(a) (b)
Fig.31: Solenoid behavior. (a) : OFF state. (b): ON state

Fig.4.32: Symbols or real solenoids


BINARY STATE SENSORS & ACTUATORS

4.2.4.5 Solenoid Valves

Solenoid valves are a combinations of solenoids and valve assemblies . As can be


seen from figure 4.33, the solenoid function is to control the opening and closing of an
orifice inside the valve assembly. Power application to the solenoid power terminals
pulls down the plunger, opens the orifice, and allows the liquid to flow from the inlet to
the outlet. Power removal de-energizes the solenoid coil, allows the spring to upward
moves the plunger, and finally closes the orifice and blocks the liquid or gas flow. Fig.4.34
shows symbols of solenoid valves.

Orifice

Inlet Outlet

(a) (b)
Fig.34: Solenoid Valve behavior. (a) : OFF state. (b): ON state

Fig4.35: Examples of real solenoid valves.


BINARY STATE SENSORS & ACTUATORS

4.2.6 Magnetic Contactors

Magnetic contactors are special type of electromagnetic relays. They are designed to
carry heavy current, their current rating may ranges from 10 A to 2000A. To conduct
and interrupt heavy currents, the contactors are provided with spark extinction
mechanism to let the contactors contacts make and break the heavy currents without
damage. The pictures in figure 4.36 give an idea about the construction of this switching
devices in addition to its behavior under the powered and unpowered states. Fig.4.37 display
examples of industrial magnetic contactors.

NC
Control

contacts
NO

L1 T1
Power
L2 T2
contacts
L3 T3

Armature

Coil

˷
Fig.4.36: Basic construction of magnetic contactor. (a): OFF state. (b): ON state
BINARY STATE SENSORS & ACTUATORS

Fig.4.37: Examples of industrial used magnetic contactors.

4.2.7 DC solid state relays

DC solid state relays are power electronics switching devices in which small control
signals (3-32VDC ) control large DC load currents. Figure 4.38 introduces the basic
functional blocks of this contact less relay. As it is sound from the figure it is free from
any mechanical part and so it can be used for high switching rates as compared to
BINARY STATE SENSORS & ACTUATORS

the electromagnetic one witch can only be used with relatively small switching rate
applications. Here the application of the control signal creates conducting bridge between
the power source and the load via the power transistor low forward resistance.
Blocking the control signal increases the transistor resistance connected in series with the
load ( device reverse resistance) and this reduces the load current into negligible value. The
Solid state relays can be driven by different devices because of its control voltage wide
operating range. Fig.4.39 shows symbols of these relays.

Load

0-Vdcmax
voltage
Input Output
3-32VDC circuit circuit
voltage

Fig.4.38: Functional blocks of DC type solid state relay


-

Fig.4.39: Example of DC solid state relays.


BINARY STATE SENSORS & ACTUATORS

4.2.8 AC solid state relays

AC solid state relays are power electronics switching devices used to control the switching
of heavy AC load currents using either two antiparallel connected thyristors or triac switches
. Here the firing signal and hence the heavy AC load current is also controlled by small
control signals ( 3-32VDC). Figure4.40 shows the basic functional blocks of this mechanical
parts free relay. Here the application of the control signal creates conducting bridge
between the power source and the load via the power semiconductor device low forward
resistance. Blocking the control signal stops the firing pulses and leads to negligible current
flow in the load or in other word increases the power switch resistance connected in series
with the load into very high value. Samples of ac solid state relays are shown in fig,4.41.

Load

0-VACmax
voltage
Input Output
3-32VDC circuit circuit
voltage

N
Fig.4.41: Functional blocks of triac type solid state relay

Fig.4.42: Symbols of ac solid state relays


BINARY STATE SENSORS & ACTUATORS
BINARY STATE SENSORS & ACTUATORS
BINARY STATE SENSORS & ACTUATORS
What is meant by:

Bit :
Bit is the smallest unit of storage. A bit stores just a “0” or “1”. The Bit is suitable
to represents the lamp’s state ( dark, shining). The Bit is suitable to represents the
push-button states ( presses, released ). The Bit is suitable to represents the selector
switch (ON,OFF).

Byte :
Byte is a group of 8 bits.
When all its eight bits take their “0” value
( 27*0 + 26*0 +25*0 24*0 +23*0 +22*0 +21*0 +20*0) , the decimal equivalent of the
Byte is “0”.
When all its eight bits take their “1” value
( 27*1 + 26*1 +25*1 24*1 +23*1 +22*1 +21*1 +20*1) , the decimal equivalent of the
Byte is “255” and this equals to 28-1 ( where 8 refers to the fact that the Byte
consists of 8 Bits).

Word :
Word is a group of 16 Bits ( two Bytes).
When all its sixteen bits take their “0” value
( 215*0 + 214*0 + 213*0 +212*0 +211*0 +210*0 +29*0 + 28*0 + 27*0 + 26*0 +25*0 +24*0 +23*0 +22*0 +21*0 +20*0)

, the decimal equivalent of the Word is “0”.


When all its sixteen bits take their “1” value
( 215*1 + 214*1 + 213*1 +212*1 +211*1 +210*1 +29*1 + 28*1 + 27*1 + 26*1 +25*1 +24*1 +23*1 +22*1 +21*1 +20*1)

, the decimal equivalent of the Word is “65535” and this equals 216-1 ( where 16
refers to the fact that the Word consists of 16 Bits) .
Double Word :
Double Word is a group of 32 Bits ( 2 words or 4 bytes).
When all its thirty two bits take their “0” value
( 231*0 + …………….. +211*0 +210*0 +29*0 + 28*0 + 27*0 + 26*0 +25*0 +24*0 +23*0 +22*0 +21*0 +20*0)

, the decimal equivalent of the Double Word is “0”.


When all its thirty two bits take their “1” value
( 231*1 + ……………. +211*1 +210*1 +29*1 + 28*1 + 27*1 + 26*1 +25*1 +24*1 +23*1 +22*1 +21*1 +20*1)

, the decimal equivalent of the Double Word is “4 294 967 295” and this equals
232-1 ( where 32 refers to the fact that Double Word consists of 32 Bits) .

Long Word :
Long Word is a group of 64 Bits (4 words or 8 bytes ).
When all its sixty four bits take their “0” value
( 263*0 + …………….. +211*0 +210*0 +29*0 + 28*0 + 27*0 + 26*0 +25*0 +24*0 +23*0 +22*0 +21*0 +20*0)

, the decimal equivalent of the Long Word is “0”.


When all its sixty four bits take their “1” value
( 263*1 + ……………. +211*1 +210*1 +29*1 + 28*1 + 27*1 + 26*1 +25*1 +24*1 +23*1 +22*1 +21*1 +20*1)

, the decimal equivalent of the Long Word is “9223 3720 3685 4775 807” and
this equals 264-1 ( where 64 refers to the fact that Long Word consists of 64 Bits) .

Integer :
Integer is a whole number ( not fractional number ) that can be positive, negative,
or zero.
The following numbers are integer type numbers :
0,1,1000,1959, -2000, -16000, 16000, etc.
In PLC and in computers in general, Integer number is represented by 16 bits (
one Word or two Bytes ), the most significant bit (the bit with weight 215) is used
for the number’s sign ( 1means negative number and 0 means positive number )
whereas the remaining 15 bits are used for the number’s magnitude. Because of
this distribution , the Integer number takes values from -32768 through 0 to 32767
.
Why the maximum value of integer number is 32767?
Answer:
As mentioned above, the number of bits allocated for the magnitude in integer
type is 15 bits and this reaches its maximum value when all the bits take their “1”
value
( 214*1 + 213*1 +212*1 +211*1 +210*1 +29*1 + 28*1 + 27*1 + 26*1 +25*1 +24*1 +23*1 +22*1 +21*1 +20*1)
=215-1=32767

Why the minimum value of integer number is32768?


The negative number is represented by two’s complement. The two’s complement
is calculated by first inverting the bits of the number ( 0 is changed into 1 and 1 is
changed to 0) and then add one to the result.
Example :
The two’s complement of the binary number “101” is calculated
As follow:
Step 1: invert the number bits “101” after inversion became “010”
Step 2: add one to the inverted result : “010” +1=”011”
In case of integer type as stated above only 15 bits are allocated for the magnitude
of the number. So when all the bits are “0” the two’s complement is calculated as :
Step 1 : “000 0000 0000 0000 “ is inverted into “111 1111 1111 1111 “ and this
equal to 32767.
Step2: adds 1 to step 1 so the magnitude became 32767 +1=32768=215.
And this in case of negative number means -32768.
when all the bits are “1” the two’s complement is calculated as :
Step 1 : “111 1111 1111 1111 “ is inverted into “000 0000 0000 0000 “ and this
equal to 0.
Step2: adds 1 to step 1 so the magnitude became 0 +1=1.
And this in case of negative number means -1.

Double Integer :
In PLC and in computers , Double Integer number is represented by 32 bits (two
Words or 4 Bytes ), the most significant bit (the bit with weight 231) is used for the
number’s sign ( 1means negative number and 0 means positive number ) whereas
the remaining 31 bits are used for the number’s magnitude. Because of this
distribution , the Double Integer number takes values from -2147483648 (=-231)
through 0 to 2147483647 (=231-1 ).

Long Integer :
In PLC and in computers , Long Integer number is represented by 64 (4 Words or
8 Bytes ) bits, the most significant bit (the bit with weight 263) is used for the
number’s sign whereas the remaining 63 bits are used for the number’s magnitude.
Because of this distribution, the Long Integer number takes values from -263
through 0 to 263 -1.

Unsigned Integer :
In PLC and in computers , Unsigned Integer number is represented by 16 bits (
one Word ). It differs from the Integer by the maximum and the minimum values
because the Integer type uses 15 bits for the magnitude and one bit for the sign
where as the Unsigned Integer takes only positive values and so the whole number
of bits (16 bits ) are used for the number representation . Its minimum value is 0
and its maximum value is 65535 (216-1).

Unsigned Double Integer :


In PLC and in computers , Unsigned Double Integer number is represented by 32
bits ( two Word ). It differs from the Double Integer by the maximum and the
minimum values because the Double Integer type uses 31 bits for the magnitude
and one bit for the sign where as the Unsigned Doble Integer takes only positive
values and so the whole number of bits (32 bits ) are used for the number
representation . Its minimum value is 0 and its maximum value is
4294 9672 95 (232-1).

Unsigned Long Integer :


In PLC and in computers , Unsigned Long Integer number is represented by 64
bits ( 4 Words ). It differs from the Long Integer by the maximum and the
minimum values because the Long Integer type uses 63 bits for the magnitude and
one bit for the sign where as the Unsigned Doble Integer takes only positive
values and so the whole number of bits (64 bits ) are used for the number
representation . Its minimum value is 0 and its maximum value is
1844 6744 o737 0955 1615 (264-1).
PLC's Contacts & Coils Instructions

In PLC programming, contacts and coils instructions play the same roles of the
independent and dependent variables of Boolean expression assignment statements
A O B = C in which A and B are the independent variables , O is the logic function, and C
is the dependent variable ( mapping result). The contact instructions { | | , |/| , |P| ,
|N|} form the independent variables set whereas the coil instructions { ( ), ( /
), ( S ), ( R ), ( P ), ( N ) } take the position of the dependent ones . Each of
aforementioned PLC instructions has its own unique applications. The following
will details the meaning and applications of these instructions :

2.1 Normally Open Contact Instruction ( | | )

This contact functions as if it were a normally open contact of a magnetic


contactor. When being activated, it bridges the rung points connected to its left and
right sides. Each contact has its own label and is linked to bit in the input, output, or
memory process register . The state of the contact reflects the state of its driving bit. When
the driving bit is "0" the contact behaves as an open circuit and behaves as a closed or
short circuit when the driving bit is "1". The way these contacts are connected is very
important. The serial connection gives AND logic gate's equivalent. The parallel gives the
equivalent of the OR logic gate.

Fig, 2.1 shows how to construct 3-input AND logic gate using normally open contact
instruction.

Figure 2.1 : 3-input AND Gate


Fig. 2.2 represents the Construction of 3-input OR gate using the normally open contact

Instruction.

Figure 2.2 : 3-input OR Gate

2.2 Normally Closed Contact Instruction ( | / | )

The normally closed contact instruction takes the role of the normally closed
contact of magnetic relay. As its instance when being activated, disconnects the rung
points connected to its left and rights sides. The state of the contact reflects the negated
state of its driving bit. When the driving bit is "1" the contact behaves as an open circuit
and behaves as a closed circuit when the driving bit is "0". The way these contacts are
connected is also important. The serial connection gives NOR logic gate's equivalent
and the parallel one gives the NAND logic gate equivalent.

Fig,2.3 displays the construction of 3-input NOR gate using the normally closed contact.

Fig.2.4 shows how to constructs 3- input NAND logic gate using normally closed contact

Instructions.
Figure 2.3 : 3-input NOR Gate

Figure 2.4 : 3-input NAND Gate


2.3 Positive Transition Sensing Contact Instruction ( | P | )

This one _scan _ON instruction functions as if it were a positive triggered


monostable vibrator. When its driving bit changes from zero ( its valve at the previous
scan ) to one ( at the current scan ), its right side takes logic one value only during the
current scan and return back to zero at the next scan. Figure 2.5 shows the behavior of such
instruction .
Driving Bit Value (Start)

Switches
Scan#1 Scan#2 Scan#3
Instruction Right
Side signal
Switches
Figure 2.5: Positive transition sensing contact behavior
Switches

Fig 2.6 states how to use this instruction in constructing rising edge T flip-flop.

Figure 2.6 : Rising edge T flip-flop


2.4 Negative Transition Sensing Contact Instruction ( | N | )

This one is identical to its predecessor except that the temporary logic one state
takes place at the transition of its logic value from logic one ( its value at the previous
state) to logic zero ( at the current scan) and then return to zero again ( at the next
scan. Figure 2.7 shows the behavior of such instruction .

Driving Bit Value (%IX0.0.0)

Scan#1
Switches Scan#2 Scan#3

Instruction Right
Side signal
Switches

Switches
Figure 2.7: Negative transition sensing contact
behavior
Fig. 2.8 illustrates how this instruction can be used to construct falling edge T flip-flop.

Figure 2.8 : Falling edge T flip-flop


2.5 Coil Instruction ( ( ) )

This coil instruction behaves the same way the magnetic contactor's coil behaves.
Its activation and deactivation depends upon its left side rung logic value. Logic one
means an active state and this means writing "1" in its corresponding bit location in the
process-image register. Logic zero resets it corresponding bit. In other words, one can say
that this instruction is the dependent logic variable in a logic expression ( Ex :D= ( A
AND B ) OR C.

Fig. 2.9 shows this coil instruction represents the dependent variable “ D” in the logic
expression “ D = ( A AND B ) OR C “.

Figure 2.9 : D = ( A AND B ) OR C;

2.6 Negated Coil Instruction ( ( / ) )

The negated coil instruction can be considered as coil instruction followed by logic
NOT gate . It does the reverse of the normal coil instruction. When the logic value of its
left side rung equals "1" , it writes "0" in its corresponding bit location in the
process-image register and does the reverse when its left side rung jumps to "1".

Fig. 2.10 displays the realization of DeMorgan's Theorem 1 ( The complements of a


product of variable is equal to the sum of the complements of the variables) using this
negated coil instruction.
Fig. 2.11 displays the realization of DeMorgan's Theorem 2 ( The complements of sum
of variable is equal to the product of the complements of the variables) also making use of
this negated coil instruction.

Figure 2.10: DeMorgan's Theorem 1

Figure 2.11: DeMorgan's Theorem 2


2.7 SET & RESET Coil Instructions ( ( S ) & ( R ) )

These two coils instructions control the same bit in the process-image register. The
SET coil instruction sets the bit ( write logic "1" to the bit) when its left side rung
toggle to logic "1" and remain so what over the value of its left side rung is. The
RESET coil instruction reset the bit(write logic "0" to the bit) set by SET instruction when
its left side rung toggle to logic "1" and remain so what over the value of its left side
rung is. From the point of view of digital logic, these two coil instructions play the
same roles of the "S" and "R" inputs of the well-known SR flip-flop.

Fig. 2.12 uses the SET and RESET coil instruction in building first in priority circuit.

Figure 2.12: First IN Priority Circuit


2.8 Positive Transition Sensing Coil Instructions ( ( P ))

The positive transition sensing coil instruction can be considered as coil


instruction preceded by positive transition sensing contact. When its left side rung
logic value changes from zero ( rung valve at the previous scan ) to one ( at the
current scan ) this coil instruction forces its corresponding bit in the process image
register to take logic "1" only during this current scan. Figure 2.13 shows the behavior
of such instruction .

Instruction Left
Side signal
Switches

Scan#1
Switches Scan#2 Scan#3

Instruction bit state

Figure 2.13: Positive transition sensing coil behavior


Switches

Fig. 2.14 uses positive transition sensing coil instruction to build positive triggered JK flip
flop

Figure 2.13: Positive triggered JK Flip-Flop


2.9 Negative Transition Sensing Coil Instructions ( ( N ))

The negative transition sensing coil instruction does the reverse of its counterpart ,
the positive transition sensing coil instruction. When its left side rung logic value
changes from one ( rung valve at the previous scan ) to zero ( at the current scan )
this coil instruction forces its corresponding bit in the process image register to take
logic "1" only during the current scan.

Figure 2.14 shows its usage in constructing negative triggered JK Flip-Flop.

Figure 2.14: Negative triggered JK Flip-Flop


PLC Timing Instructions
The PLC timing instructions are software version or replacement of hardwired timers.
They are an output instructions when activated they create time related actions ( on delay
action, off delay action, time limited on activity, and measure the time durations between
two events ).

ON Delay Timers

ON delay timers are used to create contact instructions (Q) that becomes active
after preset time interval passage. These timers instructions are classified in to direct time
setting timers (TON) in which the time setting is the time assigned to the input PT (here
PT is of TIME data type) and indirect or integer time setting (TON_UINT) in which the
time setting is the product of integer type preset time setting (PT) and integer type time
unit (UNIT). Both has an enable input (IN) to activate or deactivate the instruction and
an output variable ET to register and display the elapsed time. Figure 1 displays the
ladder symbols of these timers and also their timing diagram.

TON TON
IN Q IN Q
PT
PT ET ET
UNIT

(a) (b)

IN IN

PT PT
Q Q

PT*UNIT
PT

ET ET
Figure 1: ON delay timers a): On timer b): On timer of integer setting.
Example 1: ON delay Motor Starter.

Stop1 Start1 X1

Switc Switc Swi


X1
hes hes tch

es
Swi
X TON Motor #1
tch
IN Q Switches
S es

w T#60S
PT ET
Stop2
it Start2
Switche X
c
Switc Switc
s 2
h X2
hes hes
e
X2 TON_UNIT Motor #2
S
Swi
s IN Q w
Switch tch Switches
it
es es 60
PT ET
c

Swi h
1000 PT
tch e
Switche
Figure 2: ON delay Motor Starter. es s
s

Example 2: Three phase induction motor star delta starter.

Stop:% IX0.0.1 Start:%IX0.0.0


Main:%QX0.0.0

Switches Switches Switches


Main
T1
Switches
Main TON
Switc
IN hes Q
Switches

T#60S
PT ET
Main T1.Q Delta
Star:%QX0.0.1
Switche
Switc Switc Switc
s Switches
hes
Main hes
T1.Q hes
Star
Delta:%QX0.0.2

Switc Switc Switc


Switches
hes hes hes

Figure 3: Three phase induction motor star


delta starter.
OFF Delay Timers

OFF delay timers are used to delay the off activities. When activated (IN=1), these
timers instantaneously close their normally open contacts but when deactivated (IN=0) they
delay the opening of these contacts until the preset time delay is elapsed. These timers
instructions are classified in to direct time setting timers (TOF without rest facility and
TOF_RST with reset facility) in which the time setting is the time assigned to the input
PT (here PT is of TIME data type) and indirect or integer time setting (TOF_UINT) in
which the time setting is the product of integer type preset time setting (PT) and integer
type time unit (UNIT). Each has an enable input (IN) to activate or deactivate the
instruction and an output variable ET to store the elapsed time. Figure 4 displays the
ladder symbols of these timers and also their timing diagram.

TOF TOF_RST
IN Q IN Q
PT
PT ET ET
UNIT

IN IN

Q Q
PT PT
PT PT

(a)
RST
TOF_UNIT
IN Q (b)
ET PT
ET
UNIT

IN

Q
PT*UNIT
PT* UNIT

(c)

Figure 4: OFF delay timers a): OF timer b): OF with reset c) OF timer with integer setting.
Example 3: Three phase induction motor bidirectional star delta starter.

Stop:% IX0.0.1 StartFW:%IX0.0.0 REVMain REVOFFT.Q FWMain:%QX0.0.0


Switches Switches
Switches Switches Switches
FWMain

Switches FWOFFT

FWMain TOFF
Switches
Switches IN Q
TFON
FWMain
T#1m
PT ET
TON
Switches
Switches
IN Q Switche

s
T#60S
PT ET

Switche
Stop StartREV:%IX0.0.2 FMMain FWOFFT.Q REVMain:%QX0.0.1
s
Switches Switches
Switches Switches Switches
REVMain

Switches REVOFFT

REVMain TOFF
Switches
Switches
IN Q
TRON
T#1m
PT ET
REVMain TON
Switches
Switches Switche
IN Q
s
T#60S
PT ET

Switche
TFON.Q
FWMain Delta
Star:%QX0.0.2
s
Switches Switches Switc
Switches
REVMain TRON.Q
hes

` Switches Switches
Delta:%QX0.0.3
FWMain TFON.Q Star

Switches
Switches Switches Switc
REVMain TRON.Q
hes

Switches Switches

Figure 5: Three phase induction motor bidirectional star delta starter.


PULSE Timers

Pulse timers are used to produce fixed duration output after being excited by their left side
rung positive transition. On the positive transition of IN, these timers instantaneously close
their normally open contacts and remain so till the elapsed time reaches the preset time, the
moment the contacts return to their state. Negative transition of RST resets the elapsed
time output (ET) and allow for new cycle. Any toggling for IN in the period from the
positive transition to the preset time is neglected. These timers instructions are classified
into direct time setting timers (TP without rest facility and TP_RST with reset facility)
and indirect or integer time setting (TP_UINT). Figure 6 displays the ladder symbols of
these timers and also their timing diagram.

TP TP_RST
IN Q IN Q
PT
PT ET ET
UNIT

RST
I
N
Q
PT IN
P
T
ET Q
PT
(a) PT

ET
TP_UNIT
IN Q
ET RST
PT
ET (b)
UNIT

RST

I
N
Q
PT
P
T
ET

(c)

Figure 6: OFF delay timers a): OF timer b): OF with reset c) OF timer with integer setting.
Example 4: Automatic liquid mixing machine.
MixingMotor

SValve2
LS2

SValve1 LS1
MixerOutlet

Stop:% IX0.0.1 Start:%IX0.0.0 LS1:%IX0.0.2 SVslve1:%QX0.0.0


P
Switches Switches Switches
SValve1
S
Switches
w

Stop:% IX0.0.1 i
LS1 LS2 SVslve2:%QX0.0.1
t
Switches Switches Switches
c
SValve1
h
2Switche
e MixingMotor:% QX0.0.2
SValve2 s TP_UNIT
Switches s
IN Q Switches

% MW2
PT
1000
Switche UNIT
0Switches
RST
s
Switche
MixerOutlet:%QX0.0. 3
MixingMotor:%QX0.0.2
s TP_UNIT
N
Switches
IN Q

% MW3 PT
1000
Switche UNIT
s
0Switche
RST
s
Switche

Figure 7: Automatic liquid mixing machine


TMR Timers

Integration timers (TMR) integrate the ON period or periods of their inputs marked IN
and store the accumulated time in the elapsed time variable (ET). When ET reaches the
preset time ( PT in case of TMR and PT*UNIT in case of TMR_UNUIT), the instructions
assign "1" to their outputs Q. New cycle can be initiated after stropping the RST inputs.
Figure 8 shows their ladder symbol and timing diagrams.

TMR TMR_UNIT
IN Q IN Q
PT
PT ET ET
UNIT

RST RST

IN IN

Q Q

PT PT

RST RST

(a) (b)

Figure 8: TMR timers (a): Direct TMR (b): TMR with integer setting
Example 5: Ice cream cone filling machine with teaching function.

N/T:%IX0.0.0 R

P
Switches Swi

S tch

w TMR1 es

i
N/T Fill:%IX0.0.1 TMR
Switches
t
Switc Switches
IN Q
c
hes
h T#1m
PT ET
e
R
Switche
s
RST
s
S

wi

tc
Fill
N/T MOVE
he
N IN Q
Switches s
Quantity
Sw TMR1.ET OUT
IN
itc
Switches
Switches
N/T he Fill
TP1Switc
s
IN TP hes
Switches Switc

hes
Q
Quantity
PT ET
Switches

N/T Fill
FillerOutlet:%QX0.0.

0
Switches Switc
N/T TP1.Q
hes
Switches

Switches Switche

Figure 9: Ice cream cone filling machine


TMR_FLK Timers

Integration timers with flickers (TMR_FLK) produces an out signal Q with mark equals
to the time assigned to ON time input variable and space equals to the time assigned to the
OFF time input variable. Figure 10 pictures the ladder symbol used and state the operating
principle of this timing instruction.

TMR_FLK IN
IN Q
ON ON Time
ET
OFF
OFF Time
RST

Figure 10: TMR with flickers

Example 6: Flashing Odd /Even lamps.

TMR_FLK1

ON/OFF: IX0.0.0 TMR _FLK


Switches

Switches
IN Q

T#60S
ON ET
T#60S
Switche OFF
s
Switches
T#60S RST

TMR_FLK1.Q MOVE Switches

EN Q
Switches

2#01010101 OUT %QB0.0.0


IN
Switches

TMR_FLK1.Q MOVE
EN Q
Switches

2#10101010
OUT %QB0.0.0
IN
Switches

Figure 11: Flashing Odd /Even lamps.

A/M Fill
TRTG Timers

Retriggerable timers produce an out signal Q with pulse width equals to the time
assigned to PT in case of ( TRTG) type and equals to PT*UINT in case of TRTG_UINT
one. Here the new pulse can only be generated after the elapsed of the preset time ( until
ET=PT) and occurrence of positive transition of the instruction input IN. Figure 12
pictures the ladder symbol used and gives more deep understanding to the relationship
between the various variables of this timing instruction.

TRTG TRTG-UINT
IN Q IN Q
PT
PT ET ET
UNIT

RST RST

IN IN

Q Q

PT PT

RST RST
(a) (b)
Figure 12: TRTG timers (a): Direct TRTG (b): TRTG with integer setting
Example 7: PWM Heater Control.
TRTG1

OFF: IX0.0.0 ON TRTG


Switches

Switches Switches
IN Q

TRTG1.Q % MW2 PT ET
N
Switches 1000
Switche UNIT
S
TMR_FLK1.Q s
Switches
0 RST
wi GE
EN Q
Switches tc
Swi
OFF Period IN1 Pulses:%QX0.0.0
he OUT
TRTG1.E tch
Switches
IN2
s
TSwitches es

Switches

Figure 13: PWM Heater Control


PLC Counting Instructions
The PLC counting instructions are advanced software version or replacement of
electronic or mechanical counters. The counting instructions are subdivided into up
counting , down counting , and combined up down counting instructions. These key
instructions are widely used in industrial application . For example they may be used to keep
track of the number of water bottles coming out of the filling station, to control a gate for
redirecting the movement of items ( books, bottles, etc.) , to count the number of time an
event take place, measuring the linear distance an object moves, measuring the rotation
speed of motors, keeping track of the undesired items on a conveyor, etc.

UP Counting Counters

Up counters increase their current count output variable “ CV” each time their
trigger inputs experience a transition from logic zero to logic one. The instruction output
Boolean variable Q toggles from zero to one when CV reaches the preset count value “ PV”
and stay so unless reset by the reset input R. The upper counting level depends upon the
counting instruction type. Table 1 lists the upper limits for the various up counting
instructions . Figure 1 shows the instruction function block and timing chart.

Table 1: Maximum counting value of counting up instructions.

Instruction PV data type Maximum counting value


CTU_INT Integer 32767
CTU_DINT Double integer 2147483647
CTU_LINT Long integer 9223372036854775807
CTU_UINT Unsigned integer 65535
CTU_UDINT Unsigned double integer 4294967295
CTU_ULINT Unsigned long integer 18446744073709551615

CTU_XXXXX R
CU Q
CU

R
Q
CV
PV CV
PV

CV=0 CV=PV
CV=1 CV=Max Count

Figure 1: Up counting instruction timing chart


Example 1: In book packaging process it is required to change the traveling path of the

books each time preset number of books have been passed ( say 12 books).

assuming two paths, write PLC program to do that.

BooksSensors
BooksSensors C1.Q ResetC1
ResetC1
P
Switches
Switches Switches Switches
Switches
C1
Swi
BooksSensors CTU_INT
tch Swit
N
Switches
es
IN ches Q
Swit ResetC1
R
che
Switches
s
Req.Quantity PV CV

C1.Q Switches FlapCoil


FlapCoil

Switches Switches Switches


C1.Q FlapCoil

Switches Switches

Figure 2: Traveling Path Controller.


Down Counting Counter

Down counters decrease their current count output variable labeled CV , starting from
the preset value "PV" loaded by the load input "LD", each time their trigger inputs
experience transition from logic zero to logic one. The instruction output Boolean
variable Q toggles from zero to one the time CV reaches zero and stay one unless reset by
the load input LD . The minimum counting level depends upon the counting instruction
type. Table 2 lists the lower limits for the various down counting instructions . Figure 2
shows the instruction function block and details its timing chart.

Table 2: Minimum counting value of counting down instructions

Instruction PV data type Minimum counting value


CTD_INT Integer -32767
CTD_DINT Double integer -2147483647
CTD_LINT Long integer -9223372036854775807
CTD_UINT Unsigned integer -65535
CTD_UDINT Unsigned double integer -4294967295
CTD_ULINT Unsigned long integer -18446744073709551615
LD
CTD_XXXXX CD
CD Q

LD Q
PV CV
PV CV 0

CV=PV CV=0
CV=PV-1 CV=Mini Count

Figure 3: Down counting instruction timing chart

Example 2: Write ladder diagram to track the number of remaining items in a store
previously loaded with 100 items.

Enter 100 Items


BooksSensors ResetC1
Load
P
Switches
Switches C1 Switches
Switches
ItemLeaveSensor S
CTD_INT
Swit w
P
Switches IN ches
Q
i

Swit Load t
LD
che c
Switches
s 100 PV CV h

C1.Q e
StoreEmpty
Switches
s
Switches Switches

Figure 4: Tracking the remaining items in a store

UP/ Down Counting Counters

UP / Down counters can be considered as two counters (up counter and down counter)
sharing the same preset value input variable PV and current value output variable CV. The
up counting part has its own unshared terminals or variables represented by the triggering
input CU, reset input R, and the output QU. The down counter unshared variables are
the triggering input CD, the load input LD, and the output variable QD. The upper and
lower counting levels for these counters depend upon the instruction used type. Table 3 list
down these limits.
Table 3: MAXIMUM /Minimum counting values of up/down counting instructions

Instruction PV data type Max/Min counting value


CTUD_INT Integer +-32767
CTUD_DINT Double integer +-2147483647
CTUD_LINT Long integer +-9223372036854775807
CTUD_UINT Unsigned integer +-65535
CTUD_UDINT Unsigned double integer +-4294967295
CTUD_ULINT Unsigned long integer +-18446744073709551615

Example 3: Draw ladder diagram for Parking Garage Controller with N car capacity

Start
LT
Switches IN ENO
CarInside SpaceOK
Swit IN1
OUT
che Switches Switches
Capacity IN2 GarageFull
S
s
Switches w
Switches

EnterSensor ExitOK SpaceOK it


EnterOK
c
Switches Switches Switches
h
Switches
ExitSensor EnterOK es
ExitOK
P
Switches Switches
CUD1 Switches
S
EnterOK CTUD_INT
Switches w
P CU QU it
Switches
Swit
S
ExitOK CD c
QD
WN h
wche
0 R CV CarsInside e
it s Switches
0 S LD s
c

h wi
NS PV
e tc
wi
s he
S
tc
wi s
he
tc
Figure 5: Parking Garage Controller
s
he

s
Ring Counter

Ring counter CTR is an up counting instruction with inherent reset strobe facility. Here
the current value CV increases as the rung connected to CD experiences a transition from
zero to one and CV is less than PV. When CV equals PV the Q output becomes "1". The
next positive transition on CD ( after CV=PV) resets the Q output and forces CV to take a
value of one and new cycle starts. The ring counter supports only integer data types for its
CV and PV variables. Figure 6 displays the ladder symbol and the timing chart of the ring
counter.
RST
CTR1
CTR CD
CD Q

PV Q
PV CV
RST CV

CV=0 CV=PV CV=0


CV=1 CV=1
(a) (b)

Figure 6: Ring counter instruction (a): Symbol . (b): timing chart

Example 4: Y is one dimensional array. It consists of 10 word type elements. Write PLC
Program segment to continuously copy the contents of this array one after the other to the
PLC output terminals. Let the copy process time span equals to 30sec.

Start TMR_FLK CTR


EN Q CD Q
Switches
T#5S
Swit ON 10 PV
ET J
che T#5S
Switches OFF CV
0Swi RST
s
0
Switch RST tch
Swi
es es
tch
Start Swi

tch MOVE es
Switches EN ENO
es
Pattern[J] IN OUT Lamp
Swit

che s
s

Figure 6: Light Flashing System


PLC Shift and Rotate Instructions
Shift designated array elements.

The shift designated array elements ( SHIFT_A) shifts the sub array elements starting at
the start shifting location(Start) and terminating at the end shifting location(End). Each time
the instruction enable bit (EN) experiences a positive transition, the sub array elements are
shifted N times. The sub array first N elements ( from the Start position) are filled by the
data stored in the IN input variable. The data leaving the end position ( over flowing data ) is
shifted to the output variable OUT. The direction of shifting is determined by
the comparison state of Start and End. For Start>End, the shift direction is from the
upper positions to the lower ones and vice versa. The source array (SRC) data type can be
any type except the string type. Figure 1 shows the ladder symbol of the instruction
under investigation and also the shifting movement for one positive transition of IN .

SHFT_A SRC SRC


BOOL EN ENO BOOL 0 0
1 IN=10 1
ANY IN OUT UINT
Start=2 2 0
10
ARRAY ARRAY
SRC SRC 3 2
OF ANY C OF ANY 4 3
End=5 5 4
OUT=5
UINT START 6 6
7 7
UINT END
Before Shifting After one pulse Shifting
UINT N

Figure 1: SHIFT_A ladder symbol and behavior diagram


Example 1:

Using SHIFT_A instruction, write ladder program to generate the following repeated
sequence [ 0,1,4,8,16,32,64,128].

Solution : The solution is as drawn in figure 2 with an initial value of A equals


to {1,4,8,16,32,64,128}.

MOVE
BooksSensors
_1ON
EN ENO
Switches
Switch
ResetC1
es
1 IN OUT %QW0.0.0
Switches
Sw

itc
_T20s SHFT_A
he
P
Switche
EN ENO
s
Swis
%QW0.0.0 IN OUT %QW0.0.0
tch

es
A SRC SRC A
C
6 START

0 END

1 N

Figure 2: Example 1 ladder diagram


Shift With Carry.

The shift with carry instruction (SHIFT_C) behaves the same way the SHIFT_A
instruction does. It can be considered as SHIFT_A with Boolean data type but SRC is not an
array data type. Here SCR may be Byte, Word, Dword, or Lword. So to treat SHIFT_ C as
SHIFT_A, the byte type data should be treated as if it were an array of 8 Boolean type
elements, word type data as an array of 16 Boolean type elements, dword as an array of
32 Boolean type elements, and lword as an array of 64 Boolean type elements . Figure 3
shows the ladder symbol of this instruction and also the shifting movement for one
positive transition of IN .

SHFT_C SRC:%MB2 SRC:%MB2


BOOL EN ENO BOOL 0 0
1 IN=1 1
BOOL CY OUT BOOL
1 Start=2 0 1
{ Byte, SRC SRC { Byte, 1 0
Word, C Word, 1 1
Dword, Dword, End=5 0 1
Lword} Lword} OUT=0
0 0
UINT START 0 0

UINT Before Shifting After one pulse Shifting


END

UINT N

Figure 3: SHIFT_C ladder symbol and behavior diagram


Example 2:

Using SHIFT_C instruction, write ladder program to generate the following repeated
sequence [ 0,1,2,4,8,16,32,64,128].

Solution : The solution is as drawn in figure 9.3 with an initial value of %mw2
equals 1.

MOVE
BooksSensors
_1ON
EN ENO
Switches
Switch
ResetC1
es
1 IN OUT %MW2
Switches
Sw

_T20s itc SHFT_C


P he EN ENO
Switche
s
Swis
Y CY1 OUT Y
tch
%MW2 SRC SRC %MW2
es
0 C
START
7 END
1 N

Figure 4: Example 2 ladder diagram

Shift Right.

The shift right instruction ( SHR) shifts the image of the bit string ( Byte, Word, Dword,
Lword ) assigned to IN ( instruction data input) as N ( instruction shifting times ) bits
number and stores the shifted result in the instruction output variable OUT. As compared to
SHIFT_C, this one has one shift direction ( from left to right), the shifting process is
executed over the whole string image, the overflow data is lost, and there is no specific
inlet to substitute the left end bit or bits. Figure 5 highlights the ladder symbol used and
illustrates is operation for different N values.
SHR IN N OUT
BOOL EN ENO BOOL 1 64
{ Byte,Word, IN { Byte,Word, 2 32
OUT
Dword,Lword 3 16
Dword,Lword}
4 8
INT } N 5 4
6 2
7 1
8 0

Figure 5: SHR ladder symbol and shifting Process as function of N

Example 3:
Draw ladder diagram to copy the upper byte of %MW4 to the lower byte of %QW0.0.0.
without affecting the content of the upper part of %QW0.0.0.

Solution:
Copy
SHR
P EN ENO
Switche
%MW4
Swi s IN OUT X
tch 8 N
es

AND
BooksSensors
EN ENO
%QW0.0.0
Switches IN1
ResetC1 %QW0.0.0
OUT
16#FF00 IN2
Switches

OR
EN ENO
%QW0.0.0 IN1
OUT %QW0.0.0
X IN2

Figure 6: Example 3 ladder diagram


Shift Left.

The shift let instruction ( SHL) does the reverse done by its predecessor SHR. SHR
does the integer division by two, but SHL does the multiplication by 2. It shifts the image
of the bit string IN as N times from the least significant bit towards the most significant one.
Figure 7 displays the ladder symbol used and illustrates the instruction operation for
different N values.

SHL IN N OUT
BOOL EN ENO BOOL 1 2
{ Byte,Word, IN OUT { Byte,Word, 2 4
Dword,Lword Dword,Lword} 3 8
4 16
INT } N 5 32
6 64
7 128
8 256
Figure 7: SHL ladder symbol and shifting Process as function of N

Example 4:
Draw ladder diagram to copy the lower byte of %MW4 to the upper byte of %QW0.0.0.
without affecting the content of the lower part of %QW0.0.0..

Solution:

Copy
SHL
EN ENO
Switches
%MW4 IN OUT X
8 N

AND
BooksSensors
EN ENO
%QW0.0.0
Switches IN1
ResetC1 %QW0.0.0
OUT
16#00FF IN2
Switches

OR
EN ENO
%QW0.0.0 IN1
OUT %QW0.0.0
X IN2

Figure 8: Example 4 ladder diagram


Rotates Designated Array Elements.

The Rotate designated array elements ( ROTATE_A) shifts the sub array elements
starting from the start shifting location (Start) and terminating at the end shifting location
(End). Each time the instruction enable bit (EN) experiences a positive transition, the sub
array elements are shifted N times. The sub array first N elements ( from the Start position)
are filled with the data coming from the end location. The data leaving the end position
( over flowing data ) is stored in the output variable OUT. The direction of shifting is
determined by the comparison state of Start and End. For start>End, the shift direction is
from the upper positions to the lower ones and vice versa. The source array (SRC) data
type can be any type except the string type. Figure 9 shows the ladder symbol of the
instruction under investigation and also the shifting movement for three different
configurations.

ROTATE_A
BOOL EN ENO BOOL

Array of any SRC SRC Array of any


Type except string C Type except string
UINT START OUT Same Type
UINT END Of SRC
UINT N Elemen
Elements
ts

SRC Initial vale {1,2,3,4,5,6,7} where 1 represents the content of SRC[0].


Pulse number 1st configuration OUT 2nd configuration OUT 3rd configuration OUT
Start=0, End=6, N=1 Start=0, End=6, N=2 Start=1, End=5, N=1
1 7 6 6
2 6 4 5
3 5 2 4
4 4 7 3
5 3 5 2
6 2 3 6
7 1 1 5
8 7 6 4
9 6 4 3

Figure 9: ROTATE_A ladder symbol and behavior for Three different Configuration.
Example 5:

Propose ladder diagram to control the ON/OFF switching of eight lamps according to
the data listed in figure 10. Assume the step rhythm to be 20 sec.

Step Output State Step Output State


87654321 87654321
1 00011000 9 11111111
2 00100100 10 00000000
3 01000010 11 11111111
4 10000001 12 00000000
5 01000010 13 11111111
6 00100100
7 00011000
8 00000000
Figure 10: Data table of example 5.
Solution:

Figure 11 details the solution in which the array Y is initialized with the hexa decimal
values { 18,24,42,81,42,24,18,00,FF,00,FF,00,FF}.

T1
Start
TMR_FLK
EN Q
Switches
T#10S ON

T#10S OFF ET
0 RST

T1.Q
ROTATE_A
PSwitches EN ENO
Y SRC SRC

12 START
OUT %QB0.0.0
0 END

1 N

Figure 11: Example 5 ladder diagram


Rotate With Carry.

The rotate with carry instruction (ROTATE_C) shifts the sub bit string SRC ( SRC may
be Byte, Word, Sword, Lword) bits starting from the start shifting location (start) and
terminating at the end shifting location(END). Each time the instruction enable bit (EN)
experiences a positive transition, the sub string bits are shifted N times. The sub string
first N bits ( from the Start position) are filled with the data coming from the end
location. The data leaving the end position ( over flowing data ) is stored in the Boolean
output variable OUT. The direction of shifting is determined by the comparison state
of Start and End. For start > End, the shift direction is from the upper positions to the
lower ones and vice versa. Figure 12 shows the ladder symbol of this shifting instruction
and its behavior under different configurations..

ROTATE_C
BOOL EN ENO BOOL
{ Byte, Word, SRC SRC { Byte, Word,
Dword, Lword} C Dword, Lword}

UINT START
OUT BOOL
UINT END
UINT N

SRC Initial vale {16#12}


Pulse 1stconfiguration 2nd configuration 3rdconfiguration 4th configuration
No. SRC SRC SRC OUT
Start=0, End=6, Start=0, End=6, Start=6, End=0, Start=1, End=5, N=1
N=1 N=2 N=1
1 24 48 09 24
2 48 22 44 0A
3 11 9 22 14
4 22 24 11 28
5 44 11 48 12
6 09 44 24 24
7 12 12 12 0A
8 24 48 09 14
9 48 22 44 28

Figure 12: ROTATE_C ladder symbol and behavior for four different Configuration.
Example 6:

The water circulation for cooling tower is to be 24 hours. Propose a three water pump
system in which each pump runs one hour and rests two.

Solution:
Run
MOVE
P EN ENO
Switches

S 1 IN OUT %QX0.0.0
wi

tc

he
T1
Run
s TMR_FLK
Switches
EN Q
T#30M ON
T#30M OFF ET
0 RST

T1.Q Run
ROTATE_C
N
Switches
EN ENO
Switch
SRC %QW0.0.0
%QW0.0.0
S es SRC
wi 0 START
tc
2 END OUT
he

s 1 N

Figure 13: The proposed three pump controller


Rotate Right.

The rotate right instruction ( ROR) shifts the image of the input bit string IN ( Byte,
Word, Dword, Lword ) as N ( shifting times ) bits number, fills the leftmost locations
with the values shifted out of the right most locations such that for M bits string, the least
significant bit B0 of IN is rounded to image B(M-N) bit. The modified ( shifted and
rounded) version of the input bit string is stored in the output variable OUT. Figure 14
shows the ladder symbol and enhances the aforementioned explanation.

ROR
BOOL EN ENO BOOL
{ Byte, Word, IN { Byte, Word,
Dword, Lword} OUT Dword, Lword}
INT N

IN vale {2#10101010}
Bit IN OUT (N=1) OUT (N=2) OUT (N=3)
7 1 OUTB7=INB0=0 OUTB7=INB1=1 OUTB7=INB2=0
6 0 OUTB6=INB7=1 OUTB6=INB0=0 OUTB6=INB1=1
5 1 OUTB5=INB6=0 OUTB5=INB7=1 OUTB5=INB0=0
4 0 OUTB4=INB5=1 OUTB4=INB6=0 OUTB46=INB7=1
3 1 OUTB3=INB4=0 OUTB3=INB5=1 OUTB3=INB6=0
2 0 OUTB2=INB3=1 OUTB2=INB4=0 OUTB2=INB5=1
1 1 OUTB1=INB2=0 OUTB1=INB3=1 OUTB1=INB4=0
0 0 OUTB0=INB1=1 OUTB0=INB2=0 OUTB0=INB3=1

Figure 14: ROR ladder symbol and its behavior under different values of N
Example 7: Using ROR instruction, write ladder program to generate the following
repeated sequence [ 16,8,4,2,1].

Solution :
C1
_T#10s
CTR
P CD Q
Switches

S 5 PV
w

i
0 RST CV N
t

h
Start
e ROR
P EN ENO
s Switches
S 32 IN
w

i
N N OUT %QB0.0.
t 0
c

s
Figure 15: Ladder diagram of example 7

Rotate Left.

The rotate left instruction ( ROL) shifts the image of the input bit string IN ( Byte,
Word, Dword, Lword ) as N bits number, fills the rightmost locations with the values
shifted out of the left most locations such that for M bits string, the most significant bit BM-1
of IN is rounded to image BN-1 bit. The modified version of the input bit string is stored
in the output variable OUT. Figure 16 shows the ladder symbol and tabulates the left
rotation of %MB3 for different values of N.

IN vale=%MB3= {2#10101010}
Bit IN OUT (N=1) OUT (N=2) OUT (N=3)
7 1 OUTB7=INB6=0 OUTB7=INB5=1 OUTB7=INB4=0
6 0 OUTB6=INB5=1 OUTB6=INB4=0 OUTB6=INB3=1
5 1 OUTB5=INB4=0 OUTB5=INB3=1 OUTB5=INB2=0
4 0 OUTB4=INB3=1 OUTB4=INB2=0 OUTB46=INB1=1
3 1 OUTB3=INB2=0 OUTB3=INB1=1 OUTB3=INB0=0
2 0 OUTB2=INB1=1 OUTB2=INB0=0 OUTB2=INB7=1
1 1 OUTB1=INB0=0 OUTB1=INB7=1 OUTB1=INB6=0
0 0 OUTB0=INB7=1 OUTB0=INB6=0 OUTB0=INB5=1
Figure 16: ROL ladder symbol and its OUT value as function of N
Example 8: Using ROL instruction, write ladder program to generate the following
repeated sequence [ 1,2,4,8,16].

Solution

C1
_T#10s
CTU
P CU Q
Switches

S C1.Q R
w

i
5 PV CV N
t

h
Start
e ROL
P EN ENO
s Switches
S 1 IN
w

i
N N OUT %QB0.0.
t 0
c

Figure 17: Ladder diagram of example 9.8 solution.

First IN First OUT.

The first-in-first-out (FIFO_XXXXX) is two gates controlled queue. Its inlet gate is
controlled by the input marked LOAD, its exit gate is controlled by the UNLD input. The
queue its self is an array of any type of data except the string one (XXXXX є{BOOL,
BYTE, WORD, DWORD, LWORD, SINT, INT,DINT,LINT,USINT,UINT,UDINT,ULINT,
REAL,LREAL,TIME,DATE,TOD, DT} . It has two flags and one pointer. The flags are the
empty flag (EMPTY) which rises 1 when the queue is free from any item and the full
flag (FULL) which declares there is no empty position in the queue ( the queue is full).
The pointer (PNT) points to the top of the queue, it ranges from 0 to the queue capacity.
The in and out traffic of items are controlled by the queue request input (REQ). New item
entering depends upon the states of the REQ, LOAD, the FULL, a new item is allowed to
enter only if REQ=1,LOAD=1,and Full =0. Pushing items out of the queue depends upon
UNLD and REQ states, UNLD should be "1" and also REQ should be "1". The function
block of this instruction is shown in figure 18.

FIFO_XXXXX
BOOL REQ DONE BOOL
{ Any type IN
except string } OUT { Any type
except string }
{ Array of any type
FIFO
except string }

BOOL LOAD PNT INT

BOOL UNLD FULL BOOL

BOOL RST EMPTY BOOL

Figure 18: FIFO function block.


Example 9: Write ladder program to keep track of the last 12 values of a certain integer type
variable .

Solution.

C1
OK_Move C1.Q
CTU
P
Switches Switches
CU Q
S Reset S R
w w

i
13 i PV ET
t t

c c
OK_Move C1.Q Get_Out
h h
P
Switches
e e
Switches Switches
OK_Move Get_In
Ss s
N
w
Switches Switches
Si FIFO_INT
wt BOOL
REQ DONE
ci

ht
X IN
ce
OUT
AofX FIFO
hs

e
Get_In LOAD PNT
s
Get_Out UNLD FULL

Reset RST EMPTY

Figure 19:
Last IN First OUT.

The last-in-first-out (LIFO_XXXXX) is a stack in which the inlet and exit share the
same terminal ( opening) . The stack its self is an array of any type of data except the
string one (XXXXX є{BOOL, BYTE,WORD DWORD, LWORD, SINT,INT, DINT, LINT,
USINT,UINT,UDINT,ULINT, REAL,LREAL,TIME,DATE,TOD, DT} . Loading the stack
( entering new item) is done when the request is one ( REQ=1 ), the stack is not full
(FULL=0), and the load enable is active (LOAD=1). Unloading the stack( releasing the stack
top item) is ok when the request is one and the unload input is active (UNLD=1. The stack
instruction also includes an integer type pointer (PNT) to keep track of the top of the stack
( current position). The function block of this instruction is well illustrated in figure 20.

LIFO_XXXXX
BOOL REQ DONE BOOL
{ Any type IN
except string } OUT { Any type
except string }
{ Array of any type
except string } FIFO

BOOL LOAD PNT INT

BOOL UNLD FULL BOOL

BOOL RST EMPTY BOOL

Figure 20: LIFO function block.


Example 10: Write ladder program to capture the first N values of a certain word type
variable .

Solution:

C1
Store
CTU
P CU Q
Switches

S Reset R
w

i
N +1 PV ET
t

c
Store C1.Q Get_In
h
P
Switch
e Switches Switches
Extract C1.Q Get_Out
Ss es
P
w
Switches Switches Switches
Si LIFO_WORD
wt BOOL
REQ DONE
ci

ht
X IN
ce
OUT
AofX FIFO
hs

e
Get_In LOAD PNT
s
Get_Out UNLD FULL

Reset RST EMPTY

Figure 21: Storing the first N values


Structured text programming
The structured text (ST) language is high level language currently used
in PLC programming. Like any other high level language it contains may functions
and key words. Many of which also do equivalent functions as in the other
programming languages. It enables PLC programmer to develop and program more
complex control algorithms. Structurally it highly looks like the well known and
efficient PASCAL programming language.

Comments

Comments are used to increase the readability of programs. They are used to mark the
beginnings and ends of program sections and also to give brief explanation to the program
instructions or parts they headed. Here we have the one line (//) comments and the multiline
or block comments {(* comments *)}.

Logical Statements

Logical statements consist of one or more logical operators (AND, OR, XOR, NOT) and
any same data type operands ( Bit, Byte, Word, Dword, Lword).

Example 1: Write ST program to develop 2-to-4 decoding circuit. Assume S1 and S0 are
the decoder inputs and Y3,Y2,Y1, and Y0 are the decoder outputs.

Solution: Y3:= S1 AND S0; Y2:= S1 AND NOT (S0); Y1:= NOT(S1) AND S0;
Y0:=NOT(S1) AND NOT( S0);

Example 2: Write ST program segment to show the complement of a product of


variables equals the sum of the complements of the variables.

Solution: Y0:= NOT ( %MW1.1 AND %MW1.0); // Y0 is the complements of product.


Y1:= NOT %MW1.1 OR NOT %MW1.1; // Y1 is the sum of complements.

Example 3: Show the complement of sum of variables equals the product of


complements of the variables. Assume two variables.

Solution: Y0:= NOT ( %MW1.1 OR %MW1.0); // Y0 is the complements of sum.


Y1:= NOT %MW1.1 AND NOT %MW1.1; // Y1 is the product of complements.

Example 4: Write program segment to invert memory bit %MW1.2 each scan if
%MW1.1 is true.

Solution: CLOCK:= ( %MW1.1 XOR CLOCK); // CLOCK=%MW1.2


Example 5: X is 64 bit length bit-type variable. Suggest solution to invert the middle
four bits each new scan.

Solution:
X:=X XOR 2#0000000000000000000000000000001111000000000000000000000000000000; (*X is
LWORD bit type variable.*)

Example 6: Write the ST equivalent of the circuit shown in figure 10.1.

VCC +

Stop

McCoil Start

McCoil

VCC -

Figure 1: Latch circuit


Solution:
McCoil:=Stop AND (Start OR McCoil); (* McCoil is the output contactor coil bit, Stop is
the Stop pushbutton input bit, and Start is the Start pushbutton input bit*)
Example 7, Draw the traditional control diagram of a changeover switch which supplies
electric power from either the national grid or local generator with the highest
priority to the national grid. Also write the ST equivalent of that controller.

Solution:

(* Let the availability of national grid represented by the input %IX0.0.0 and has the label
NGOK. Also assign the label LGOK for the %IX0.0.1 to represents the availability state of
the local generator. For the changeover contactors, assign NG_C for %QX0.0.0 output bit
responsible to control the national grid interfacing power contactor and LG_C for
%QX0.0.1 for the contactor connecting the generator to the load.*)

VC +
LG -Line

NG -Line Start_Stop
LGOK

LG_C NG_C

NGOK NGOK

NG_OK LG_OK VCC -


NG_C LG_C
Neutral

Figure 2: Changeover switch control


circuit
NG_C:=Start_Stop AND NOT LG_C AND NGOK;
LG_C:=Start_Stop AND LGOK AND NOT NG_C AND NOT NGOK;

Example 9: Write the ST text that functions as a 4-input multiplexing circuit.

Solution:

Y3:=S1 AND S0 AND I3;


Y2:=S1 AND NOT S0 AND I2;
Y1:=NOT S1 AND S0 AND I1;
Y0:=NOT S1 AND NOT S0 AND I0;

Y:=Y1 OR Y2 OR Y3 OR Y4;
Example 10: Write the ST equivalent of JK flip-flop.

dummy:= (J AND NOT Q) OR (K AND Q);

R_Trig(Clk:=dummy,q=>Flip);

Q:=Flip XOR Q;

Arithmetic Statements

Arithmetic statements also consist of one or more arithmetic operators and any same
num-type operands. The operators involved here are the addition (+), the subtraction (-), the
multiplication (*), the division (/),the remainder (MOD), and the exponential (**). All these
types allow any numerical data type except the exponential one is restricted to real data ones.

Example 11: Write the ST text that generates the Triangular membership function
drawn in figure10.3. μ(x)

0.5

x
a b c

Solution: Figure 3: Triangular membership function

U_x= MAX(0,MIN((x-a)/(b-a),(c-x)/(c-b))); // a,b,c are real type variables.

Example 12, Write the ST text that generates the bell-shaped membership function
drawn in figure10.4. μ(x)

0.5

x
a b c
Figure 4: Bell-shaped membership function
U_x:=1/(1+(ABS((x-b)/a))**(2*c )// a,b,c are real type variables.
Example 13, Write the ST text that generates the sigmoid-right membership function
drawn in figure10.5.
μ(x)

0.5

x
c
Figure 5: Sigmoid-right membership function
Solution:

U_x= 1/(1+EXP(IN:=a*(c-x))); // a is positive number

Example 14, Write the ST text that generates the sigmoid-left membership function
drawn in figure6.
1

0.5

x
c

Solution:

U_x= 1/(1+EXP(IN:=a*(c-x))); // a is negative number

Example 10.15, Write the ST text that solves the equation of the definite minimum
inverse time over current relay.

Solution:

T:= c/((I/IS)**a -1); //


IF Conditional Statements

IF conditional statements control ( allow or deny ) the execution of one or more


statements bounded by their start and termination identifiers. The execution or deny depends
upon the true or false results of the comparison expression following the statements
identifiers ( IF, ELSE, ELSIF). These statements have a number of structures as illustrated
in figure 7.
IF Condition THEN IF Condition THEN IF Condition1 THEN
statement 1; . . . . statement A1; . . . . statement A1; . . . .
statement n; statement An; statement An;
END_IF; ELSE ELSIF Condition k
statement B1;. . . . statement K1;. . . .
statement Bm; statement Km;
END_IF; ELSE
statement V1;
statement Vj;
Figure 7: Conditional statement structures END_UF;

Example 16, Write the ST text to get set / reset function.

Solution :

IF S=1 Then Q:=1;

END_IF;

IF R=1` Then Q:=0;

END_IF;

Example 17, Write the ST text to test two integer type variables X and Y and assign the
value of the smallest one to Z;

Solution:

IF X<=Y THEN

Z:=X;

ELSE

Z:=Y;

END_IF:
Example 18, Write the ST text to obtain the membership function sketched in figure10.8

Solution:
μ(x)
IF X<=a THEN 1

Y:=0;
0.5
ELSIF X>=b THEN

Y:=1; x
a b
ELSE
Figure 8: S-like membership function
Y:=(X-a)/(b-a);

END_IF;

Example 19, Write the ST text to obtain the membership function sketched in figure9.

Solution: μ(x)

IF X>=a THEN 1

Y:=0; 0.5
ELSIF X<=b THEN
x
b a 0
Y:=1;
Figure 9: Z-like membership function
ELSE

Y:=(X-a)/(b-a);

END_IF;
CASE Conditional Statements

CASE is used to execute one out of many statements. The selected statement is that one
whose line starts with the current value of the integer type expression following the
reserved word "CASE". The two possible basic structures of this selection facility are
pictured in figure 10.

CASE Expression OF CASE Expression OF


1: statement ; . . . 1: statement ; . . .
statement; statement;
: :
n: statement ; . . . n: statement ; . . .
statement; statement;
END_CASE ELSE
statement;
statement;
END_CASE

Figure 10: CASE statement structures

Example 20, Propose ST program to implement the block diagram shown in figure 11.

I0

I1

OR Q0

Switches

XOR

Swi
Switches
tch

es

I2 I3

Figure 11: One out of four logic functions


Solution:

V:=WORD_TO_INT(IN:=(SHR_WORD(IN:=IW0.0.0,N:=2) AND 16#0003));

CASE V OF

0: %QX0.0.0:= %IX0.0.0 AND %IX0.0.1;

1: %QX0.0.0:= %IX0.0.0 OR %IX0.0.1 ;

2: %QX0.0.0:= %IX0.0.0 XOR %IX0.0.1;

3: %QX0.0.0:= NOT %IX0.0.0 ;

END_CASE;

Example 21, Propose ST program to output the content of the selected location in
table 1 into %QW0.0.0.

CASE Location OF Location Contents


1: %QW0.0.0:= MOVE_WORD (IN:=16#8001); 1 16#8001
2 16#4002
2: %QW0.0.0:= MOVE_WORD (IN:= 16#4002);
3 16#2004
3: %QW0.0.0:= MOVE_WORD (IN:= 16#2004);
4 16#1008
4: %QW0.0.0:= MOVE_WORD (IN:= 16#1008; 5 16#0810
5: %QW0.0.0:= MOVE_WORD (IN:= 16#0810); 6 16#0420
6: %QW0.0.0:= MOVE_WORD (IN:= 16#0420); 7 16#0240
7: %QW0.0.0:= MOVE_WORD (IN:= 16#0240); 8 16#0180
8: %QW0.0.0:= MOVE_WORD (IN:= 16#0180); 9 16#0240
9: %QW0.0.0:= MOVE_WORD (IN:= 16#0240); 10 16#0420
10: %QW0.0.0:= MOVE_WORD (IN:= 16#0420); 11 16#0810
12 16#1008
11: %QW0.0.0:= MOVE_WORD (IN:= 16#0810);
13 16#2004
12: %QW0.0.0:= MOVE_WORD (IN:= 16#1008); 14 16#4002
13: %QW0.0.0:= MOVE_WORD (IN:= 16#2004); 15 16#8001
14: %QW0.0.0:= MOVE_WORD (IN:= 16#4002); 16 16#0000
15: %QW0.0.0:= MOVE_WORD (IN:=16#8001);
16: %QW0.0.0:= MOVE_WORD (IN:=16#0000);

END_CASE;
FOR Statements

FOR is used to do predetermined repetition times . It takes the general form shown in
figure 12. The instruction integer data type counter has three control parameters, the start,
the end, and the increment .

FOR Counter:= Start To END BY increment DO

Statement 1;

Statement n;

END_FOR;

Figure 12: FOR instruction general form.

Example 22, Write PLC program to sort the contents of the array Y whose elements
are stored in memory location %MW10 to %MW15 in an ascend manner;

Solution:

FOR I:= 0 TO 5 DO

FOR J:= I +1 TO 5 DO

IF Y[J]< Y[I] THEN

Dummy:=Y[I];

Y[I]:=Y[J];

Y[J]:=Dummy;

END_IF;

END_FOR;

END_FOR;

Example 23, Write PLC program to sort the contents of the array Y whose elements
are stored in memory location %MW10 to %MW15 in a descendent manner;

Solution:

FOR I:= 0 TO 5 DO
FOR J:= I +1 TO 5 DO

IF Y[J]> Y[I] THEN

Dummy:=Y[I];

Y[I]:=Y[J];

Y[J]:=Dummy;

END_IF;

END_FOR;

END_FOR;

WHILE Statements

WHILE is used to do repetition with unknown number of times . Here the continuity
of repetition depends upon the logical result of the expression comes immediately after the
WHILE word. That means it first examines the continuity flag and then decides to inter the
loop or goes out of it to allow the next statement to be executed. The syntax of this
statement is :

WHILE Expression is true DO

Statement 1;

Statement n;

END_WHILE;

Example 24, Write PLC program to search the contents of the array Y seeking a
given number. Assume Y to be one dimensional array of length equals 6;

Solution:

J:=0; // an integer data type

Location:=6; // the assigned value should be any number greater than Y length.

WHILE J<=5 DO

IF item=Y[J] THEN Location:=J; EXIT; END_IF;

J:=J + 1;

END_WHILE;
REPEAT Statements

REPEAT is used to do repetition with unknown number of times . Here the continuity
of repetition depends upon the logical result of the expression comes immediately after the
UNTIL word. That means it first executes the loop and then decides to repeat the loop or
goes out of it to allow the next statement to be executed. With this statement. the
loop is executed at least once because the continuity flag is examined at the end of the loop.
The syntax of this statement is :

REPEAT

Statement 1;

Statement n;

UNTIL Condition is true // no semicolon here

END_REPEAT;

Example 25, Using Newton's method, find the root of the equation 𝑥 3 − 𝑥 − 1 = 0

Solution:

Xn_1:=0.5; // assume an initial value to Xn_1;

REPEAT

Xn:=(2*Xn_1**3 +1)/(3*Xn_1**2-1); // Xn= Xn + f(x)/f '(x);

FX:=Xn**3- Xn -1;

Xn_1:=Xn;

UNTIL (ABS(FX)<=0.0000001)

END_REPEAT;
Human Machine Interface (HMI)

The touch panels which are also called human-machine interfaces (HMI) are
programmable devices permit the human operators to communicate with the industrial
control systems like for example the programmable logic controller (PLC), the variable
frequency drive (VFD) and the servo driver. There are large number of touch panel
manufacturers and each series of panels have their own programming software . As an
examples, XP_50TTA is LSIS product and is programmed using XP_BUILDER,
DOP_B10E615 is Delta one programmed by SCREEN_EDITOR, KTP_400 is Siemens
brand and is programmed by SIMATIC WINCC. In fact all the brands and supported
programming software shot the same birds, they provide the human operator with the
abilities to monitor the critical process variables in the way they prefer, input commands to
select the suitable control algorithm, direct the maintenance technicians to fault source (s) ,
give pictorial representation to the process under control, allow different languages
speakers to deal with the machinery, etc. Specifically one can say the programmed HMIs
have the ability to monitor and/or modify the controllers memory contents ( Input-
image register, output-image register, memory-registers) as bit, byte, word, dword, real,
and also as group of any of these types and also have the theme related display techniques.
Also here one must not forget that HMIs can be programmed with high level like
languages ( C, Basic) to implement their own tasks.
Here LSIS brand will be used to introduce the role of the HMI panels in the
industrial process control and the commonly used software programming components.

Software Programming Components

As stated before the HMI communicates with the programmable controller to read or
modifies their memory locations. The HMI itself deals with the operator through a number of
screens or pages on which the software graphical components or interfaces are positioned.
Some of these components act as a mirror to display what are going inside the
programmable controller and others as loaders responsible to load or modify the memory
locations with the desired values. The following are the most commonly used items or
components in this context.

1- Bit Switch

Bit switch is used to control the ON/OFF of the relevant PLC bit address. It can be
assigned any shape from the programming environment library or new created shapes.
It may be found in one of four modes. These are:
1- ON mode: Pressing the bit switch under this mode sets the PLC relevant bit on and
preserves the on state whether the switch is still pressed or not.
2- OFF mode : Pressing the bit switch with this mode resets the PLC relevant bit previously
set by a bit switch of on mode. The state is preserved whether the switch is still pressed or
not.
3- Momentary mode: Here the bit switch behaves as if it were normally open pushbutton. As
long as the switch is pressed the PLC relevant bit is on. The time the switch is released the
PLC bit return to its normal value.
4- Alternative mode: In this mode of operation, each time the bit switch is pressed the PLC
relevant bit is inverted that means if it was on before the pressing, after the pressing it
becomes off and if it was off it becomes on.

Example 1 , Design HMI interface screen to enable the operator to : (1): Control the
on/off state of a lamp using one bit switch. (2): To start/stop motor starter using two
pushbutton like approach. (3): To set/reset PLC memory bit %MW2.0 which controls
coil Y. Also attach the relevant PLC ladder program.

Solution:

OFF:%MW1.0 ON:%MW1.1 MCCoil:%QX0.0.1

MCCoil

%MW2.0 Y

(b)
(a)

Bit Switch Lamp ON OFF SET RESET


Mode Alternative Momentary Momentary ON OFF
Address %QX0.0.0 %MW1.1 %MW1.0 %MW2.0 %MW2.0

Figure 1: a): Interface HMI page. b): PLC ladder diagram. c): Bit switches modes and
their PLC relevant
2- Bit Lamp

Bit lamp is used to display the ON/OFF state of the relevant PLC bit address. Its default
shape is lamp shape, but it can be assigned any shape from the programming environment
library or new created shapes.
Example 2 , Design HMI interface screen to enable the operator to on/off and monitor
star/delta starter. Also attach the relevant PLC ladder program.

Solution:

OFF ON Main

Main
Main T1
TON
IN Q

T#6S PT ET

Main T1.Q Delta Star

Main T1.Q Star Delta


(a)

(b)
Bit Device Type Mode Address
OFF Bit switch Momentary %MW1.0
ON Bit switch Momentary %MW1.1
Main Bit lamp %QX0.0.0
Star Bit lamp %QX0.0.1
Delta Bit lamp %QX0.0.2

Figure 2: a): Interface HMI page. b): PLC ladder diagram. c): Bit devices characteristics

3- Word Switch

Word switch is used to modifies the content of 16bit or 32 bit size PLC memory address.
As 16bit switch it can support Signed and Unsigned DEC PLC data types, and as 32bit size
supports Signed DEC, Unsigned DEC, and Float PLC data types. It can take any shape from
the programming environment shape's libraries or assigned new shape according to the
designer understanding. The operation margin of this switch extends to four mode of
operations. These are :
1- Set mode: Pressing the word switch under this configuration writes the direct or
indirect set value in the PLC relevant address. With direct set value ( constant) it
preserves that value whether the switch is still pressed or not. With indirect one ( content of
another device) the relevant PLC address receives that of the another at the pressing
instance.
Example 3 , In ice cream filling machine, the quantity of drawn ice cream depends upon
the time interval the outlet solenoid valve is activated. Assume there are three cone sizes,
Design PLC ladder program and HMI interface screen to enable the operator to select the
proper filling utility.

Solution:

TPFILL
Fill %QX0.0.0
TP_UNIT
Switches
P IN Q
Switches
Switches
%MW4 Swit
PT ET
Swit

ches ches
Switche Swit Swit
100 UNIT
s ches ches
Switche Switch
0 RST
s es
S Swit

w ches (b)
i
(a) t

Device Type Set Address Position h Display


used Value e
Fill- Bit lamp
Figure 12.3: a): Interface HMI page. b):%QX0.0.0
PLC ladderAs stated in thes(a)
diagram. c): B) devicesVisible
characteristics
Solenoid

Family Word Switch 400 %MW4 Under family size cone Transparent
Size
Medium Word Switch 200 %MW4 Under medium size cone Transparent
Size
Small Word Switch 100 %MW4 Under small size cone Transparent
Size
Fill Momentary Bit Switch %MW1.0 Under each cone Transparent
(c)

2- ADD mode: Pressing the word switch add the direct or indirect set value to the PLC
relevant address. With direct set value, each time the switch is pressed, the relevant PLC
address's value is increased by constant increment whereas with indirect one the increase
amount is function of the indirect address value at the pressing time.

3- SUB mode: Pressing the word switch subtract the direct or indirect set value from
the PLC relevant address. With direct set value, each time the switch is pressed, the
relevant PLC address's value is decreased by constant decrement whereas with
indirect one the decrement amount is function of the indirect address value at the
pressing time.
Example 4 , In plastic bottle blowing machinery, the bottle shape depends upon three
heaters running along the bottle route to the mold. These heaters are the upper, middle,
and lower heaters. Suggest an HMI screen to allow the user to fine and coarse controls these
heaters to force the ampoules to take the mold shape. Assume the heaters to be driven
by digital to analog module with four channels (channel’s input words are :
%UW0.1.3, %UW0.1.4, %UW0.1.5, %UW0.1.6).

Solution:

4- Digit ADD: Pressing the word switch increments the PLC relevant address value. The
Upper Heater Middle Heater Lower Heater
Word Set PLC Mode Set PLC Mode Set Value PLC
Switch Mode Value Address value Address Address

ADD 1 %UW0.1.3 ADD 1 %UW0.1.4 ADD 1 %UW0.1.5

ADD 50 %UW0.1.3 ADD 50 %UW0.1.4 ADD 50 %UW0.1.5

SUB 1 %UW0.1.3 SUB 1 %UW0.1.4 SUB 1 %UW0.1.5

SUB 50 %UW0.1.3 SUB 50 %UW0.1.4 SUB 50 %UW0.1.5

increment amount is function of the selected number system (HEX or BCD) and the
position of the digit to be incremented by 1. For example selecting BCD as the number
system and 2 as the digit position, each press increments the tenth position by one until
reaching 9 after which the tenth position returns to zero and new increment cycle start again.

Example 5 , Design HMI page such that the operator can set the PLC memory word
%MW4 in thumb wheel like manner.
Solution:

Device Type Operation Mode Set Address


Value
Numeric 16 bit, BCD %MW4
display
Word Switch Digit ADD 4 %MW4

Word Switch Digit ADD 3 %MW4

Word Switch Digit ADD 2 %MW4

Word Switch Digit ADD 1 %MW4

5- Digit SUB: Pressing the word switch decrements the PLC relevant address value. The
decrement amount is function of the selected number system (HEX or BCD) and the
position of the digit to be decremented by 1. For example selecting BCD as the number
system and 3 as the digit position, each press decrements the hundredths position by 1 until
reaching 0 after which the hundredths position returns to 9 and new decrement cycle start
again.

Example 6 , Design HMI page such that the operator can set the PLC memory word
%MW4 in thumb wheel like decreasing manner .

Solution:
Device Type Operation Mode Set Address
Value
Numeric 16 bit, BCD %MW4
display
Word Switch Digit ADD 4 %MW4

Word Switch Digit ADD 3 %MW4

Word Switch Digit ADD 2 %MW4

Word Switch Digit ADD 1 %MW4


6- Script: Pressing the word switch executes the assigned C language program segment like
script.

Example 7 , Give HMI utility that inverts the state of %MW1.0 each time the word
switch %HW4 is pressed;

Solution:

Device Type Operation Mode Set Address


Value
Bit lamp %MW1.0

Word Switch Script invert %HW4

// Scrip name is invert

@[X:%MW0.0]=!@[X:%MW0.0];

Error:

4- Numeric Input

This device is used to modify and display the PLC related word or double Word.
For 16 bit size word the supported numeric formats are the unsigned DEC, signed DEC,
Octal, Hex, Bin, and BCD . For 32 bit size, the float data type is added to the previous list.
This numeric device allows the designer to modify the relevant PLC word with the scaled
version of what is entered in this device in addition to keep the entered value between the
selected minimum and maximum limits if scaling check box is marked. Masking the input
data is possible if the cipher check box is selected. Here and only
for 32 bit size word, one must understand that memory word k (%MWk) refers to the
PLC's memory double k/2 (%MD(k/2) k is positive even integer).

Example 8 , Propose HMI screen to allow the operator to modify any item of 4*4 real
data type matrix. Assume the PLC name of this matrix is Y, its start address is %MD0, the
rth raw index address is MW40, and the cth column index address is %MW41 ( MW40 and
MW41 are both of 16bit size.
Solution:
HMI Screen HMI Devices Address Map

%MW2 %MW4 %MW6 %MW8

%MW10 %MW112 %MW14 %MW16

%MW18 %MW20 %MW22 %MW24

%MW26 %MW28 %MW30 %MW32

%MW32 %MW40.0 %MW40.1

PLC program segment PLC Relevant Address Map ( Y items addresses )

// ST instruction
%MD1 %MD2 %MD3 %MD4
// r is integer type data with address %MW40
%MD5 %MD6 %MD7 %MD8
// c is integer type data with address %MW41
%MD9 %MD10 %MD11 %MD12
// Z is real type data with address %MD17
%MD13 %MD14 %MD15 %MD16
Z:= Y[r,c];

%MD1 %MW40.0 %MW40.1

5- Numeric Display

This device is used to display the PLC related word or double Word according to
the required format. For 16bit size word the supported numeric formats are the unsigned
DEC, signed DEC, Octal, Hex, Bin, and BCD . For 32 bit size, the float data type is added
to the previous list. It also provides scaling facility so that the PLC related address content
can be transformed to the value the end user can well understand or in other words to
emulate the real environment.

Example 9 , Design HMI utility that displays the binary, octal, and hex equivalent of
unsigned decimal number.
Solution:

15 1111 17 F

Numeric Type Configuration Set Address


item Value
input Unsigned Dec %MW1
1
5

Display Bin %MW1


1111

Display Octal %MW1


17
1
7

Display Hex %MW1


F

6- Graph meter

The graph meter display device displays the value of PLC relevant word or double word
numeric data in term of the position of clock like hand moving clockwise or counter clock
wise inside one of circle, top-half circle, bottom-half circle, left-half circle, right-half circle,
top-fan, bottom-fan, left-fan, right-fan, or 3/4 fan shapes. The pointer swings between upper
and lower limits fixed during the design phase of this device. This device deals with word
and double word data types. For word (16bit size), the supported numeric formats are
the unsigned DEC, signed DEC, and BCD . For double word ( 32 bit size), unsigned
DEC, signed DEC, BCD, and float data type are supported.
Example 10 , Design clock page with three hands ( second hand, minute hand, hour
hands).

Solution:

Item Address Lower Lower PG image Border Direction Point Function


limit limit (x)
setting setting
Graph %MW220 0 60 Transparent Transparent CW 0 Seconds hand
meter
Graph %MW221 0 60 Transparent Transparent CW 12 Minutes hand
meter
Graph %MW222 0 60 Transparent Transparent CW 0 Hours hand
meter

You might also like