Unit 4 - L Notes - Introduction To Microcontroller
Unit 4 - L Notes - Introduction To Microcontroller
Introduction to Microcontrollers
Introduction
Microcontroller Vs Microprocessors
A microprocessor is a single chip CPU (Central Processing Unit) in which the memory
and peripherals are connected externally. A microcontroller consists of processor,
peripherals include Memory (RAM and ROM), I/O ports, Timers/Counters,
Communication Interface, ADC etc.
A microcontroller does not require additional interfacing ICs for operation and it
functions as a stand-alone system.
The clock speed of a microcontroller varies from a few MHz to 50 MHz whereas the
microprocessors can operate clock speed above 1 GHz.
In 1975, Intel fabricated a chip (Intel 8048) with inbuilt RAM and ROM which was widely
used in varieties of applications. The EPROM and PROM included later in the microcontrollers.
The Intel Corporation released an 8-bit version in the year 1981 called the IC8051 which became
popular and widely used for industrial applications.
`
A microcontroller can be considered a self-contained system with a processor, memory and
peripherals and can be used as an embedded system. The majority of microcontrollers in use
today are embedded in other machinery, such as automobiles, telephones, appliances, and
peripherals for computer systems.
Types of Microcontrollers
8-bit microcontroller
When in-house bus in a MCU is 8-bit bus then the ALU carries out the logic & arithmetic
operations on a byte at an order. The MCU is 8-bit micro-controller. The illustrations of 8-bit
MCU are- Intel 8031/8051, Motorola MC68HC11 & PIC1x families.
16-bit microcontroller
The 16 bit Microcontroller consists of a 16 bit bus and the ALU performs arithmetic and logic
operations on the 16 bit operand.
32-bit microcontroller
When in-house bus for the data transmitting function in an MCU is 32-bit bus then the ALU
carries out logic & arithmetic functions on operand words of 32 bits at the orders. The MCU
is 32-bit micro-controller.
Different Families of Microcontroller:
Intel Family
Intel Corporation introduced the 8051 microcontroller. It is 8-bit, inbuilt RAM and ROM,
timers/Counters, Serial ports, 12 clocks per instruction etc. But the 8051 microcontroller does not
have an in built memory bus and Analog to Digital Converters (ADC). In 1980, Intel fabricated
the single chip microcontroller 8051 with Harvard architecture.
PIC Family
PIC (Programmable Interface Controller) microcontrollers are slightly older than 8051
microcontrollers and it offers high performance. The single chip PIC microcontroller was
introduced by Microchip technology fabricated with Harvard architecture. The programming part
is very complex and hence it is not suitable choice for beginners.
AVR Family
In the year 1996, Atmel fabricated the single chip AVR microcontroller with a modified
Harvard Architecture. This chip is loaded with C- compiler, Free IDE (Integrated Development
`
Environment) and it has lot of features. This microcontroller is little bit difficult for the beginners
to handle.
Maximum speed
On-chip RAM and ROM capacity
Cost efficient
On-chip peripherals
Number of I/O pins
Microcontroller has an input device in order to get the input and an output device to display the
final process output. For example, Microcontroller is used in electronic applications such as
Television. The Television has a remote control which is input device and the TV screen is the
output device. The signal sent from the remote control is captured by the microcontroller. The
microcontroller controls the channel selection, the amplifier system and picture tube adjustments
such as hue, brightness, contrast etc.
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.
Programming in Microcontroller
Microcontrollers were originally programmed only in assembly language, but various high-level
programming languages, such as C, Python and JavaScript, are now also in common use to target
microcontrollers and embedded systems. These languages are either designed especially for the
purpose, or versions of general purpose languages such as the C programming language.
Recent microcontrollers are often integrated with on-chip debug circuitry that when accessed by
an in-circuit emulator (ICE) via JTAG, allow debugging of the firmware with a debugger. A
`
real-time ICE may allow viewing and/or manipulating of internal states while running. A tracing
ICE can record executed program and MCU states before/after a trigger point.
Applications of Microcontrollers
Microcontrollers are used in wide range of products which are automatically controlled. The
various products that make use of microcontrollers in our everyday life are:
Home Appliances: - Television, DVD player, Telephone, Cellular Phones, Camera, Security
systems, Sewing machine, Musical instrument, Exercising machine, Video games,
Microwave oven, Fax machine, Printers, Security Systems, Telephones.
Memory Types
A Memory module is a physical device which is used to store user programs or data in a
temporary or permanent manner. All memory structures have an address bus and a data bus. The
various types of memories used in microcontroller are
This is the volatile memory which means that the stored programs and data are lost when
the power is shut off. It offers fast read access times. There are different types of RAM are:
Static RAM
Dynamic RAM
Static RAM
The Static RAM (SRAM) uses transistor to store a single bit of data. Its structure is
complex than Dynamic RAM (DRAM). It does not need periodic refreshment to maintain data. It
is more expensive and faster than DRAM. It is used in Cache memory.
Dynamic RAM
`
The Dynamic RAM (DRAM) uses a separate capacitor to store each bit of data. It is
available in large storage capacity. It needs the data to be refreshed periodically to retain the
data. It consumes high power. It is used in Main memory.
It is a non-volatile memory which means that the stored programs are retained even if the
power is shut off. Data stored in ROM neither be erased nor replaced. The instructions are
written in ROM at the time of manufacturing and it is used to execute on start-up of computer
and makes the system ready for work. It contains a set of start-up instructions to check that
memory is functioning well and check for other hardware devices. These instructions also check
for an operating system and load its necessary part to RAM.
It is a memory chip in which the data is written only once. Once the data is written, it
cannot be altered. It can be executed at a very high speed and it is used for converting critical and
lengthy operations into micro-programs that are fused into a chip. The fuse is existed for every
bit of the PROM and it is programmed by blowing the fuses. If any error occurs, it cannot be
removed and it is unusable. It is also referred to as OTP (One Time Programmable).
It is initially blank and the user can write programs and data on it using special ultraviolet
rays. The data written on EPROM can be erased and reprogrammed with the help of electrical
pulses.
`
Flash Memory
It is a non-volatile memory chip used for storage and for transferring data between a
personal computer (PC) and digital devices. Devices uses flash memory erases data at the block
level and rewrite data at the byte level. It is used in a wide range of consumer devices include
USB (Universal Serial Bus) flash drives, smart phones, tablet computers, digital cameras and
embedded controllers.
The architecture of flash memory consists of a memory array stacked with a large number
of flash cells. It has a grid of columns and rows with a cell that has two transistors at each
intersection. It consists of a floating-gate transistor which based on complementary metal-oxide
semiconductor (CMOS) technology used to hold an electrical charge in a memory to store data.
Flash memory devices operates on two different technologies which are NAND and NOR
to map the data. NOR flash provides high-speed random access, reading and storing data in
specific memory locations. NAND flash is used to read and write data sequentially at high speed.
It handles data in tiny blocks called pages. It is used in digital cameras, audio and video players,
solid-state and USB flash drives, and TV set-top boxes. The time taken to read the contents is
faster than to write the data.
`
Chapter 2
Peripheral Devices
Peripherals
The microcontroller includes CPU, memory and peripheral devices. The various
peripheral devices are:
It is used to facilitate the flow of signal between the CPU and the external devices. There
are 32 I/O pins in microcontroller which are configured as either input or output ports.
I/O port is the physical port that connects to communicate other hardware devices. I/O
interface is the software interfaces that allow the Operating System (OS) to communicate with
hardware devices. An I/O port generally refers to the physical port (e.g., DB-9, USB connector,
DB-25 connector, etc.
`
485 transceivers.
Timers/Counters
Embedded systems often require mechanisms for counting the occurrence of events and for
performing tasks at regular intervals. A timer is a specialized type of clock which is used to
measure time intervals. A timer that counts from zero upwards for measuring time elapsed is
often called a stopwatch. It is a device that counts down from a specified time interval and used
to generate a time delay.
Timers are used to generate timings of internal or external events, scheduling events, measuring
the width of a pulse, speed control of motors (PWM), generation of complex waveforms and
frequency generation.
A counter is a device that stores (and sometimes displays) the number of times a particular event
or process occurred, with respect to a clock signal. It is used to count the events happening
outside the microcontroller.
Timer Counter
The register incremented for every The register is incremented considering 1 to 0
machine cycle. transitions at its corresponding to an external
input pin (T0, T1).
Maximum count rate is 1/12 of the Maximum count rate is 1/24 of the oscillator
oscillator frequency. frequency.
A timer uses the frequency of the A counter uses an external signal to count pulses.
internal clock, and generates delay.
The ADC is used to convert analog input signal into digital output signal. Analog signals
are generated from the transducers and it is processed by the microcontroller in digital signal.
The data processing in digital signal reduces the effects of noise and increases the accuracy.
Analog-to-Digital converters (ADC) translate analog real world signals like temperature,
pressure, voltage, current, distance, or light intensity, into its equivalent digital signal.
`
Applications of ADC
Digital Voltmeter – It measures voltage in analog form and converts it into equivalent
digital form.
Voice Recorder – It uses ADC to convert analog voice information to the digital
information.
Scanner – It uses ADC to convert analog information provided by the picture into digital
information.
Mobile Phone –The voice in analog form is converted into digital form for speech
compression, encoding etc.
The DAC is used to convert digital input signal into analog output signal. It is used in
digital systems to provide interface with analog sensors. The digital data may be produced from a
microprocessor, Application Specific Integrated Circuit (ASIC), or Field Programmable Gate
Array (FPGA), but ultimately the data requires the conversion to an analog signal in order to
interact with the real world.
Applications of DAC
MODEMS – It uses DAC to convert the digital data to analog form in order to carry the
analog signal over telephone lines.
Digital Motor Control
Sound Systems
Function Generators
Oscilloscopes
Digital Audio Systems
Video adapters
Interrupt Control
`
handler to deal with the event. After servicing the interrupt, the microcontroller continues to
perform the normal activities.
It is a hardware component that can transmit and receive digital data. It is used to perform
communications over the serial ports through an RS-232 serial interface standard. UART devices
can operate at various clock speeds.
`
Chapter 3
IC8051 Microcontrollers
IC8051 Microcontroller
An 8-bit microcontroller performs arithmetic and logical operations with 8-bits. The
examples of 8-bit microcontroller are IC8051 andIC8031. The IC8051 microcontroller is
launched in the year 1980 by Intel Corporation. The IC8031 is a member of the IC8051 family.
IC8031 has no on-chip ROM as compared to IC8051.
8-bit Microcontroller
4Kilobytes on-chip program memory (ROM)
128 bytes on-chip data memory (RAM)
128 user defined software flags
Four register banks
40-pin DIP IC
8-bit bi-directional data bus
16-bit unidirectional address bus
32 general purpose registers each of 8-bit
Two 16-bit Timers
Three internal and two external interrupts
Four 8-bit I/O ports
8-bit Stack Pointer
16-bit Program Counter and Data Pointer
Operating frequency is 24MHz – 33MHz
One Microsecond instruction cycle with 12 MHz crystal
Operates on +5V Regulated DC Power Supply
Full duplex UART
It has 21 Special Function Registers (SFRs)
Bit and Byte addressable
`
Block Diagram of Microcontroller
The fig.1 shows the basic layout of a microcontroller. The microcontroller includes
Processor Core, Memory (RAM and EEPROM), Timer/Counter module, Digital I/O module,
Analog module and Interrupt Controller.
The system bus connects all the support devices to the CPU. The system bus consists of an 8-bit
data bus, a 16-bit address bus and bus control signals. All other devices like program memory,
ports, data memory, serial interface, interrupt control, timers, and the CPU are all interfaced
together through the system bus.
Processor Core
It is the CPU of the microcontroller. It contains the Arithmetic Logic Unit (ALU), the
control unit, and the registers include program counter, stack pointer, accumulator, register file
etc.
Memory
The memory of the microcontroller is divided into program memory and data memory.
The program memory is used for storing of permanent programs and the data memory is used for
storing temporary storage of data. The EEPROM acts as program memory and the RAM acts as
data memory. A Direct Memory Access (DMA) controller is used to transfer data between
memory and peripheral components in larger microcontrollers.
Timer/Counter
A Timer/Counter module allows the microcontroller to perform tasks for certain time
periods. The 8051 microcontroller consists of two 16-bit timers and counters such as timer 0 and
timer 1. Both the timers consist of a 16-bit register in which the lower byte is stored in the TL
and the higher byte is stored in the TH. The Timer can be used as a counter as well as for timing
operation that depends on the source of the clock pulses to the counters. This module is used in
operations which include clock functions, frequency generation and measurement, modulation
and pulse generation.
The Timers and Counters in IC8051 microcontrollers contain two special function registers
which are TMOD (Timer Mode) register and TCON (Timer Control) register.
`
Fig. 1 Block diagram of Microcontroller-8051
The important features of microcontroller are parallel digital I/O ports. The I/O ports are
multiplexed with alternate functions for the peripheral devices on the microcontroller. They are
used to interface peripherals such as printers, external memories, LEDs and LCDs to the
microcontroller. There are serial ports in microcontroller which is used to interface serially
connected peripherals with the microcontroller.
Analog Module
Microcontroller can read the analog voltage from the output of sensors and convert it into
digital by using Analog to Digital Converter (ADC). This digital signal is processed by the
microcontroller and converts it back into analog voltage as output by using Digital to Analog
Converter (DAC).
It is used to interface the microcontroller with the peripheral devices. Serial communication is
the process of transmitting or receiving single bit at a time between the microcontroller and the
peripheral devices. The rate of serial data transmission is expressed in baud rate. The serial
communication is performed using UART (Universal Asynchronous Receiver and Transmitter).
`
Asynchronous indicates that data is transferred without the need of external clock signal. A
microcontrollers UART device has separate signals for transmitting and receiving serial data.
Asynchronous communication requires start bit, data bits, synchronization bits, parity bits and
stop bit.
Interrupt Controller: -
Interrupt is an event that suspends the main program temporarily and transfers the control to a
special routine which executes the event-related function. After the completion of event, the
program control returns back to the main program where the interrupt is called. Interrupt Service
Routine (ISR) is a code that tells the microcontroller what to do when the interrupt occurs.
Interrupts are classified as hardware and software interrupts. Hardware interrupts are
generated by the inbuilt devices of the microcontroller such as timer or by the interfacing
devices. Software interrupts are generated through the program.
8051 Interrupts
The external interrupt flags are cleared when the processor branches to the interrupt service
routine, provides the interrupt is a negative edge triggered.
`
Types of Registers
Accumulator (A)
B register
It is both a bit and byte-addressable register. It is used for multiply and divide operations. It can
also be used for general purpose operations.
`
The flag register in the IC8051 is called the Program Status Word (PSW) register. It is an 8-bit
register. The four flags in IC8051 are Carry flag, Auxiliary Carry flag, Overflow flag, Parity flag.
Carry Flag
After the execution of arithmetic or logic operations, if there is a carry out of D 7th bit, this flag is
set. Otherwise, it is reset.
This flag is set when there is a carry from digit D 3 to D4after performing arithmetic operations.
Otherwise, it is reset. It is used in BCD operations.
Parity Flag
After the execution of arithmetic or logic operations, if the accumulator contains odd number
of 1’s, then the parity flag will be set. If the accumulator contains even number of 1’s, then the
parity flag will be reset.
Overflow flag
This flag is set whenever the result of a signed number operation is too large, causing the high-
order bit to overflow into the sign bit. It is used to detect errors in signed arithmetic operations.
These two bits RS1 and RSO in PSW register are used to select various memory locations
(Bank0 to Bank3) in the RAM memory location.
`
Stack Pointer (SP)
Stack is used to store the data temporarily in RAM locations. It is 8-bit register, indicates the
address of the top of the stack. The operation of stack is Last-In First-Out.
The PC in the 8051 is 16-bits wide. It tells the microcontroller where the next instruction to
execute is found in memory. When the IC8051 is initialized, PC usually starts at 0000h and is
incremented each time an instruction is executed.
I/O Ports
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. The I/O pins can be configured as 1 for input and 0 for output as per the
logic state.
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 pull-up resistor.
Port 0
The P0 (zero) port is characterized by two functions.
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.
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.
`
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.
Programming of IC8051
The program is a sequence of instructions that are executed by the microcontroller in a
particular order to perform a predefined task. Programming also involves debugging and
troubleshooting of instructions and instruction sequence to make sure that the desired task is
performed.
Structure of the 8051 Microcontroller Assembly Language
Each line or statement of the assembly language program of 8051 Microcontroller consists of
four fields. The arrangement of these fields is shown below.
Addres Label Mnemonics Comments
s
Address
It is the first field in the program format. Each program should be entered with the address
location. The starting address is used during the execution of the program. The address is also
required for branch instructions. The program counter keeps track of the address of the program.
`
Label
The Label is programmer chosen name for a Memory Location or a statement in a program.
The Label part of the statement is optional and if present, the Label must be terminated with a
Colon (:)
Mnemonics
The Mnemonics is the main part of the 8051 Microcontroller Assembly Language
Programming as it is responsible for the task performed by the Microcontroller. Any Instruction
in the Assembly Language consists of two parts: Op-code and Operand(s).
The first part of the Instruction is the Op-code, which is short for Operation Code, specifies
the operation to be performed by the microcontroller. Op-codes in Assembly Language are called
as Mnemonics.
Comments
The last part of the Structure of 8051 Assembly Language is the Comments. Comments are
statements included by the developer for easier understanding of the code and are used for proper
documentation of the Program. Comments are optional and if used, they must begin with a
semicolon (;) or double slash (//) depending on the Assembler.
Abbreviations used in IC8051 Instructions
Rn Register R7-R0 of the currently selected Register Bank
direct 8-bit internal data location’s address. This could be an Internal Data RAM location or a
Special Function Register [i.e., I/O port, control register, status register, etc.]
@Ri 8-bit internal data RAM location (0-255) addressed indirectly through register R 1or R0.
#data 8-bit constant included in instruction.
#data 16 16-bit constant included in instruction
addr 16 16-bit destination address. Used by LCALL and LJMP. A branch can be anywhere within the
64K byte Program Memory address space.
bit Direct Addressed bit in Internal Data RAM or Special Function Register.
The various types of 8051 instructions along with commands are listed below.
Data transfer instructions – MOV, MOVC, MOVX, PUSH, POP, XCH, XCHD
Arithmetic instructions – ADD, ADDC, SUBB, MUL, DIV, INC, DEC, DA A
Branching and Subroutines instructions– LJMP, LCALL, JZ, JNZ, JMP, NOP, RET, RETI
Instructions for Logical Instructions – ANL, ORL, XRL, CLR, CPL, RLC, RRC, SWAP
Instructions for Boolean Variable Instrutions – SETB, MOV, CLR, JB, JBC, ANL, ORL.
Special Purpose Instructions – MOVC, MOVX, SWAP, XCH, XCHD, JBC, RETI, DAA
`
General Format: MOV Rd, Rs – It copies the content of source register (R s) into the destination
register (Rd).
Examples: MOV A, R0 – It copies the contents of R0 into the Accumulator register.
ADD A, R7 – It add the contents of Accumulator and register R7 and stores the sum in the
Accumulator.
Applications of 8051 Microcontroller
The applications of IC8051 are:
Industrial Process Control
Communication Systems (Mobile Phones, Intercoms, Paging devices etc.)
Consumer electronics (Remote Controls, Computers, TV Tuners, etc.)
Medical Equipment
GPU is made to process and output both 2D and 3D computer graphics. GPU implements
the graphics pipeline consisting of:
Vertex transformations
Geometry processing
Rasterizing polygons to pixels
Processing the pixels
Writing to the frame buffer
GPU have faster and more advanced memory interfaces. It enables to run high definition
graphics on Personal Computer. It works as both a programmable graphics processor and a
`
scalable parallel computing platform. GPUs are an essential part of chipsets equipped with
modern smartphones.
The first GPU was developed by NVidia in 1999 and called the GeForce 256. This GPU
model could process 10 million polygons per second and had more than 22 million transistors.
The GeForce 256 was a single-chip processor with integrated transform, lighting effects, triangle
setup/clipping and rendering engines. The GPU is connected to the CPU and is completely
separate from the motherboard. The random access memory (RAM) is connected through the
accelerated graphics port (AGP) or the peripheral component interconnect express (PCI-Express)
bus.
An FPU is a processor that performs floating point calculations. It supports the real, integer
and BCD integer data types. It greatly improves the efficiency of Intel Architecture processors in
handling the high precision floating point processing operations. It can be defined as a
specialized coprocessor that can manipulate data faster than the basic microprocessor. It is
difficult to implement in hardware and it can be part of the CPU since it can be implemented as a
micro-program within the CPU.
`
Chapter 4
IC8051 Interfacing
Serial Port
Parallel Port
Serial Port
It requires single cable for data transmission. The 8051 has two signals for serial
communication which are TxD (Transmit Data) and RxD (Receive Data). The TXD line is pin
11 of the microcontroller (P3.1) while the RXD line is on pin 10 (P3.0). The 8051 includes an
on-chip serial port that can be programmed to operate in one of four different modes and at a
range of frequencies. In serial communication the data is rate is known as the baud rate, which
simply means the number of bits transmitted per second. The 8051 serial port is full duplex. In
other words, it can transmit and receive data at the same time.
Parallel Port
It requires multiple wires through which the data bits are transmitted in parallel. The
parallel port was designed to be used with the printers. In the parallel I/O mode, devices can be
`
interfaced using two techniques: peripheral mapped I/O and memory-mapped I/O. In peripheral-
mapped I/O, a device is identified with an 8-bit address and enabled by I/O-related control
signals. In memory-mapped I/O, a device is identified with a 16-bit address and enabled by
memory-related control signals.
The Digital to Analog Converter (DAC) is used to interface the IC8051 with the external
devices to get the output in analog form. The output of DAC is analog signal which is used to
control the process.
8-bit DAC
Fast settling time: 150 ns
TTL and CMOS compatible
Power Supply: 4.5 to 18 V (Positive or Negative)
Low Power Consumption: 33 mW
Accuracy: 0.19 (Positive or Negative)
Interfacing Diagram
Port 1 of IC8051 is connected to the data lines D7-D0 of Digital to Analog Converter (DAC)
IC0808. The output of DAC is connected to the inverting terminal of the operational amplifier
IC741. The analog output is generated from the 8-bit digital input.
`
Fig. 1 Interfacing DAC with IC8051 microcontroller
Analog signals have infinite number of data like a sine wave. ADC converts analog data into
particular states, which can be measured in numbers as a physical quantity. It converts data in
periodical manner, which is known a sampling rate. The benefit of converting analog to digital is
that the noise can be eliminated from the original signal and digital signal can be represented
more accurately.
ADC IC0808
It is an 8-bit ADC. It has 8-channels IN0-IN7. It has three address lines which are represented by
A, B and C. These address lines are used to select the analog channels.
A B C Channel
0 0 0 IN0
0 0 1 IN1
0 1 0 IN2
`
0 1 1 IN3
1 0 0 IN4
1 0 1 IN5
1 1 0 IN6
1 1 1 IN7
SOC (Start of Conversion) – When this signal goes from High to Low state, ADC
initiates conversion of analog to digital.
EOC (End of Conversion) – ADC sends this High EOC signal to Microcontroller to
indicate conversion is completed.
OE (Output Enable) – When it is High, the output latch of ADC get enables and the
converted data is then available to microcontroller.
Interfacing Diagram
The analog input signal from sensors is read through one of eight input channels by using
three selection lines A, B and C. Port 2 in IC8051 is used to select the channel, initiates start of
conversion and to receive the end of conversion signal. Once the end of conversion signal is
enabled, then the IC8051 reads 8-bit data using Port 1 through data bus.
`
Fig. 2 Interfacing Analog I/O with IC8051 Microcontroller
Display
A seven-segment display device is an electronic device used to display digital data and it is
made up of seven LED (Light Emitting Diode) segments. The seven segments are represented as
A, B, C, D, E, F and G. The common signal is grounded. DP denotes decimal point.
LED is made up of PN junction in which the current conduction takes place only in forward
bias. The current doesn’t flow in reverse bias. Each LED has two pins which are anode and
cathode. Anode is a positive terminal and the cathode is the negative terminal. Seven segment
displays is used to display numbers 0 to 9. The seven LEDs are used to form the seven segments
and a dot point. It is used in variety of devices include clocks, weight lift, home appliances,
traffic light control etc.
`
Fig. 3 Seven Segment Display
The seven segment displays are connected either in common cathode or common anode.
Depending upon the decimal digit to be displayed, the particular set of LEDs is forward biased.
For instance, to display the numerical digit 0, we will need to light up six of the LED segments
corresponding to A, B, C, D, E and F.
Common Anode
In this type, all the anode terminals are made to common and tied to Vcc (5v). The segments A
to G require a logic LOW signal (GND) in order to glow.
Common Cathode
In this type, all the cathode terminals are made common and tied to GND. The
segments A to G require a logic High signal (5v) in order to glow.
`
Fig. 5 Common Cathode Connection
Fig. shows the interfacing seven segment display with IC8051. Port 1 of IC8051 is connected
to the seven segment and a decimal point.
`
Chapter 5
Programmable Logic Controller
PLC stands for Programmable Logic Controller. It is introduced in the late 1960’s. It is a
specialized computer used to control the industrial processes. It is developed to replace hard
wired logic relays at a large scale. It performs many functions, providing an interface between
analog and digital input and output.
A PLC interfaces numerous types of external electrical and electronic signals. These
signals can be AC or DC currents or voltages. Typically, they range from 4 to 20 milli-amperes
(mA) or 0 to 120VAC, and 0 to 48VDC. These signals are referred to as I/O (input/output)
points.
The variety of control tasks were performed by contactors, relays and other
electromechanical devices prior to PLCs. This is referred to as hard-wired control.
The functions of a PLC input circuit are to convert the input signals provided by sensors and
switches into logic signals that can be used by the CPU. The program instructions are written
onto the programming device through mnemonics and stored in the user memory. The CPU
fetches these instructions from the memory and executes the input signals by manipulating,
computing, processing them to control the output.
`
Fig. 1 Block Diagram of PLC
The block diagram of PLC includes
It is the heart of the PLC system. It reads input data from various sensing devices, executes the
user program from the memory and sends appropriate output commands to control devices. A
DC power source is required to produce the low-level voltage used by the processor and I/O
modules.
Programming Device
The control logic or the program is written using the programming device. The data is entered
into the PLC processor through the keyboard. The methods of programming in PLC are Ladder
diagram, Instruction list and block diagram.
It is used to interface the input devices with the processor and to interface the processor with
the output devices. The I/O module provides the isolation between processor and I/O devices.
`
Input module
The input module has two functions: reception of an external signal and status display of that
input point. The input to an input module is in either a discrete or analog form. If the input is an
ON-OFF type, such as with a push button or limit switch, the signal is considered to be of a
discrete nature. If, on the other hand, the input varies, such as with temperature, pressure, or
level, the signal is analog in nature.
Peripheral devices sending signals to input modules that describe external conditions can be
switches (limit, proximity, pressure, or temperature), push buttons, or logic, binary coded
decimal (BCD) or analog-to-digital (A/D) circuits. These input signal points are scanned, and
their status is communicated through the interface module or circuitry within each individual
PLC and I/O base.
The various input modules of PLC are:
DC voltage (110, 220, 14, 24, 48, 15-30V) or current (4-20 mA).
AC voltage (110, 240, 24, 48V) or current (4-20 mA).
Analog input (12-bit).
Thermocouple input.
Resistance temperature detector.
PID (proportional, integral, differentiation) input.
Output module
The output module transmits discrete or analog signals to activate various devices such as
hydraulic actuators, solenoids, motor starters, and displays the status (through the use of LEDs)
of the connected output points. Signal conditioning, termination, and isolation are also part of the
output module's functions. The output module is treated in the same manner as the input module
by the processor.
The various output modules of PLC include:
DC voltage (24, 48,110V) or current (4-20 mA).
AC voltage (110, 240v) or current (4-20 mA).
Isolated (24V DC).
Analog output (12-bit).
Memory
`
The memory is divided into two types which are data memory and program memory. The
program information or the control logic is stored in the user memory or the program memory
from where the CPU fetches the program instructions.
The memory section stores retrievable digital information in three dedicated locations of the
memory. These memory locations are routinely scanned by the processor. The memory will
receive ("write" mode) digital information or have digital information accessed ("read" mode) by
the processor. This read/write (R/W) capability provides an easy way to make program changes.
Power Supply
The Power Supply section gets its input power from an external 120V AC or 240V AC source
line voltage. This line voltage is then stepped-down, rectified, filtered, regulated, voltage- and
current-protected, and status-monitored, with status indication displayed.
System Busses
The internal paths along which the digital signals flow within the PLC are called busses.
The system has four busses:
The CPU uses the data bus for sending data between the different elements
The address bus to send the addresses of locations for accessing stored data
The control bus for signals relating to internal control actions
The system bus is used for communications between the I/O ports and the I/O
unit.
Input Devices
It is the computer hardware equipment used to provide data, and control signals to an
information processing system. The various input devices are
Output Devices
`
It is hardware equipment used to communicate the processor output into an understandable
form. The various output devices are
Valves
Motors
Pumps
PLC Programming
A CPU of the PLC executes two different programs:
The Operating System
The User Program
The Operating System
The operating system organizes all the functions, operations and sequences of the CPU that are
not associated with a control task. The OS tasks include
Handling a hot restart and warm restart
Updating and outputting the process image tables of input and outputs
Executing the user program
Detecting and calling the interrupts
Managing the memory areas
Establishing communication with programmable devices
The User Program
It is a combination of various functions which are required to process an automated task. This
must be created by the users and need to be downloaded to the CPU of the PLC. Some of the
tasks of the user program include:
Initiating all the conditions for starting the specified task
Reading and evaluating all binary and analog input signals
Specifying output signals to all binary and analog output signals
Executing interrupts and handling errors
In present industrial automation sector, there are several leading PLC manufactures that develop
typical PLC’s ranging from small to high-end PLC’s. Each and every PLC manufacturer has its
own dedicated software to program and configure the PLC hardware. But the PLC programming
language is varied depending on the manufacturers. Some manufacturers have common
`
programming languages and some others have dissimilar. Some of the standard programming
languages of PLC are basically of two types, which are further sub-divided into several types,
which are as follows:
1. Textual language
Instructions List (IL)
Structured Text (ST)
2. Graphical language
Ladder Diagrams (LD)
Function Block Diagram (FBD)
Sequential Function Chart (SFC)
Compared with text based languages, graphical languages are preferred by many users to
program a PLC due to their simple and convenient programming features. All the necessary
functions and functional blocks are available in the standard library of each PLC software. These
function blocks include timers, counters, strings, comparators, numeric, arithmetic, bit-shift,
calling functions, and so on.
• Ladder Diagrams (LD) PLC Programming
Among several programming languages ladder logic
diagram is the most basic and simplest form of
programming the PLC. Before going to program the PLC
with this language, one should know some basic
information about it. The below figure shows the
hardwired-ladder diagram wherein the same lamp load is
controlled by two push button switches, In case if any one Figure 1 Ladder Logic PLC Programming
Advantages of PLC
`
Handles complicated systems
Smaller physical size than hard-wire solutions
Interface for Input and Output readily available
Disadvantages of PLC
Chapter 6
PID Controller
Introduction
PID stands for Proportional Integral Derivative Controller. It is a feedback control mechanism
used in control system. PID controller maintains the output such that there is zero error between
process variable and set point by closed loop operations.
`
An open-loop control system takes input under consideration and doesn’t react on the
feedback to obtain the output. An open loop control system works on fixed operation conditions
and there are no disturbances. The structure of open loop control system is easy to construct and
implement.
Fig.1 shows the block diagram of closed loop control system. The output is given feedback to
the input for correction. The closed loop control systems are complex in design and very
expensive. It produces accurate output.
`
Fig. 2 Block Diagram of Closed Loop Control System
The tuning of PID controller is based on the error signal which is the difference between the
setpoint and process variable. The output of PID controller is given to the process in order to
maintain the steady state. The process output is measured by suitable sensor which is feedback to
the input to generate the error signal. The disturbance enters the process which is to be measured
and eliminated.
`
Proportional Controller
The output of the proportional controller is the product of gain and measured error. It is the
most common of all industrial process control action. It calculates the difference between the
process variable signal and the set point signal, which is called as an error. It provides an
immediate reaction to a change in the process variable. The higher gain value of proportional
control causes repeatedly overshoot the setpoint, leading to oscillation.
If the error is high, then the controller output is also high. As the error is zero, it produces
zero output. In proportional control, the correction factor is determined by the size of the
difference between set point and the measured value. It provides stable operation but always
maintains the steady state error. When the proportional constant increases, the speed of response
is increased. It can be used to obtain fast response systems with a large transmission coefficient.
A high proportional gain results in a large change in the output for a given change in the error. A
small gain results in a small output response to a large input error, and a less responsive or less
sensitive controller.
Proportional band is the percentage change in the process variable needed to cause a 100 percent
change in controller output.
Integral Controller
`
It overcomes the drawback of proportional controller. It is the process of accumulating the
process variable value as the time progress. Integral action decides how fast to move the output.It
eliminates the steady state error by the process of integration. It integrates the error over a period
of time until error value reaches to zero. When the negative error occurs, the output of the
integral control will decrease. It limits the speed of response and affects stability of the system.
By reducing the integral gain, the speed of the response can be increased. The controller output
depends on the integral of error signal over time. It doesn’t be used alone, but mostly it is used
along with proportional control. If there is any deviation between set point and process variable,
an addition corrective signal is supplied by the integral control mode function till steady state
error becomes zero.
CO=K p ( T1 ∫ e dt )+ Bias
i
It eliminates offset
It reduces integrated error
It produces overshoot
It has integral wind-up problem
Derivative Controller
Integral controller does not have the capability to predict the future behavior of error.
Derivative controller overcomes this problem be anticipating future behavior of the error. It
provides an output which is proportional to the rate of change of the error with respect to time. It
is used to prevent overshoot and undershoot of the setpoint and to restore the process value
rapidly to the setpoint.
`
It is also called as anticipatory controller because it moves the control valve in such a direction
as to counteract the rapid change of process variable. The output of derivative action is the
product of derivative constant and the rate of change of error with respect to time. It must not be
used alone because of rapid start of control output that can result extremely large rate of change
of output, even for a small error change. It is used along with proportional plus integral control
or with only proportional control.
Advantages
6.6.2 Disadvantages
It eliminates the offset and produces quick response. PI controller can be used to avoid large
disturbances and noise presents during operation process. Whereas PID controller can be used It
is widely used in process industries for controlling parameters like pressure, level, flow etc. The
drawback of PI controller is it produces slow response to disturbance.
1
(
CO=K p e+
Ti ∫ )
e dt + Bias
Advantages
Disadvantages
`
It doesn’t predict the future error
It increases the overshoot
Slow response
de
CO=K p∗e+ K d + Bias
dt
de
CO=K p∗e+ K i∫ e dt+ K d + Bias
dt
Advantages
It produces fast response
It eliminates steady state error
It decreases the overshoot
Disadvantages
It is difficult to tune proportional, integral and derivative gains for a particular process
`
Response Curve of PID Controller
http://nptel.ac.in/courses/117104072/
http://nptel.ac.in/courses/Webcourse-contents/IIT
KANPUR/microcontrollers/micro/ui/Course_home1_1.htm
`
Additional reading
`
DEC Alpha: 210642, 211066, 21068, 21164
MIPS: TS (R10000) RISC Processor
PA-RISC: HP 7100LC
1.1.7Characteristics of RISC
The major characteristics of a RISC processor are as follows.
It consists of simple instructions.
It supports various data-type formats.
It utilizes simple addressing modes and fixed length instructions for pipelining.
It supports register to use in any context.
One cycle execution time.
“LOAD” and “STORE” instructions are used to access the memory location.
It consists of larger number of registers.
It consists of less number of transistors.
1.1.8 CISC Processor
CISC stands for Complex Instruction Set Computer. It is designed to minimize the number of
instructions per program, ignoring the number of cycles per instruction. The emphasis is on
building complex instructions directly into the hardware.
The compiler has to do very little work to translate a high-level language into assembly level
language/machine code because the length of the code is relatively short, so very little RAM is
required to store the instructions.
Some of the CISC Processors are −
IBM 370/168
VAX 11/780
Intel 80486
1.1.9Characteristics of CISC
Variety of addressing modes.
Larger number of instructions.
Variable length of instruction formats.
Several cycles may be required to execute one instruction.
Instruction-decoding logic is complex.
One instruction is required to support multiple addressing modes.
`
1.1.10 Special Processors
These are the processors which are designed for some special purposes. Few of the special
processors are given below.
1.1.11 Coprocessor
A coprocessor is a specially designed microprocessor, which can handle its particular function
many times faster than the ordinary microprocessor.
Example:
Math Coprocessor.
Some Intel math-coprocessors are −
8087-used with 8086
80287-used with 80286
80387-used with 80386
1.1.12Input/Output Processor
It is a specially designed microprocessor having a local memory of its own, which is used to
control I/O devices with minimum CPU involvement.
Example:
DMA (direct Memory Access) controller
Keyboard/mouse controller
Graphic display controller
SCSI port controller
1.1.13DSP (Digital Signal Processor)
This processor is specially designed to process the analog signals into a digital form. This is
done by sampling the voltage level at regular time intervals and converting the voltage at that
instant into a digital form. This process is performed by a circuit called an analogue to digital
converter, A to D converter or ADC.
A DSP contains the following components.
Program Memory − It stores the programs that DSP will use to process data.
Data Memory − It stores the information to be processed.
Compute Engine − It performs the mathematical processing, accessing the program from
the program memory and the data from the data memory.
Input/Output − It connects to the outside world.
`
The applications of DSP are
Sound and music synthesis
Audio and video compression
Video signal processing
2D and 3d graphics acceleration.
Example:
Texas Instrument’s TMS 320 series, e.g., TMS 320C40, TMS320C50.
`
bit Direct Addressed bit in Internal Data RAM or Special Function Register.
The IC8051 is a 40-pin IC available in Dual-In line package (DIP). It requires a single +5V
power supply. The maximum internal clock frequency is 12 MHz.
`
`
Fig. 1 Pin Diagram of IC8051
`
PID Tuning Method
The determination of corresponding PID parameter values for getting the optimum
performance from the process is called tuning. This is obviously a crucial part in case of all
closed loop control systems. There are number of tuning methods have been introduced to obtain
fast and acceptable performance.
The steps involved in these methods include experimental determination of the dynamic
characteristics of the control loop and estimating the controller tuning parameters that produce a
desired performance for the dynamic characteristics determined. The various tuning methods are
discussed below.
Trial and Error Method
This is the simple method of tuning a PID controller. Once we get the clear understanding of
PID parameters, the trial and error method become relatively easy.
Set integral and derivative terms to zero first and then increase the proportional gain until
the output of the control loop oscillates at a constant rate. This increase of proportional
gain should be in such that response the system becomes faster provided it should not
make system unstable.
Once the P-response is fast enough, set the integral term, so that the oscillations will be
gradually reduced. Change this I-value until the steady state error is reduced, but it may
increase overshoot.
Once P and I parameters have been set to a desired values with minimal steady state
error, increase the derivative gain until the system reacts quickly to its set point. Increasing
derivative term decreases the overshoot of the controller response.
Zeigler-Nichols Method
It is another popular method for tuning PID controllers. Ziegler and Nichols presented two
classical methods for determining values of proportional gain, integral time and derivative time
based on transient response characteristics of a given plant or system.
First Method
Obtain a unit step response of the plant experimentally and it may look‘s’ shaped curve
as shown in figure below. This method applies, if obtained response exhibit s-shaped curve
for unit step input otherwise it cannot be applied.
Obtain two constants, delay time L and time constant T by drawing a tangent line at the
inflection point of the s-shaped curve.
`
Set the parameters of Kp, Ti, and Td values from the table given below for three types of
controllers.
Second Method
It is very similar to the trial and error method where integral and derivative terms are set
to the zero, i.e., making Ti infinity and Td zero.
Increase the proportional gain such that the output exhibits sustained oscillations. If the
system does not produce sustained oscillations then this method cannot be applied. The
gain at which sustained oscillations produced is called as critical gain.
Once the sustain oscillations are produced, set the values of Ti and Td as per the given
table for P, PI and PID controllers based on critical gain and critical period.
`
Internal Model Control (IMC)
• A more comprehensive model-based design method, Internal Model Control (IMC), was
developed by Morari and coworkers (Garcia and Morari, 1982; Rivera et al., 1986).
• The IMC method, like the DS method, is based on an assumed process model and leads
to analytical expressions for the controller settings.
• These two design methods are closely related and produce identical controllers if the
design parameters are specified in a consistent manner.
`
• The model response is subtracted from the actual response Y, and the difference, is used
as the input signal to the IMC controller.
• In general, due to modeling errors and unknown disturbances that is not accounted for in
the model.
• The IMC method can be used to derive PID controller settings for a variety of transfer
function models.
Tuning Relations Based on Integral Error Criteria
• Controller tuning relations have been developed that optimize the closed-loop response
for a simple process model and a specified disturbance or set-point change.