PLC
PLC
LIST OF CONTENTS
Unit1
Introduction to PLC, Concept of PLC - Building blocks of PLC - Functions of various blocks,
- limitations of relays - Advantages of PLCs over electromagnetic relays - Different
programming languages - PLC manufacturer etc.
Unit 2
Working of PLC, Basic operation and principles of PLC, Architectural details
processor Memory structures - I/O structure Programming terminal - Power supply
Unit3
Instruction Set - Basic instructions bit.-Timer instruction like retentive timers, resetting of timers -
Counter instructions like up counter, down counter, resetting of counters.- Arithmetic Instructions
(ADD,SUB,DIV,MUL etc.)- MOV instruction - Comparison instructions like equal, not equal, greater,
greater than equal, less than, less than equal
4. Ladder Diagram Programming
5 Applications of PLCs
6 Micro Controller Series(MCS)-51Over View
7 Instruction Set Addressing Modes
8 Assembly language programming
9 Design and Interface
UNIT I
What is PLC?
Programmable Logic Controller (PLC) is a digital computer used for the automation of various
electro-mechanical processes in industries. These controllers are specially designed to survive in harsh
situations and shielded from heat, cold, dust, and moisture etc. PLC consists of a microprocessor which
is programmed using the computer language.
The program is written on a computer and is downloaded to the PLC via cable. These loaded programs
are stored in non – volatile memory of the PLC. During the transition of relay control panels to PLC, the
hard wired relay logic was exchanged for the program fed by the user. A visual programming language
known as the Ladder Logic was created to program the PLC.
2|Page
1.4 Building blocks of PLC
PLCs have input/output devices like switches, push buttons, limit switches,sensors,lamp
indicators,relays solenoids motors etc. block diagram of a PLC shown in above Fig. It has three
major units/sections.
The input module has bank of terminals for physically connecting input devices, like push buttons,
limit switches etc. to a PLC. The role of an input module is to translate signals from input devices into
a form that the PLC's CPU can understand.
The Output module also has bank of terminals that physically connect output devices like solenoids,
motor starters, indicating lamps etc. to a PLC. The role of an output module is to translate signals
from the PLC's CPU into a form that the output device can use. The tasks of the I/O section can be
classified as:
• Conditioning
3|Page
• Isolation
• Termination
• Indication
An electronic system for connecting I/O modules to remotely located I/O devices can be added if
needed. The actual operating process under PLC Control can be thousands of feet from the CPU and
its I/O modules.
CPU Section:-
The Central Processing Unit, the brain of the system is the control portion of the PLC. It has
three Subparts.
• Memory System
• Processor
• Power Supply
Memory System:-
The memory is the area of the CPU in which data and information is stored and retrieved. The total
memory area can be subdivided into the following four Sections.
The input image memory consists of memory locations used to hold the ON or OFF states of each input
field devices, in the input status file.
The output status file consists of memory locations that stores the ON or OFF states of hardware output
devices in the field. Data is stored in the output status file as a result of solving user program and is
waiting to be transferred to the output module's switching device.
Data Memory - It is used to store numerical data required in math calculation, bar code data etc.
Executive Memory - It is used to store an executive program or system software. An operating system of
the PLC is a special program that controls the action of CPU and consequently the execution of the
user's program. A PLC operating system s designed to scan image memory, interprets the instruction of
user's program stored in main memory, and executes the user's application program the operating
system is supplied by the PLC manufacturer and is permanently held in memory.
Processor:-The processor, the heart of CPU is the computerized part of the CPU in the form of
Microprocessor / Micro controller chip. It supervises all operation in the system and performs all
tasks necessary to fulfill the PLC function.
• It reads the information i.e. status of externally connected input devices with input module.
It stores this information in memory for later use.
It carries out mathematical and logic operations as specified in application program.
After solving the user's program, it writes the result values in the memory.
It sends data out to external devices like output module, so as to actuate field hardware.
It performs peripheral and external device communication.
4|Page
Power Supply -
The power supply provides power to memory system, processor and I/O Modules.
It converts the higher level AC line Voltage to various operational DC values.
For electronic circuitry.
It filters and regulates the DC voltages to ensure proper computer operations.
Programmer/Monitor -
The Programmer/Monitor (PM) is a device used to communicate with the circuits of
the PLC. The programming unit allows the engineer/technicians to enter the edit the program to be
executed. In its simplest form it can be hand-held device with membrane keypad for program entry and a
display device (LED or LCD) for viewing program steps of functions. More advanced systems employ a
separate industrial terminal or personal computers with type-writer type keyboard and CRT monitors.
With the help of proprietary software, it allows programmer to write, view and edit the program and
download it into the PLC. It also allows user to monitor the PLC as it is running the program. With this
monitoring systems, such things as internal coils, registers, timers and other items not visible externally
can be monitored to determine proper operation. Also, internal register data can be altered, if required. to
fine tune program operation while debugging. Communication between PM and PLC is done via a cable
connected to a special programming port on PLC. Connection to the personal computer can be through a
serial port or from a dedicated card installed in the computer.
1.6 PLC Programming language - Using flowcharts, Using ladder logic and Using statement logics or
mnemonics
1.7 PLC manufacturer - Allen Bradley, Rockwell Automation, Mitsubishi, Omron, Siemens etc.
A) Bill Gates
B) Dick Morley
C) Bill Landis
D) Tod Cunningham
5|Page
Q4. In a PLC, the scan time refers to the amount of time in which …..
a. Siemens
b. Mitsubishi
c. Microsoft
d. ABB
Q1 Define PLC
Q2 What are the limitations of relay over PLC
Q3 Explain building blocks of PLC in detail
Q4 List the names of PLC manufacturer.
6|Page
UNIT 2
7|Page
PC
Program
Loader
Switches
Printer
I/O
Processor Modules Machines
Cassette
Loader
Power
Memory
EPROM Supply
Loader
Peripherals External Devices
System Buses – Buses are the paths through which the digital signal flows internally of the PLC.
The four system buses are:
• Data bus is used by the CPU to transfer data among different elements.
• Control bus transfers signals related to the action that are controlled internally.
• Address bus sends the location’s addresses to access the data.
• System bus helps the I/O port and I/O unit to communicate with each other
8|Page
2.3 The memory space can be divided into two broad categories:
Advanced ladder logic functions allow controllers to perform calculations, make decisions and do other
complex tasks. Timers and counters are examples of ladder logic functions. They are more complex than
basic inputs contacts and output coils and relay heavily upon data stored in the memory of the PLC.
The user program will account for most of the memory of a PLC system. Program files contain the
logic controlling machine operation. This logic consists of instructions that are programmed in a ladder
logic format.
The data file portion of memory stores input and output status, processor status, the status of various
bits and numerical data.
9|Page
Multiple Choice Questions
a. Motor
b. Light
c. Valve
d. Sensor
a. Analog output
b. Digital output
c. Analog input
d. Digital input
Q.3 The type of memory which is fast and temporarily stores the data which are
immediately required for use is called as______.
a. HDD
b. ROM
c. RAM
d. SSD
Q.4 how is the speed of operation of conventional relay system as compared to digital controllers?
a. very slow
b. very fast
c. same
d. almost similar
a. machine tools
b. automated assembly equipment
c. moulding and extrusion machines
d. all of the above
10 | P a g e
UNIT 3 INSTRUCTION SETS
3.PLC Instructions
3.1 Bit instructions
3.2 Timer and Counter instructions
3.3 Program Control Instructions
3.4 Compare Instructions
3.5 Math Instructions
11 | P a g e
TOF Timer Off A non-retentive timer that accumulates
Delay time when the rung makes a true-to-
false transition.
12 | P a g e
3.3 Move/Logical Instructions
SWPB Swap Byte Rearranges the bytes of a tag and stores the
Instruction bytes in the new order.
BTD Bit Field Copies the specified bits from the Source,
Distribute shifts the bits to the appropriate position,
and writes the bits into the Destination.
13 | P a g e
AND Bitwise AND Performs a logical AND operation by using
the bits in Source A and Source B and
placing the result in the Destination.
14 | P a g e
MCR Master Cont. Used in pairs to create a program zone that
Res. can disable all rungs between the MCR
instructions.
15 | P a g e
LES Less Than This instruction determines whether Source A
is less than Source B.
16 | P a g e
DIV Divide Divides Source A by Source B and places
the result in the Destination.
SQR Square Root Calculates the square root of the source and
places the integer result in the Destination.
17 | P a g e
B. Preset value of timer 6 in file 4.
C. Accumulator for timer 6 in file 4.
D. Accumulator for counter 6 in file 4.
Q4: To reset the time for a PLC what condition must be true?
A. Reset rung of TON must be true.
B. Reset rung of TON must be false.
C. RST instruction with timer address must be true.
D. RST instruction with associated timer address must be false.
Question 5: To increase the number of inputs and outputs of the PLC, one can use expansion modules.
A. True.
B. False.
C. None of the above.
Question 6: Solenoids, lamps, motors are connected to:
A. Analog output.
B. Digital output.
C. Analog input.
D. Digital input
Question 7: In a counter instruction if the accumulator value becomes greater than or equal to the
preset value then which of the following is true?
A. CU bit goes on.
B. DN bit goes on.
C. Both CU and DN bits go on.
D. None of the above.
Short / long Answer type Questions
Q1 Explain time instructions in detail
Q2 Explain Counter instructions in detail
4 Ladder Logic
Let’s take a look at an example of ladder logic programming:
This ladder logic program is three rungs long. The program is “scanned” or run by the CPU from left
to right and top to bottom. The symbols placed throughout the rungs are actually graphical
instructions. The names for these instructions are:
First Rung
Looking at the first rung, notice the first two inputs I:1/1 and I:1/2. The symbol is an XIC, and the I
denotes that this is an input. This instruction represents a physical input found on one of the discrete
input cards.
Figure 2. The first rung represents a physical input found on one of the discrete input cards.
I:1 means that this input card has been placed in slot 1, directly adjacent to the processor. The /1
indicates the bit of interest. Input cards have more than one channel, and if the instruction specifies
/1, the instruction accesses channel 1.
The second input represents channel 2 on the same card. An XIC instruction really means true if
closed. That is, this instruction will be true if the input device it represents is closed. If an instruction
is true it is highlighted in green. The only way for an output to be energized is if a path of true
instructions can be traced from the left rail to the right rail. Therefore, the output on rung one will be
true because a path of true instructions, I:1/1 and I:1/2, exists. This is effectively an AND operation.
The output in this case, B: 0/1, is actually an internal bit stored in the PLC's memory. That’s why it’s
labeled B instead of O for “output.” These internal bits work great when a certain state or set of
inputs needs to be recorded without actually turning on a physical output.
Unit 5
Product packaging is one of the most frequent cases for automation in industry. It can be encountered
with small machines (ex. packaging grain like food products) and large systems such as machines for
packaging medications. Example we are showing here solves the classic packaging problem with few
elements of automation. Small number of needed inputs and outputs provides for the use of CPM1A
PLC controller which represents simple and economical solution.
By
pushing START key you activate Flag1 which represents an assisting flag (Segment 1) that comes up
as a condition in further program (resetting depends only on a STOP key). When started, motor of an
conveyor for boxes is activated. The conveyor takes a box up to the limit switch, and a motor stops
then (Segment 4). Condition for starting a conveyor with apples is actually a limit switch for a box.
When a box is detected, a conveyor with apples starts moving (Segment 2). Presence of the box
allows counter to count 10 apples through a sensor used for apples and to generate counter CNT010
flag which is a condition for new activation of a conveyor with boxes (Segment 3). When the
conveyor with boxes has been activated, limit switch resets counter which is again ready to count 10
apples. Operations repeat until STOP key is pressed when condition for setting Flag1 is lost. Picture
below gives a time diagram for a packaging line signal.
Ladder diagram:
Traffic light control using PLC
Pump control
6. 8051 Microcontroller
A microcontroller is a small and low-cost microcomputer, which is designed to perform the specific
tasks of embedded systems like displaying microwave’s information, receiving remote signals, etc.
The general microcontroller consists of the processor, the memory (RAM, ROM, EPROM), Serial
ports, peripherals (timers, counters), etc.
Microcontroller Microprocessor
Microcontrollers are used to execute a single Microprocessors are used for big
task within an application. applications.
Its designing and hardware cost is low. Its designing and hardware cost is high.
It is built with CMOS technology, which Its power consumption is high because it
requires less power to operate. has to control the entire system.
It consists of CPU, RAM, ROM, I/O ports. It doesn’t consist of RAM, ROM, I/O ports.
It uses its pins to interface to peripheral
devices.
Types of Microcontrollers
Microcontrollers are divided into various categories based on memory, architecture, bits and
instruction sets. Following is the list of their types −
Bit
Based on bit configuration, the microcontroller is further divided into three categories.
8-bit microcontroller − This type of microcontroller is used to execute arithmetic and logical
operations like addition, subtraction, multiplication division, etc. For example, Intel 8031 and
8051 are 8 bits microcontroller.
16-bit microcontroller − This type of microcontroller is used to perform arithmetic and
logical operations where higher accuracy and performance is required. For example, Intel
8096 is a 16-bit microcontroller.
Memory
Based on the memory configuration, the microcontroller is further divided into two categories.
Instruction Set
Based on the instruction set configuration, the microcontroller is further divided into two categories.
CISC − CISC stands for complex instruction set computer. It allows the user to insert a single
instruction as an alternative to many simple instructions.
RISC − RISC stands for Reduced Instruction Set Computers. It reduces the operational time
by shortening the clock cycle per instruction.
Applications of Microcontrollers
Microcontrollers are widely used in various different devices such as −
Pins 1 to 8 − These pins are known as Port 1. This port doesn’t serve any other functions. It is
internally pulled up, bi-directional I/O port.
Pin 9 − It is a RESET pin, which is used to reset the microcontroller to its initial values.
Pins 10 to 17 − These pins are known as Port 3. This port serves some functions like
interrupts, timer input, control signals, serial communication signals RxD and TxD, etc.
Pins 18 & 19 − These pins are used for interfacing an external crystal to get the system clock.
Pins 21 to 28 − These pins are known as Port 2. It serves as I/O port. Higher order address bus
signals are also multiplexed using this port.
Pin 29 − This is PSEN pin which stands for Program Store Enable. It is used to read a signal
from the external program memory.
Pin 30 − This is EA pin which stands for External Access input. It is used to enable/disable the
external memory interfacing.
Pin 31 − This is ALE pin which stands for Address Latch Enable. It is used to demultiplex the
address-data signal of port.
Pins 32 to 39 − These pins are known as Port 0. It serves as I/O port. Lower order address and
data bus signals are multiplexed using this port.
8051 microcontrollers have 4 I/O ports each of 8-bit, which can be configured as input or output.
Hence, total 32 input/output pins allow the microcontroller to be connected with the peripheral
devices.
Pin configuration, i.e. the pin can be configured as 1 for input and 0 for output as per the logic
state.
o Input/output (I/O) pin − All the circuits within the microcontroller must be connected
to one of its pins except P0 port because it does not have pull-up resistors built-in.
o Input pin − Logic 1 is applied to a bit of the P register. The output FE transistor is
turned off and the other pin remains connected to the power supply voltage over a pull-
up resistor of high resistance.
o When the external memory is used then the lower address byte (addresses A0A7) is
applied on it, else all bits of this port are configured as input/output.
o When P0 port is configured as an output then other ports consisting of pins with built-in
pull-up resistor connected by its end to 5V power supply, the pins of this port have this
resistor left out.
Input Configuration
If any pin of this port is configured as an input, then it acts as if it “floats”, i.e. the input has unlimited
input resistance and in-determined potential.
Output Configuration
When the pin is configured as an output, then it acts as an “open drain”. By applying logic 0 to a port
bit, the appropriate pin will be connected to ground (0V), and applying logic 1, the external output
will keep on “floating”.
In order to apply logic 1 (5V) on this output pin, it is necessary to build an external pullup resistor.
Port 1
P1 is a true I/O port as it doesn’t have any alternative functions as in P0, but this port can be
configured as general I/O only. It has a built-in pull-up resistor and is completely compatible with
TTL circuits.
Port 2
P2 is similar to P0 when the external memory is used. Pins of this port occupy addresses intended for
the external memory chip. This port can be used for higher address byte with addresses A8-A15.
When no memory is added then this port can be used as a general input/output port similar to Port 1.
Port 3
In this port, functions are similar to other ports except that the logic 1 must be applied to appropriate
bit of the P3 register.
When these pins are configured as inputs (i.e. logic 1), then built-in pull-up resistors provide
very weak current, but can activate up to 4 TTL inputs of LS series.
If all 8 bits of a port are active, then the total current must be limited to 15mA (port P0:
26mA).
In the "timer" function mode, the counter is incremented in every machine cycle. Thus, one can think of it as
counting machine cycles. Hence the clock rate is 1/12 th of the oscillator frequency.
In the "counter" function mode, the register is incremented in response to a 1 to 0 transition at its
corresponding external input pin (T0 or T1). It requires 2 machine cycles to detect a high to low transition.
Hence maximum count rate is 1/24 th of oscillator frequency.
The operation of the timers/counters is controlled by two special function registers, TMOD and TCON
respectively.
Timer Mode control (TMOD) Special Function Register:
Timer Mode-0:
In this mode, the timer is used as a 13-bit UP counter as follows.
The input pulse is obtained from the previous stage. If TR1/0 bit is 1 and Gate bit is 0, the counter continues
counting up. If TR1/0 bit is 1 and Gate bit is 1, then the operation of the counter is controlled by input.
This mode is useful to measure the width of a given pulse fed to input.
Timer Mode-1:
This mode is similar to mode-0 except for the fact that the Timer operates in 16-bit mode.
Interrupts are the events that temporarily suspend the main program, pass the control to the external
sources and execute their task. It then passes the control to the main program where it had left off.
8051 has 5 interrupt signals, i.e. INT0, TFO, INT1, TF1, RI/TI. Each interrupt can be enabled or
disabled by setting bits of the IE register and the whole interrupt system can be disabled by clearing
the EA bit of the same register.
A low priority interrupt can only be interrupted by the high priority interrupt, but not
interrupted by another low priority interrupt.
If two interrupts of different priority levels are received simultaneously, the request of higher
priority level is served.
If the requests of the same priority levels are received simultaneously, then the internal polling
sequence determines which request is to be serviced.
ORG: The origin (ORG) instruction tells the assembler the address of the memory location for the next
instruction or data byte should be assembled. ORG is entered at the beginning of a program. When
different parts of a programme (e.g. subroutines) are to be placed in different areas of memory, an
ORG pseudo instruction is used before each part of the program to specify the starting location for
assembly of that part of the program. The origin instruction has the following form
END: When an assembler scans the program to be assembled it must know, where the program ends. It
cannot depend on a HLT instruction for this because some programmes don’t contain a halt instruction
as the last instruction and other don’t contain a halt at all. An application program used, e.g., in process
monitoring on control might run continuously and, therefore, not contain a halt instruction. Thus, an
end assembly, END directive must be the last instruction. The directive has a form. END
The END statement explicitly indicates the end of the program to the assembler. If no END statement
is given, then the assembler just keeps on running through all the memory.
The ORG and END assembler directives, in effect, frame the program to be assembled. ORG 0000H
[Assembly language instructions] END
EQU: Symbolic names, which appear in assembly language programs as labels, instructions
mnemonics and operands are translated to binary values by the assembler. As discussed in
handassembly the labels are assigned the current value of the assembler’s location counter when
encountered in the first pass of the assembly. Instruction mnemonics have predefined values that the
assembler obtains from a table that is part of the assembler.
DB: When a table of fixed data values is required, memory must also be allocated. However, unlike
the DS, each memory locations must have a defined value that is assembled into it.
DW: Define word DW instruction is similar to define byte pseudo instruction. opt. name: DW list The
only difference between the DB & DW is that expression in this define word list is evaluated to 16-bit
quantity and stored as 2-bytes. It is stored with the lower order byte in the lower of the two memory
locations and the higher order byte in the next higher location
Light Emitting Diodes or LEDs are the mostly commonly used components in many applications.
They are made of semiconducting material. In this project, I will describe about basics of Interfacing
LED with 8051 Microcontroller.
The main principle of this circuit is to interface LEDs to the 8051 family micro controller. Commonly,
used LEDs will have voltage drop of 1.7v and current of 10mA to glow at full intensity. This is applied
through the output pin of the micro controller.
Circuit Diagram
NOTE: I suggest you to connect 1KΩ Pull-up resistors to all the pins of PORT0 of 8051. I haven’t
shown that connection in this circuit diagram
Components Required
Circuit Design
The circuit mainly consists of AT89C51 microcontroller. AT89C51 belongs to the family of 8051
microcontroller. It is an 8-bit microcontroller. This microcontroller has 4KB of Flash Programmable
and Erasable Read Only Memory and 128 bytes of RAM. This can be programmed and erased a
maximum of 1000 times.
It has two 16 bit timers/counters. It supports USART communication protocol. It has 40 pins. There are
four ports are designated as P0, P1, P2, and P3. Port P0 will not have internal pull- ups, while the other
ports have internal pull-ups.
Microcontroller Questions
Question1. Introduction of 8051 Microcontroller Architecture?
Answer :
In 1981, Intel Corporation introduced an 8-bit microcontroller called the 8051. The 8051 became
widely popular after Intel allowed other manufacturers to make and market any flavors of the 8051.
They please with the condition that they remain code-compatible with the 8051. This has led to many,
versions of the 8051 with different speeds and amounts of on-chip ROM marketed by more than half a
dozen manufacturers. It is important to note that although there are different flavors of the 8051 in
terms of speed and amount of on-chip ROM, they are all compatible with the original 8051 as far as
the instructions are concerned. This means that if you write your program for one, it will run on any of
them regardless of the manufacturer.
Question 2. Intel 8051 Follows Which Architecture?
Answer :
Intel 8051 is Harvard Architecture.
Question 3. What Is The Difference Between Harvard Architecture And Von Neumann
Architecture?
Answer :
The name Harvard Architecture comes from the Harvard Mark. The most obvious characteristic of
the Harvard Architecture is that it has physically separate signals and storage for code and data
memory. It is possible to access program memory and data memory simultaneously. Typically, code
(or program) memory is read-only and data memory is read-write. Therefore, it is impossible for
program contents to be modified by the program itself.
The von Neumann Architecture is named after the mathematician and early computer scientist John
von Neumann. Von Neumann machines have shared signals and memory for code and data. Thus,
the program can be easily modified by itself since it is stored in read-write memory.
Question 4. 8051 Was Developed Using Which Technology?
Answer :
Intel’s original MCS-51 family was developed using NMOS technology, but later versions,
identified by a letter C in their name (e.g., 80C51) used CMOS technology and consume less power
than their NMOS predecessors. This made them more suitable for battery-powered devices.
Question 5. Why 8051 Is Called 8 Bit Microcontroller?
Answer :
The Intel 8051 is an 8-bit microcontroller which means that most available operations are limited to
8 bits.
Question 6. What Is The Width Of Data Bus?
Answer :
8-bit data bus
Question 7. What Is The Width Of Address Bus?
Answer :
16-bit address bus
Question 8. List Out The Features Of 8051 Microcontroller?
Answer :
o 40 Pin IC.
o 128 bytes of RAM.
o 4K ROM.
o 2 Timers (Timer 0 and Timer 1).
o 32 Input/ Output pins.
o 1 serial port.
o 6 Interrupts (Including Reset).
Question 9. What Location Code Memory Space And Data Memory Space Begins?
Answer :
At location 0x00 for internal or external memory
Question 10. How Much On Chip Ram Is Available?
Answer :
128 bytes of RAM (from 0x00 to 0x7F) and can be used to store data.
Question 11. List out Addressing Modes In Mcs-51?
Answer :
o Direct Addressing
o Register Addressing
o Register Indirect Addressing
o Implicit Addressing
o Immediate Addressing
o Index Addressing