1. Submitted for partial fulfillment of award of
BACHELOR OF TECHNOLOGY
DEGREE IN E&C ENGG.
(2007-2011)
A
Project Report
On
CELL PHONE OPERATED LAND ROVER
SUBMITTED TO: SUBMITTED BY:
Mrs. Ritu Singh Akash Chandel (0821331005)
Electronics & Communication Engineering Deptt. Anupam Singh (0821331018) Hindustan
Institute of Technology, Ashutosh Singh (08 21331024)
Gr. Noida
---------------------------------------------------------------------------------------------------
Department of Electronics and Communication Engineering
Hindustan Institute of Technology
32, 34, Knowledge Park-III, Greater Noida, U.P
2. TABLE OF CONTENTS
Abstract……………………………………………………………....6
List Of Abbreviations………………………………………………...7
CHAPTER 1:- INTRODUCTION………………………………....9
1.1 Project overview……………………………………………….10
1.2 Significance of project………………………………………..12
1.3 History of remote controlled vehicle…………………..............13
1.4 First Remote control vehicles……………..................................15
1.5 Use of Remote control vehicles during world war II………..
CHAPTER 2:- WORKING.........……………………………..17
2.1 Cell Phone used as DTMF transmitter………………………………18
2.2 Cell Phone used as DTMF receiver …………………………21
2.3 D.C Motor Driver……………………………………..................24
2.4 Microcontroller Logic…………………………………
CHAPTER 3:- PCB CONSTRUCTION……………………...…27
3.1 Shear raw material…………………………………………..28
3.2 Apply image…………………………………………………
3.3 Pattern plate…………………………………………………
3.4 Strip & Etch………………………………………………..
3.5 Solder Marks………………………………………………..
3.6 Nomenclature & Fabrication………………………………..
CHAPTER 4:- CIRCUIT DIAGRAM..………………36
4.1 Microcontroller device overview………………………
4.2 PIN Diagram…………………………………………….43
4.3 PIN Description………………………………………….46
4.4 RISC Architecture……………………………………………51
4.5 Memory & Register……………………………………….
4.5.6 SFRs ………………………………………………
CHAPTER 5:- OTHER COMPONENTS……......53
5.1 Diode & V-I characteristics………………………................................55
5.2 LED……………………………………...68
5.3 Motor Driver IC L-293
4. ABSTRACT
As today the world of mobile is going to overlap all the old traditional devices. We are now
using mobile for controlling the household appliances like television, fan, refrigerator etc.
The mobile is used to capture the video audio files, to store them, to transmit them to other
mobiles. The mobile is used for internet, commutation etc as well as the original use i.e. for
communication. Mobiles are coming with the features like clock, stop watch, world clock,
calculator, currency converter, spot light, audio/video player etc. the user needs a device
which can solve his all the problems and fulfill all the needs. So why can‘t we use this
popular device for controlling the ROBOT which may be a car or a personal assistant.
In this project we tried to overcome with this feature of mobile. In this project we
show that how we control the movement of any small robot with the help of mobile
phone. By using this logic we not only control the movement of vehicle but also switch
on/off other accessories on robot.
Mobile as a transmitter is used having 12 keypad for control operation and can be used
from anywhere in the world.
Programmable, multifunctional, DTMF based receiver because of PIC16F877, which can
be reprogrammed 10000 times.
Robot is self powered by 12V battery
High power DC motor is used to control Robot moment.
6. CHAPTER-1
Introduction Robotics
Robotics develop man-made mechanical devices that can move by themselves, whose motion
must be modeled, planned, sensed, actuated and controlled, and whose motion behavior can
be influenced by ―programming‖. Robots are called ―intelligent‖ if they succeed in moving in
safe interaction with an unstructured environment, while autonomously achieving their
specified tasks.
This definition implies that a device can only be called a ―robot‖ if it contains a movable
mechanism, influenced by sensing, planning, and actuation and control components
Robotics is, to a very large extent, all about system integration, achieving a task by an
actuated mechanical device, via an ―intelligent‖ integration of components, many of which it
shares with other domains, such as systems and control, computer science, character
animation, machine design, computer vision, artificial intelligence, cognitive science,
biomechanics, etc. In addition, the boundaries of robotics cannot be clearly defined, since also
its ―core‖ ideas, concepts and algorithms are being applied in an ever increasing number of
―external‖ applications, and, vice versa, core technology from other domains (vision, biology,
cognitive science or biomechanics, for example) are becoming crucial components in more
and more modern robotic systems.
Research in engineering robotics follows the bottom-up approach: existing and working
systems are extended and made more versatile. Research in artificial intelligence robotics is
top-down: assuming that a set of low-level primitives is available, how could one apply them
in order to increase the ―intelligence‖ of a system. The border between both approaches shifts
continuously, as more and more ―intelligence‖ is cast into algorithmic, system-theoretic form.
For example, the response of a robot to sensor input was considered ―intelligent behaviour‖ in
the late seventies and even early eighties. Hence, it belonged to A.I. Later it was shown that
many sensor-based tasks such as surface following or visual tracking could be formulated as
control problems with algorithmic solutions. From then on, they did not belong to A.I. any
more
7. BLOCK DIAGRAM:
Mobile as
Receiver
DTMF
Decoder PIC
Microcontroller
Left H Right H
Bridge Bridge
Left Right
Motor Motor
Fig:-1.1
8. 1.1PROJECT OVERVIEW :
Fig:-1.2
In this project, the robot is controlled by a mobile phone that makes a call to the mobile phone
9. attached to the robot. In the coarse of a call, if any button is pressed, a tone corresponding to the
button pressed is heard at the other end of the call. This tone is called ‗dual-tone
multiplefrequency‘ (DTMF) tone. The robot perceives this DTMF tone with thehelp of the phone
stacked in the robot.
The received tone is processed by the ATmega16 microcontroller with the help of DTMF
decoder MT8870. The decoder decodes the DTMF tone into its equivalent binary digit and this
binary number is sent to the microcontroller. The microcontroller is pre programmed to take a
decision for any given input and outputs its decision to motor drivers in order to drive the motors
for forward or backward motion or a turn.
The mobile that makes a call to the mobile phone stacked in the robot acts as a remote. So this
simple robotic project does not require the construction of receiver and transmitter units. DTMF
signaling is used for telephone signaling over the line in the voice-frequency band to the call
switching centre.
The version of DTMF used for telephone tone dialing is known as ‗Touch-Tone‘. DTMF assigns
a specific frequency (consisting of two separate tones) to each key so that it can easily be
identified by the electronic circuit. The signal generated by the DTMF encoder is a direct
algebraic summation, in real time, of the amplitudes of two sine (cosine) waves of different
frequencies, i.e., pressing ‗5‘ will send a tone made by adding 1336 Hz and 770 Hz to the other
end of the mobile phone.
10. 1.2SIGNIFICANCE OF THE PROJECT :
Robotics is an interesting field where every engineer can showcase his creative and technical
skills. Radio control (often abbreviated to R/C or simply RC) is the use of radio signals to
remotely control a device. The term is used frequently to refer to the control of model vehicles
from a hand-held radio transmitter.
Industrial, military, and scientific research organizations make [traffic] use of radio-controlled
vehicles as well. A remote control vehicle is defined as any mobile device that is controlled by a
means that does not restrict its motion with an origin external to the device. This is often a radio
control device, cable between control and vehicle, or an infrared controller. A remote control
vehicle (Also called as RCV) differs from a robot in that the RCV is always controlled by a
human and takes no positive action autonomously.
One of the key technologies which underpin this field is that of remote vehicle control. It is vital
that a vehicle should be capable of proceeding accurately to a target area; maneuvering within
that area to fulfill its mission and returning equally accurately and safely to base.
Recently, Sony Ericsson released a remote control car that could be controlled by any Bluetooth
cell phone. Radio is the most popular because it does not require the vehicle to be limited by the
length of the cable or in a direct line of sight with the controller (as with the infrared set-up).
11. 1.3HISTORY OF REMOTE CONTROLLED VEHICLES :
1.3.1The First Remote Control Vehicle :
Precision Guided Weapon : This propeller-driven radio controlled boat, built by Nikola Tesla in
1898 , is the original prototype of all modern-day uninhabited aerial vehicles and precision
guided weapons. In fact , all remotely operated vehicles in air, land or sea. Powered by lead-acid
batteries and an electric drive motor, the vessel was designed to be maneuvered alongside a
target using instructions received from a wireless remote control transmitter. Once in position, a
command would be sent to detonate an explosive charge contained within the boat!s forward
compartment.
The weapon!s guidance system incorporated a secure communications link between the pilot!s
controller and the surfacerunning torpedo in an effort to assure that control could be maintained
even in the presence of electronic countermeasures. To learn more about Tesla!s system for
secure wireless communications and his pioneering imp lementation of the electronic logic-gate
circuit read ‗Nikola Tesla — Guided Weapons & Computer Technology‘, Tesla Presents Series
Part 3, with commentary by Leland Anderson.
12. 1.3.2Use of Remote Controlled Vehicles During World War II :
During World War II in the Europe an Theater the U.S. Air Force experimented with three basic
forms radio control guided weapons. In each case, the weapon would be directed to its target by
a crew member on a control plane. The first weapon was essentially a standard bomb fitted with
steering controls. The next evolution involved the fitting of a bomb to a glider airframe, one
version, the GB-4 having a TV camera to assist the controller with targeting. The third class of
guided weapon was the remote controlled B-17. It!s known that Germany deployed a number
of more advanced guided strike weapons that saw combat before either the V-1 or V-2. They
were the radio-controlled Henschel!s Hs 293A and Ruhrstahl!s SD1400X, known as ‘Fritz X,‘
both air-launched, primarily against ships at sea.
13. CHAPTER- 2
Working:
2.1Mobile as DTMF Transmitter:
Mobile is based on DTMF Technology. When you press a button of mobile keypad, a
connection is made that generates a resultant signal of two tones at the same time. These two
tones are taken from a row frequency and a column frequency. The resultant frequency signal is
called "Dual Tone Multiple Frequency". These tones are identical and unique.
A DTMF signal is the algebraic sum of two different audio frequencies, one from
low frequency group and other from high frequency group.
Each of the low and high frequency groups comprise four frequencies from the various
keys present on the telephone keypad; two different frequencies, one from the high frequency
group and another from the low frequency group are used to produce a DTMF signal to represent
the pressed key.
When you send these DTMF signals to the telephone exchange through cables, the servers
in the telephone exchange identifies these signals and makes the connection to the person you are
calling.
The row and column frequencies are given below:
14. When you press the digit 5 in the keypad it generates a resultant tone signal which is made up of
frequencies 770Hz and 1336Hz. Pressing digit 8 will produce the tone taken from tones 852Hz
and 1336Hz. In both the cases, the column frequency 1336 Hz is the same. These signals are
digital signals which are symmetrical with the sinusoidal wave.
2.2Receiver Part:
The whole Receiver circuit consists of 6 major parts
DTMF Receiver
Light Sensor
DC Motor driver
Microcontroller logic
DTMF Receiver: Mobile work as a DTMF receiver and encoded hybrid frequency DTMF
code tone is decoded by 8870 IC. 8870 Decode DTMF tone and convert into BCD code,
output depending upon which key is pressed at the transmitter side. The table shows decoded
output.
15. D3 D2 D1 D0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
* 1 0 1 0
0 1 0 1 1
# 1 1 0 0
Fig:-2.1
This four digit output is directly given to 89C51. It will collect this code and start comparing it
with inbuilt code. When it founds perfect match it display code on 7 segment display and
switch to that subroutine and perform that particular task.
2.3 DC motor driver: The H-Bridge is used for motor driver. The H-Bridge is widely used in
Robotics for driving DC motor in both clockwise and anticlockwise. As shown in the circuit
diagram in H Bridge two NPN and two PNP transistors is used.
16. Let us consider microcontroller provide high at pin No 13 and low at Pin No 14 thus right side
NPN transistor conducts and left side PNP transistor conducts.this means M12 is 12v and M11 is
grounded thus motor rotate clockwise
Again let us consider microcontroller provide low at pin No 13 and high at Pin No 14 thus right
side PNP transistor conducts and left side NPN transistor conducts. this means M12 is grounded
and M11 is 12v thus motor rotate anticlockwise..
2.4 Microcontroller Logic: The function of microcontroller is to control input output based on
the programmed embedded hex logic. The microcontroller continuously scans input logic. The
input logic is 4BCD data from 8870 one from fire sensor and one from light sensor. If any one of
them changes their logic level microcontroller goes to particular subroutine and perform
particular task.
Let us consider a case at the transmitter mobile I have pressed number 2, thus at receiver side
8870 generate corresponding BCD logic 0010. The microcontroller receive 0010 at pin no
1,2,3,4. The microcontroller is programmed if input is 0010, move to robot left. The robot will
moves left if left DC motor rotate slow and right DC motor rotate fast. This slow and fast
moment is dine by microcontroller using pulse width modulation. Thus when we press 2 key
microcontroller provide different pulse to left right motor. The right motor gets pulse having
mote on time then left. In the same way all microcontroller subroutine gets executed and perform
corresponding task.
If microcontroller sense 0001 input then it goes to right subroutine and moves robot right.
If microcontroller sense 0010 inputs then it goes to left subroutine and moves robot left.
If microcontroller sense 0011 input then it goes to stop subroutine and goes to standby
mode.
If microcontroller sense 0100 input then it goes to forward subroutine and moves robot
forward.
17. If microcontroller sense 0101 input then it goes to backward subroutine and moves robot
backward.
If microcontroller sense low input at pin No 5 then it goes to day night subroutine and
supply high pulse to on light.
18. CHAPTER-3
.PCB CONSTRUCTION :
Step 1:
Generated from your design files, we create an exact film representation of your design. We will
create one film per layer.
Fig:-3.1
Step 2 :
3.1Shear Raw Material
Industry standard 0.059" thick, copper clad, two sides. Panels will be sheared to accommodate
many borads. Fig:-3.2
19. Step 3:
3.2Apply Image:
Apply photosensitive dryfilm (plate resist) to panel. Use light source and film to expose panel.
Develop selected areas from panel.
Fig:-3.4
Step 4 :
3.3Pattern Plate:
Electrochemical process to build copper in the holes and on the trace area. Apply tin to surface.
note: All PCB express boards are plated through holes.
Fig:3.5
20. Step 5 :
3.4Strip & Etch:
Remove dryfilm, then etch exposed copper. The tin protects the copper circuitry from being
etched.
Fig:3.6
Step 6 :
3.5Solder mask:
Apply solder mask area to entire board with the exception of solder pads
Fig:-3.7
21. Step 7 :
3.6Solder coat:
Apply solder to pads by immersing into tank of solder. Hot air knives level the solder when
removed from the tank.
Fig:-3.8
Step 8 :
3.7Nomenclature & Fabrication
Apply white letter marking using screen printing process. Route the perimeter of the board using
NC equipment.
Fig:3.9
25. CHAPTER-4
PIC16F887A Microcontroller Device Overview
PIC16F877 belongs to a class of 8-bit microcontrollers of RISC architecture. It has 8kb flash
memory for storing a written program. Since memory made in FLASH technology can be
programmed and cleared more than once, it makes this microcontroller suitable for device
development. IT has data memory that needs to be saved when there is no supply. It is usually
used for storing important data that must not be lost if power supply suddenly stops. For
instance, one such data is an assigned temperature in temperature regulators. If during a loss of
power supply this data was lost, we would have to make the adjustment once again upon return
of supply.
RISC architecture
o Only 35 instructions to learn
o All single-cycle instructions except branches
Operating frequency 0-20 MHz
Precision internal oscillator
o Factory calibrated
o Software selectable frequency range of 8MHz to 31KHz
Power supply voltage 2.0-5.5V
o Consumption: 220uA (2.0V, 4MHz), 11uA (2.0 V, 32 KHz) 50nA (stand-by
mode)
Power-Saving Sleep Mode
Brown-out Reset (BOR) with software control option
35 input/output pins
o High current source/sink for direct LED drive
o software and individually programmable pull-up resistor
o Interrupt-on-Change pin
8K ROM memory in FLASH technology
o Chip can be reprogrammed up to 100.000 times
26. In-Circuit Serial Programming Option
o Chip can be programmed even embedded in the target device
Data can be written more than 1.000.000 times
368 bytes RAM memory
A/D converter:
o 14-channels
o 10-bit resolution
3 independent timers/counters
Watch-dog timer
Analogue comparator module with
o Two analogue comparators
o Fixed voltage reference (0.6V)
o Programmable on-chip voltage reference
PWM output steering control
Eight level deep hardware stack
Power-on Reset (POR)
Power-up Timer (PWRT) and
Oscillator Start-up Timer (OST)
Programmable code protection
Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation
Direct, indirect and relative addressing modes
Interrupt capability (up to 14 sources)
Enhanced USART module
o Supports RS-485, RS-232 and LIN2.0
o Auto-Baud Detect
Master Synchronous Serial Port (MSSP)
o supports SPI and I2C mode
28. BLOCK DIAGRAM:
Fig-4.2
4.1PIN DESCRIPTION
As seen in Fig. 1-1 above, the most pins are multi-functional. For example, designator
RA3/AN3/Vref+/C1IN+ for the fifth pin specifies the following functions:
RA3 Port A third digital input/output
AN3 Third analog input
Vref+ Positive voltage reference
C1IN+ Comparator C1positive input
This small trick is often used because it makes the microcontroller package more compact
without affecting its functionality. These various pin functions cannot be used simultaneously,
but can be changed at any point during operation.
31. 4.2Central Processor Unit (CPU)
I‘m not going to bore you with the operation of the CPU at this stage, however it is important to
state that the CPU is manufactured with in RISC technology an important factor when deciding
which microprocessor to use.
RISC Reduced Instruction Set Computer, gives the PIC16F887 two great advantages:
The CPU can recognizes only 35 simple instructions (In order to program some other
microcontrollers it is necessary to know more than 200 instructions by heart).
The execution time is the same for all instructions except two and lasts 4 clock cycles
(oscillator frequency is stabilized by a quartz crystal). The Jump and Branch instructions
execution time is 2 clock cycles. It means that if the microcontroller‘s operating speed is
20MHz, execution time of each instruc tion will be 200nS, i.e. the program will be
executed at the speed of 5 million instructions per second!
Fig.4.4 CPU Memory
32. Memory
This microcontroller has three types of memory- ROM, RAM and EEPROM. All of them will be
separately discussed since each has specific functions, features and organization.
ROM Memory
ROM memory is used to permanently save the program being executed. This is why it is often
called ―program memory‖. The PIC16F887 has 8Kb of ROM (in total of 8192 locations). Since
this ROM is made with FLASH technology, its contents can be changed by providing a special
programming voltage (13V).
Anyway, there is no need to explain it in detail because it is automatically performed by means
of a special program on the PC and a simple electronic device called the Programmer.
Fig:4.5 ROM Memory Concept
EEPROM Memory
Similar to program memory, the contents of EEPROM is permanently saved, even the power
goes off. However, unlike ROM, the contents of the EEPROM can be changed during operation
of the microcontroller. That is why this memory (256 locations) is a perfect one for permanently
saving results created and used during the operation.
RAM Memory
This is the third and the most complex part of microcontroller memory. In this case, it consists of
two parts: general-purpose registers and special-function registers (SFR).
33. Even though both groups of registers are cleared when power goes off and even though they are
manufactured in the same way and act in the similar way, their functions do not have many
things in common.
Fig.4.6 SFR and General Purpose Registers
General-Purpose Registers
General-Purpose registers are used for storing temporary data and results created during
operation. For example, if the program performs a counting (for example, counting products on
the assembly line), it is necessary to have a register which stands for what we in everyday life
call ―sum‖. Since the microcontroller is not creative at all, it is necessary to specify the address
34. of some general purpose register and assign it a new function. A simple program to increment
the value of this register by 1, after each product passes through a sensor, should be created.
Therefore, the microcontroller can execute that program because it now knows what and where
the sum which must be incremented is. Similarly to this simple example, each program variable
must be pre-assigned some of general-purpose register.
SFR Registers
Special-Function registers are also RAM memory locations, but unlike general-purpose registers,
their purpose is predetermined during manufacturing process and cannot be changed. Since their
bits are physically connected to particular circuits on the chip (A/D converter, serial
communication module, etc.), any change of their contents directly affects the operation of the
microcontroller or some of its circuits. For example, by changing the TRISA register, the
function of each port A pin can be changed in a way it acts as input or output. Another feature of
these memory locations is that they have their names (registers and their bits), which
considerably facilitates program writing. Since high-level programming language can use the list
of all registers with their exact addresses, it is enough to specify the register‘s name in order to
read or change its contents.
RAM Memory Banks
The data memory is partitioned into four banks. Prior to accessing some register during program
writing (in order to read or change its contents), it is necessary to select the bank which contains
that register. Two bits of the STATUS register are used for bank selecting, which will be
discussed later. In order to facilitate operation, the most commonly used SFRs have the same
address in all banks which enables them to be easily accessed.
35. 4.3 STACK
A part of the RAM used for the stack consists of eight 13-bit registers. Before the
microcontroller starts to execute a subroutine (CALL instruction) or when an interrupt occurs, the
address of first next instruction being currently executed is pushed onto the stack, i.e. onto one of
its registers. In that way, upon subroutine or interrupt execution, the microcontroller knows from
where to continue regular program execution. This address is cleared upon return to the main
program because there is no need to save it any longer, and one location of the stack is
automatically available for further use.
It is important to understand that data is always circularly pushed onto the stack. It means that
after the stack has been pushed eight times, the ninth push overwrites the value that was stored
with the first push. The tenth push overwrites the second push and so on. Data overwritten in this
way is not recoverable. In addition, the programmer cannot access these registers for write or
read and there is no Status bit to indicate stack overflow or stack underflow conditions. For that
reason, one should take special care of it during program writing.
Interrupt System
The first thing that the microcontroller does when an interrupt request arrives is to execute the
current instruction and then stop regular program execution. Immediately after that, the current
program memory address is automatically pushed onto the stack and the default address
(predefined by the manufacturer) is written to the program counter. That location from where the
program continues execution is called the interrupt vector. For the PIC16F887 microcontroller,
this address is 0004h. As seen in Fig. 1-7 below, the location containing interrupt vector is
passed over during regular program execution.
Part of the program being activated when an interrupt request arrives is called the interrupt
routine. Its first instruction is located at the interrupt vector. How long this subroutine will be and
what it will be like depends on the skills of the programmer as well as the interrupt source itself.
Some microcontrollers have more interrupt vectors (every interrupt request has its vector), but in
this case there is only one. Consequently, the first part of the interrupt routine consists in
interrupt source recognition.
Finally, when the interrupt source is recognized and interrupt routine is executed, the
microcontroller reaches the RETFIE instruction, pops the address from the stack and continues
program execution from where it left off.
36. Fig.4.7 Interrupt System
How to use SFRs
You have bought the microcontroller and have a good idea how to use it...There is a long list of
SFRs with all bits. Each of them controls some process. All in all, it looks like a big control table
with a lot of instruments and switches. Now you are concerned about whether you will manage
to learn how to use them all? You will probably not, but don‘t worry, you don‘t have to! Such
powerful microcontrollers are similar to a supermarkets: they offer so many things at low prices
and it is only up to you to choose. Therefore, select the field you are interested in and study only
what you need to know. Afterwards, when you completely understand hardware operation, study
SFRs which are in control of it ( there are usually a few of them). To reiterate, during program
writing and prior to changing some bits of these registers, do not forget to select the appropriate
bank. This is why they are listed in the tables above.
37. 4.4 Core SFRs
Features and Function
The special function registers can be classified into two categories:
Core (CPU) registers - control and monitor operation and processes in the central
processor. Even though there are only a few of them, the operation of the whole
microcontroller depends on their contents.
Peripheral SFRs- control the operation of peripheral units (serial communication module,
A/D converter etc.). Each of these registers is mainly specialized for one circuit and for
that reason they will be described along with the circuit they are in control of.
The core (CPU) registers of the PIC16F887 microcontroller are described in this chapter. Since
their bits control several different circuits within the chip, it is not possible to classify them into
some special group. These bits are described along with the processes they control.
STATUS Register
The STATUS register contains: the arithmetic status of the W register, the RESET status and the
bank select bits for data memory. One should be careful when writing a value to this register
because if you do it wrong, the results may be different than expected. For example, if you try to
clear all bits using the CLRF STATUS instruction, the result in the register will be 000xx1xx
instead of the expected 00000000. Such errors occur because some of the bits of this register are
set or cleared according to the hardware as well as because the bits 3 and 4 are readable only. For
these reasons, if it is required to change its content (for example, to change active bank), it is
recommended to use only instructions which do not affect any Status bits (C, DC and Z).
OPTION_REG Register
Fig:-4.8
The OPTION_REG register contains various control bits to configure: Timer0/WDT prescaler,
timer TMR0, external interrupt and pull-ups on PORTB.
38. Interrupt System Registers
When an interrupt request arrives it does not mean that interrupt will automatically occur,
because it must also be enabled by the user (from within the program). Because of that, there are
special bits used to enable or disable interrupts. It is easy to recognize these bits by IE contained
in their names (stands for Interrupt Enable). Besides, each interrupt is associated with another bit
called the flag which indicates that interrupt request has arrived regardless of whether it is
enabled or not. They are also easily recognizable by the last two letters contained in their names-
IF (Interrupt Flag).
As seen, everything is based on a simple and efficient idea. When an interrupt request arrives,
the flag bit is to be set first.
Fig:-4.9 Interrupt System Registers
If the appropriate IE bit is not set (0), this event will be completely ignored. Otherwise, an
interrupt occurs! In case several interrupt sources are enabled, it is necessary to detect the active
one before the interrupt routine starts execution. Source detection is performed by checking flag
bits.
It is important to understand that the flag bits are not automatically cleared, but by software
during interrupt routine execution. If this detail is neglected, another interrupt will occur
immediately upon return to the program, even though there are no more requests for its
execution! Simply put, the flag as well as IE bit remained set.
All interrupt sources typical of the PIC16F887 microcontroller are shown on the next page. Note
several things:
GIE bit - enables all unmasked interrupts and disables all interrupts simultaneously.
PEIE bit - enables all unmasked peripheral interrupts and disables all peripheral interrupts (This does not
concern Timer TMR0 and port B interrupt sources).
To enable interrupt caused by changing logic state on port B, it is necessary to enable it for each
bit separately. In this case, bits of the IOCB register have the function to control IE bits.
39. Fig:-4.10 Interrupt SFRs
INTCON Register
The INTCON register contains various enable and flag bits for TMR0 register overflow, PORTB
change and external INT pin interrupts.
Fig:-4.11
40. PIE1 Register
The PIE1 register contains the peripheral interrupt enable bits.
Fig:-4.12
PIE2 Register
The PIE2 Register also contains the various interrupt enable bits.
Fig:-4.13
PIR1 Register
The PIR1 register contains the interrupt flag bits.
Fig:-4.14
41. PIR2 Register
The PIR2 register contains the interrupt flag bits.
Fig:-4.15
PCON register
The PCON register contains only two flag bits used to differentiate between a: power-on reset,
brown-out reset, Watchdog Timer Reset and external reset (through MCLR pin).
Fig:-4.16
PCL and PCLATH Registers
The size of the program memory of the PIC16F887 is 8K. Therefore, it has 8192 locations for
program storing. For this reason the program counter must be 13-bits wide (2^13 = 8192). In
order that the contents of some location may be changed in software during operation, its address
must be accessible through some SFR. Since all SFRs are 8-bits wide, this register is
―artificially‖ created by dividing its 13 bits into two independent registers: PCLATH and PCL.
If the program execution does not affect the program counter, the value of this register is
automatically and constantly incremented +1, +1, +1, +1... In that way, the program is executed
just as it is written- instruction by instruction, followed by a constant address increment.
Fig:-4.17 PCL and PCLATH Registers
42. If the program counter is changed in software, then there are several things that should be kept in
mind in order to avoid problems:
Eight lower bits (the low byte) come from the PCL register which is readable and
writable, whereas five upper bits coming from the PCLATH register are writable only.
The PCLATH register is cleared on any reset.
In assembly language, the value of the program counter is marked with PCL, but it
obviously refers to 8 lower bits only. One should take care when using the ―ADDWF
PCL‖ instruction. This is a jump instruction which specifies the target location by adding
some number to the current address. It is often used when jumping into a look-up table or
program branch table to read them. A problem arises if the current address is such that
addition causes change on some bit belonging to the higher byte of the PCLATH register.
Do you see what is going on?
Executing any instruction upon the PCL register simultaneously causes the Prog ram
Counter bits to be replaced by the contents of the PCLATH register. However, the PCL
register has access to only 8 lower bits of the instruction result and the following jump
will be completely incorrect. The problem is solved by setting such instructions at
addresses ending by xx00h. This enables the program to jump up to 255 locations. If
longer jumps are executed by this instruction, the PCLATH register must be incremented
by 1 for each PCL register overflow.
On subroutine call or jump execution (instructions CALL and GOTO), the microcontroller is
able to provide only 11-bit addressing. For this reason, similar to RAM which is divided
in ―banks‖, ROM is divided in four ―pages‖ in size of 2K each. Such instructions are
executed within these pages without any problems. Simply, since the processor is
provided with 11-bit address from the program, it is able to address any location within
2KB. Figure 2-17 below illustrates this situation as a jump to the subroutine PP1 address.
However, if a subroutine or jump address are not within the same page as the location
from where the jump is, two ―missing‖- higher bits should be provided by writing to the
PCLATH register. It is illustrated in figure 2-17 below as a jump to the subroutine PP2
address.
43. Fig:-4.18 PCLATH Registers
In both cases, when the subroutine reaches instructions RETURN, RETLW or RETFIE (to return to
the main program), the microcontroller will simply continue program execution from where it
left off because the return address is pushed and saved onto the stack which, as mentioned,
consists of 13-bit registers.
Indirect addressing
In addition to direct addressing which is logical and clear by itself (it is sufficient to specify
address of some register to read its contents), this microcontroller is able to perform indirect
addressing by means of the INDF and FSR registers. It sometimes considerably simplifies
program writing. The whole procedure is enabled because the INDF register is not true one
(physically does not exist), but only specifies the register whose address is located in the FSR
register. Because of this, write or read from the INDF register actually means write or read from
the register whose address is located in the FSR register. In other words, registers‘ addresses are
specified in the FSR register, and their contents are stored in the INDF register. The difference
between direct and indirect addressing is illustrated in the figure 2-18 below:
As seen, the problem with the ―missing addressing bits‖ is solved by ―borrowing‖ from another
register. This time, it is the seventh bit called IRP from the STATUS register.
45. 4.5 TIMER
The timers of the PIC16F887 microcontroller can be briefly described in only one sentence.
There are three completely independent timers/counters marked as TMR0, TMR1 and TMR2.
But it‘s not as simple as that.
Timer TMR0
The timer TMR0 has a wide range of applications in practice. Very few programs don't use it in
some way. It is very convenient and easy to use for writing programs or subroutines for
generating pulses of arbitrary duration, time measurement or counting external pulses (events)
with almost no limitations.
The timer TMR0 module is an 8-bit timer/counter with the following features:
8-bit timer/counter;
8-bit prescaler (shared with Watchdog timer);
Programmable internal or external clock source;
Interrupt on overflow; and
Programmable external clock edge selection.
Figure below represents the timer TMR0 schematic with all bits which determine its operation. These bits are stored
in the OPTION_REG Register.
Fig:-4.20
46. The function of the PSA bit 0 is shown in the two figures below:
Fig:-4.21
The function of the PSA bit 1 is shown in the two figures below:
Fig:-4.22
47. As seen, the logic state of the PSA bit determines whether the prescaler is to be assigned to the
timer/counter or watch-dog timer.
Additionally it is also worth mentioning:
When the prescaler is assigned to the timer/counter, any write to the TMR0 register will
clear the prescaler;
When the prescaler is assigned to watch-dog timer, a CLRWDT instruction will clear
both the prescaler and WDT;
Writing to the TMR0 register used as a timer, will not cause the pulse counting to start
immediately, but with two instruction cycles delay. Accordingly, it is necessary to adjust
the value written to the TMR0 register;
When the microcontroller is setup in sleep mode, the oscillator is turned off. Overflow
cannot occur since there are no pulses to count. This is why the TMR0 overflow interrupt
cannot wake up the processor from Sleep mode;
When used as an external clock counter without prescaler, a minimal pulse length or a
pause between two pulses must be 2 Tosc + 20 nS. Tosc is the oscillator signal period;
When used as an external clock counter with prescaler, a minimal pulse length or a pause
between two pulses is 10nS;
The 8-bit prescaler register is not available to the user, which means that it cannot be
directly read or written to;
When changing the prescaler assignment from TMR0 to the watch-dog timer, the
following instruction sequence must be executed in order to avoid reset:
To select mode:
Timer mode is selected by the T0CS bit of the OPTION_REG register, (T0CS: 0=timer,
1=counter);
When used, the prescaler should be assigned to the timer/counter by clearing the PSA bit
of the OPTION_REG register. The prescaler rate is set by using the PS2-PS0 bits of the
same register; and
When using interrupt, the GIE and TMR0IE bits of the INTCON register should be set.
Reset the TMR0 register or write some well-known value to it;
To measure time:
Elapsed time (in microseconds when using quartz 4MHz) is measured by reading the
TMR0 register; and
The flag bit TMR0IF of the INTCON register is automatically set every time the TMR0
register overflows. If enabled, an interrupt occurs.
To count pulses:
The polarity of pulses are to be counted is selected on the RA4 pin are selected by the
TOSE bit of the OPTION register (T0SE: 0=positive, 1=negative pulses); and
48. Number of pulses may be read from the TMR0 register. The prescaler and interrupt are
used in the same manner as in timer mode.
Timer TMR1
Timer TMR1 module is a 16-bit timer/counter, which means that it consists of two registers
(TMR1L and TMR1H). It can count up 65.535 pulses in a single cycle, i.e. before the counting
starts from zero.
Fig:-4.23 Timer TMR1
Similar to the timer TMR0, these registers can be read or written to at any moment. In case an
overflow occurs, an interrupt is generated.
The timer TMR1 module may operate in one of two basic modes- as a timer or a counter.
However, unlike the timer TMR0, each of these modules has additional functions.
Parts of the T1CON register are in control of the operation of the timer TMR1.
Fig:-4.24 Timer TMR1 Prescaler
49. Timer TMR1 has a completely separate prescaler which allows 1, 2, 4 or 8 divisions of the clock
input. The prescaler is not directly readable or writable. However, the prescaler counter is
automatically cleared upon write to the TMR1H or TMR1L register.
Timer TMR1 Oscillator
RC0/T1OSO and RC1/T1OSI pins are used to register pulses coming from peripheral
electronics, but they also have an additional function. As seen in figure 4-7, they are
simultaneously configured as both input (pin RC1) and output (pin RC0) of the additional LP
quartz oscillator (low power).
This additional circuit is primarily designed for operating at low frequencies (up to 200 KHz),
more precisely, for using the 32,768 KHz quartz crystal. Such crystals are used in quartz watches
because it is easy to obtain one-second-long pulses by simply dividing this frequency.
Since this oscillator does not depend on internal clocking, it can operate even in sleep mode. It is
enabled by setting the T1OSCEN control bit of the T1CON register. The user must provide a
software time delay (a few milliseconds) to ensure proper oscillator start-up.
Fig:-4.25
Table below shows the recommended values of capacitors to suit the quartz oscillator. These
values do not have to be exact. However, the general rule is: the higher the capacitor's capacity
the higher the stability, which, at the same time, prolongs the time needed for the oscillator
stability.
Oscillator Frequency C1 C2
32 kHz 33 pF 33 pF
LP
100 kHz 15 pF 15 pF
200 kHz 15 pF 15 pF
Fig:-4.26 Timer TMR1 Oscillator
50. Timer TMR1 Gate
Timer 1 gate source is software configurable to be the T1G pin or the output of comparator C2.
This gate allows the timer to directly time external events using the logic state on the T1G pin or
analog events using the comparator C2 output. Refer to figure 4-7 above. In order to time a
signals duration it is sufficient to enable such gate and count pulses having passed through it.
TMR1 in timer mode
In order to select this mode, it is necessary to clear the TMR1CS bit. After this, the 16-bit
register will be incremented on every pulse coming from the internal oscillator. If the 4MHz
quartz crystal is in use, it will be incremented every microsecond.
In this mode, the T1SYNC bit does not affect the timer because it counts internal clock pulses.
Since the whole electronics uses these pulses, there is no need for synchronization.
Fig:-4.27
The microcontroller‘s clock oscillator does not run during sleep mode so the timer register
overflow cannot cause any interrupt.
Timer TMR1 Oscillator
The power consumption of the microcontroller is reduced to the lowest level in Sleep mode. The
point is to stop the oscillator. Anyway, it is easy to set the timer in this mode- by writing a
SLEEP instruction to the program. A problem occurs when it is necessary to wake up the
microcontroller because only an interrupt can do that. Since the microcontroller ―sleeps‖, an
interrupt must be triggered by external electronics. It can all get incredibly complicated if it is
necessary the ‗wake up‘ occurs at regular time intervals...
51. Fig:-4.28
In order to solve this problem, a completely independent Low Power quartz oscillator, able to
operate in sleep mode, is built into the PIC16F887 microcontroller. Simply, what previously has
been a separate circuit, it is now built into the microcontroller and assigned to the timer TMR1.
The oscillator is enabled by setting the T1OSCEN bit of the T1CON register. After that, the
TMR1CS bit of the same register then is used to determine that the timer TMR1 uses pulse
sequences from that oscillator.
The signal from this quartz oscillator is synchronized with the microcontroller clock by clearing the
T1SYNC bit. In that case, the timer cannot operate in sleep mode. You wonder why? Because the circuit
for synchronization uses the clock of microcontroller!; and
The TMR1 register overflow interrupt may be enabled. Such interrupts will occur in sleep mode as well.
TMR1 in counter mode
Timer TMR1 starts to operate as a counter by setting the TMR1CS bit. It means that the timer
TMR1 is incremented on the rising edge of the external clock input T1CKI. If control bit
T1SYNC of the T1CON register is cleared, the external clock inputs will be synchronized on
their way to the TMR1 register. In other words, the timer TMR1 is synchronized to the
microcontroller system clock and called a synchronous counter.
When the microcontroller ,operating in this way, is set in sleep mode, the TMR1H and TMR1L
timer registers are not incremented even though clock pulses appear on the input pins. Simply,
since the microcontroller system clock does not run in this mode, there are no clock inputs to use
for synchronization. However, the prescaler will continue to run if there are clock pulses on the
pins since it is just a simple frequency divider.
52. Fig:-4.29
This counter registers a logic one (1) on input pins. It is important to understand that at least one
falling edge must be registered prior to the first increment on rising edge. Refer to figure on the
left. The arrows in figure 4-11 denote counter increments.
T1CON Register
Fig:-4.30
T1GINV - Timer1 Gate Invert bit acts as logic state inverter on the T1G pin gate or the
comparator C2 output (C2OUT) gate. It enables the timer to mea sure time whilst the gate is high
or low.
1 - Timer 1 counts when the pin T1G or bit C2OUT gate is high (1); and
0 - Timer 1 counts when the pin T1G or bit C2OUT gate is low (0).
53. TMR1GE - Timer1 Gate Enable bit determines whether the pin T1G or comparator C2 output
(C2OUT) gate will be active or not. This bit is functional only in the event that the timer TMR1
is on (bit TMR1ON = 1). Otherwise, this bit is ignored.
1 Timer TMR1 is on only if timer 1 gate is not active; and
0 Gate does not affect the timer TMR1.
T1CKPS1, T1CKPS0 - Timer1 Input Clock Prescale Select bits determine the rate of the
prescaler assigned to the timer TMR1.
T1CKPS1 T1CKPS0 Prescaler Rate
0 0 1:1
0 1 1:2
1 0 1:4
1 1 1:8
Fig:- 4-2 Prescaler Rate
T1OSCEN - LP Oscillator Enable Control bit
1 - LP oscillator is enabled for timer TMR1 clock (oscillator with low power consumption and frequency
32.768 kHz); and
0 - LP oscillator is off.
T1SYNC - Timer1 External Clock Input Synchronization Control bit enables synchronization of
the LP oscillator input or T1CKI pin input with the microcontroller internal clock. When
counting pulses from the local clock source (bit TMR1CS = 0), this bit is ignored.
1 - Do not synchronize external clock input; and
0 - Synchronize external clock input.
TMR1CS - Timer TMR1 Clock Source Select bit
1 - Counts pulses on the T1CKI pin (on the rising edge 0-1); and
0 - Counts pulses of the internal clock of microcontroller.
TMR1ON - Timer1 On bit
1 - Enables Timer TMR1; and
0 - Stops Timer TMR1.
In order to use the timer TMR1 properly, it is necessary to perform the following:
Since it is not possible to turn off the prescaler, its rate should be adjusted by using bits
T1CKPS1 and T1CKPS0 of the register T1CON (Refer to table 4-2);
54. The mode should be selected by the TMR1CS bit of the same register (TMR1CS: 0= the
clock source is quartz oscillator, 1= the clock source is supplied externally);
By setting the T1OSCEN bit of the same register, the timer TMR1 is turned on and the
TMR1H and TMR1L registers are incremented on every clock input. Counting stops by
clearing this bit;
The prescaler is cleared by clearing or writing the counter registers; and
By filling both timer registers, the flag TMR1IF is set and counting starts from zero.
Timer TMR2
Timer TMR2 module is an 8-bit timer which operates in a very specific way.
Fig:-4.32
The pulses from the quartz oscillator first pass through the prescaler whose rate may be changed
by combining the T2CKPS1 and T2CKPS0 bits. The output of the prescaler is then used to
increment the TMR2 register starting from 00h. The values of TMR2 and PR2 are constantly
compared and the TMR2 register keeps on being incremented until it matches the value in PR2.
When a match occurs, the TMR2 register is automatically cleared to 00h. The timer TMR2
Postscaler is incremented and its output is used to generate an interrupt if it is enabled.
The TMR2 and PR2 registers are both fully readable and writable. Counting may be stopped by
clearing the TMR2ON bit, which contributes to power saving.
As a special option, the moment of TMR2 reset may be also used to determine synchronous
serial communication baud rate.
The timer TMR2 is controlled by several bits of the T2CON register.
55. T2CON Register
Fig:-4.33 T2CON Register
TOUTPS3 - TOUTPS0 - Timer2 Output Postscaler Select bits are used to determine the
postscaler rate according to the following table:
TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 Postscaler Rate
0 0 0 0 1:1
0 0 0 1 1:2
0 0 1 0 1:3
0 0 1 1 1:4
0 1 0 0 1:5
0 1 0 1 1:6
0 1 1 0 1:7
0 1 1 1 1:8
1 0 0 0 1:9
1 0 0 1 1:10
1 0 1 0 1:11
1 0 1 1 1:12
1 1 0 0 1:13
1 1 0 1 1:14
1 1 1 0 1:15
1 1 1 1 1:16
Fig:4.34 Postscaler Rate
TMR2ON - Timer2 On bit turns the timer TMR2 on.
1 - Timer T2 is on; and
0 - Timer T2 is off.
56. T2CKPS1, T2CKPS0 - Timer2 Clock Prescale bits determine prescaler rate:
T2CKPS1 T2CKPS0 Prescaler Rate
0 0 1:1
0 1 1:4
1 X 1:16
Fig:-4.35 Prescaler Rate
When using the TMR2 timer, one should know several specific details that have to do with its
registers:
Upon power-on, the PR2 register contains the value FFh;
Both prescaler and postscaler are cleared by writing to the TMR2 register;
Both prescaler and postscaler are cleared by writing to the T2CON register; and
On any reset, both prescaler and postscaler are cleared.
57. CHAPTER-5
OTHER COMPONENTS:
5.1DIODE:
A diode is a semiconductor device which allows current to flow through it in only one direction.
Although a transistor is also a semiconductor device, it does not operate the way a diode does. A diode
is specifically made to allow current to flow through it in only one direction. Some ways in which the
diode can be used are listed here.
A diode can be used as a rectifier that converts AC (Alternating Current) to DC (Direct Current) for a
power supply device.
Diodes can be used to separate the signal from radio frequencies.
Diodes can be used as an on/off switch that controls current.
Fig:-5.1
This symbol is used to indicate a diode in a circuit diagram. The meaning of the symbol is
(Anode) (Cathode). Current flows from the anode side to the cathode side.
Although all diodes operate with the same general principle, there are different types suited to different
applications. For example, the following devices are best used for the applications noted.
58. Fig:-5.2
Diode symbols: a - standard diode, b - LED, c, d - Zener, e - photo, f,g - tunnel, h - Schottky, i -
breakdown, j - capacitative
V-I characteristics:
FIG:-5.3
The graph on the right shows the electrical characteristics of a typical diode.
When a small voltage is applied to the diode in the forward direction, current flows easily. Because the
diode has a certain amount of resistance, the voltage will drop slightly as current flows through the
diode. A typical diode causes a voltage drop of about 0.6 - 1V (VF) (In the case of silicon diode, almost
0.6V)
59. This voltage drop needs to be taken into consideration in a circuit which uses many diodes in series.
Also, the amount of current passing through the diodes must be considered. When voltage is applied in
the reverse direction through a diode, the diode will have a great resistance to current flow. Different
diodes have different characteristics when reverse-biased. A given diode should be selected depending
on how it will be used in the circuit. The current that will flow through a diode biased in the reverse
direction will vary from several mA to just µA, which is very small.
The limiting voltages and currents permissible must be considered on a case by case basis. For example,
when using diodes for rectification, part of the time they will be required to withstand a reverse voltage.
If the diodes are not chosen carefully, they will break down
Rectification / Switching / Regulation Diode:
The stripe stamped on one end of the diode shows indicates the polarity of the diode. The stripe shows
the cathode side. The top two devices shown in the picture are diodes used for rectification. They are
made to handle relatively high currents. The device on top can handle as high as 6A, and the one below
it can safely handle up to 1A.
However, it is best used at about 70% of its rating because this current value is a maximum rating.
The third device from the top (red color) has a part number of 1S1588. This diode is used for switching,
because it can switch on and off at very high speed. However, the maximum current it can handle is 120
mA. This makes it well suited to use within digital circuits. The maximum reverse voltage (reverse
bias).this diode can handle is 30V
60. The device at the bottom of the picture is a voltage regulation diode with a rating of 6V. When this type
of diode is reverse biased, it will resist changes in voltage. If the input voltage is increased, the output
voltage will not change. (Or any change will be an insignificant amount.) While the output voltage does
not increase with an increase in input voltage, the output current will.
This requires some thought for a protection circuit so that too much current does not flow.
The rated current limit for the device is 30 mA.
Generally, a 3-terminal voltage regulator is used for the stabilization of a power supply. Therefore, this
diode is typically used to protect the circuit from momentary voltage spikes. 3 terminal regulators use
voltage regulation diodes inside.
Rectification diodes are used to make DC from AC. It is possible to do only 'half wave rectification'
using 1 diode. When 4 diodes are combined, 'full wave rectification' occurrs.
Devices that combine 4 diodes in one package are called diode bridges. They are used for full-wave
rectification.
Fig:-5.4
61. 5.2 Light Emitting Diode (LED):
Fig:-5.5
Light emitting diodes must be chosen according to how they will be used, because there are
various kinds. The diodes are available in several colors. The most common colors are red and
green, but there are even blue ones.The device on the far right in the photograph combines a red
LED and green LED in one package.The component lead in the middle is common to both
LEDs. As for the remains two leads, one side is for the green, the other for the red LED. When
both are turned on simultaneously, it becomes orange.
When an LED is new out of the package, the polarity of the device can be determined by looking
at the leads. The longer lead is the Anode side, and the short one is the Cathode side.
The polarity of an LED can also be determined using a resistance meter, or even a 1.5 V battery.
When using a test meter to determine polarity, set the meter to a low resistance measurement
range. Connect the probes of the meter to the LED. If the polarity is correct, the LED will glow.
If the LED does not glow, switch the meter probes to the opposite leads on the LED. In either
case, the side of the diode which is connected to the black meter probe when the LED glows, is
the Anode side. Positive voltage flows out of the black probe when the meter is set to measure
resistance.
Fig:-5.6
62. It is possible to use an LED to obtain a fixed voltage. The voltage drop (forward voltage, or V F)
of an LED is comparatively stable at just about 2V. I explain a circuit in which the voltage was
stabilized with an LED in "Thermometer of bending apparatus-2"..
Shottky barrier diode:
Diodes are used to rectify alternating current into direct current. However, rectification will not occur
when the frequency of the alternating current is too high. This is due to what is known as the "reverse
recovery characteristic."
The reverse recovery characteristic can be explained as follows:
IF the opposite voltage is suddenly applied to a forward-biased diode, current will continue to flow in
the forward direction for a brief moment. This time until the current stops flowing is called the Reverse
Recovery Time. The current is considered to be stopped when it falls to about 10% of the value of the
peak reverse current.
The Shottky barrier diode has a short reverse recovery time, which makes it ideally suited to use in high
frequency rectification.
Fig:-5.7
The Shottky barrier diode has the following characteristics.
The voltage drop in the forward direction is low.
The reverse recovery time is short.
However, it has the following disadvantages.
The diode can have relatively high leakage current.
63. The surge resistance is low. Because the reverse recovery time is short, this diode is often used for the
switching regulator in a high frequency circuit
Diode Marking:
European diodes are marked using two or three letters and a number. The first letter is used to identify
the material used in manufacturing the component (A - germanium, B - silicon), or, in case of letter Z, a
Zener diode.
The second and third letters specify the type and usage of the diode. Some of the verities are:
A - low power diode, like the AA111, AA113, AA121, etc. - they are used in the detector of a radio
receiver; BA124, BA125 : varicap diodes used instead of variable capacitors in receiving devices,
oscillators, etc., BAY80, BAY93, etc. - switching diodes used in devices using logic circuits. BA157,
BA158, etc. - these are switching diodes with short recovery time.
B - two capacitive (varicap) diodes in the same housing, like BB104, BB105, etc.
Y - regulation diodes, like BY240, BY243, BY244, etc. - these regulation diodes come in a plastic
packaging and operate on a maximum current of 0.8A. If there is another Y, the diode is intended for
higher current. For example, BYY44 is a diode whose absolute maximum current rating is 1A. When Y
is the second letter in a Zener diode mark (ZY10, ZY30, etc.) it means it is intended for higher current.
G, G, PD - different tolerance marks for Zener diodes. Some of these are ZF12 (5% tolerance), ZG18
(10% tolerance), ZPD9.1 (5% tolerance).
The third letter is used to specify a property (high current, for example).
American markings begin with 1N followed by a number, 1N4001, for example (regulating diode),
1N4449 (switching diode), etc.
Japanese style is similar to American, the main difference is that instead of N there is S, 1S241 being
one of them.
64. Practical examples:
The diagram of a power supply in figure (3.8) uses several diodes. The first four are in a single package,
identified by B40C1500. This is a bridge rectifier.
The LED in the circuit indicates the transformer is working. Resistor R1 is used to limit the current
through the LED and the brightness of the LED indicates the approximate voltage.
Diodes marked 1N4002 protect the integrated circuit.
Figure 5.3 below shows some other examples of diodes. The life of a globe can be increased by adding a
diode as shown in 5.3a. By simply connecting it in series, the current passing through the globe is halved
and it lasts a lot longer. However the brightness is reduced and the light becomes yellow. The Diode
should have a reverse voltage of over 400V, and a current higher than the globe. A 1N4004 or BY244 is
suitable.A very simple DC voltage stabilizer for low currents can be made using 5.3c as a reference.
65. Fig:-5.8 - using a diode to prolong the light bulb's life span, b - stair-light LED indicator,
c - voltage stabilizer, d - voltage rise indicator, e - rain noise synthesizer, f - backup supply
Unstabilized voltage is marked "U", and stabilized with "UST." Voltage on the Zener diode is
equal to UST, so if we want to achieve a stabilized 9V, we would use a ZPD9.1 diode. Although
this stabilize has limited use it is the basis of all designs found in power supplies.
66. We can also devise a voltage overload detector as shown in figure. A LED indicates when a
voltage is over a predefined value. When the voltage is lower than the operating voltage of the
Zener, the zener acts as a high value resistor, so DC voltage on the base of the transistor is very
low, and the transistor does not "turn on." When the voltage rises to equal the Zener voltage, its
resistance is lowered, and transistor receives current on its base and it turns on to illuminate the
LED. This example uses a 6V Zener diode, which means that the LED is illuminated when the
voltage reaches that value. For other voltage values, different Zener diodes should be used.
Brightness and the exact moment of illuminating the LED can be set with the value of Rx.
To modify this circuit so that it signals when a voltage drops below some predefined level, the
Zener diode and Rx are swapped. For example, by using a 12V Zener diode, we can make a car battery
level indicator. So, when the voltage drops below 12V, the battery is ready for recharge.
Figure 5.3e shows a noise-producing circuit, which produces a rain-like sound. DC current flowing
through diode AA121 isn't absolutely constant and this creates the noise which is amplified by the
transistor (any NPN transistor) and passed to a filter (resistor-capacitor circuit with values 33nF and
100k).
5.3Resistor
Resistors are the most commonly used component in electronics and their purpose is to create specified
values of current and voltage in a circuit. A number of different resistors are shown in the photos. (The
resistors are on millimeter paper, with 1cm spacing to give some idea of the dimensions). Photo 1.1a
shows some low-power resistors, while photo 1.1b shows some higher-power resistors. Resistors with
power dissipation below 5 watt (most commonly used types) are cylindrical in shape, with a wire
protruding from each end for connecting to a circuit . Resistors with power dissipation above 5 watt are
shown below.
67. High-po resistors and rheostats power resistors
The symbol for a resistor is shown in the following diagram (upper: American symbol, lower: European
symbol.)
Resistor symbols
The unit for measuring resistance is the OHM. (the Greek letter Ω - called Omega). Higher resistance values
are represented by "k" (kilo-ohms) and M (meg ohms). For example, 120 000 Ω is represented as 120k, while 1
200 000 Ω is represented as 1M2. The dot is generally omitted as it can easily be lost in the printing process. In
some circuit diagrams, a value such as 8 or 120 represents a resistance in ohms. Another common practice is to
use the letter E for resistance in ohms. The letter R can also be used. For example, 120E (120R) stands for 120
Ω, 1E2 stands for 1R2 etc.
1.1 Carbon film resistors:
This is the most general purpose, cheap resistor. Usually the tolerance of the resistance value is ±5%. Power
ratings of 1/8W, 1/4W and 1/2W are frequently used.
Carbon film resistors have a disadvantage; they tend to be electrically noisy. Metal film resistors are
recommended for use in analog circuits. However, I have never experienced any problems with this noise. The
physical size of the different resistors is as follows.
68. Rough size
Rating
Thicknesspower
Length
(W)
(mm)
(mm)
From the top of the photograph
1/8
23
1/8W
1/4
26
1/4
1/2
39
1/2W
Fig:5.10
This resistor is called a Single-In-Line(SIL) resistor network. It is made with many resistors of the same value,
all in one package. One side of each resistor is connected with one side of all the other resistors inside. One
example of its use would be to control the current in a circuit powering many light emitting diodes (LEDs).
In the photograph on the left, 8 resistors are housed in the package. Each of the leads on the package is one
resistor. The ninth lead on the left side is the common lead. The face value of the resistance is printed. ( It
depends on the supplier. )
Some resistor networks have a "4S" printed on the top of the resistor network. The 4S indicates that the package
contains 4 independent resistors that are not wired together inside. The housing has eight leads instead of nine.
The internal wiring of these typical resistor networks has been illustrated below. The size (black part) of the
resistor network which I have is as follows: For the type with 9 leads, the thickness is 1.8 mm, the height 5mm,
and the width 23 mm. For the types with 8 component leads, the thickness is 1.8 mm, the height 5 mm, and the
width 20 mm.
Fig:-5.11
69. Metal film resistors:
Metal film resistors are used when a lower tolerance (more accurate value) is needed. They are much more
accurate in value than carbon film resistors. They have about ±0.05% tolerance. They have about ±0.05%
tolerance. I don't use any high tolerance resistors in my circuits. Resistors that are about ±1% are more than
sufficient. Ni-Cr (Nichrome) seems to be used for the material of resistor. The metal film resistor is used for
bridge circuits, filter circuits, and low-noise analog signal circuits.
Rough size
Rating
Thicknesspower
Length
(W)
(mm)
(mm)
From the top of the photograph
1/8
23
1/8W (tolerance ±1%)
1/4
26
1/4W (tolerance ±1%)
1W 13.5
(tolerance 12 ±5%)
2W (tolerance ±5%) 2515
Nonlinear resistors
Resistance values detailed above are a constant and do not change if the voltage or current-flow alters. But there
are circuits that require resistors to change value with a change in temperate or light. This function may not be
linear, hence the name NONLINEAR RESISTORS.
There are several types of nonlinear resistors, but the most commonly used include : NTC resistors (figure a)
(Negative Temperature Co-efficient) - their resistance lowers with temperature rise. PTC resistors (figure b)
(Positive Temperature Co-efficient) - their resistance increases with the temperature rise. LDR resistors (figure
70. c) (Light Dependent Resistors) - their resistance lowers with the increase in light. VDR resistors (Voltage
dependent Resistors) - their resistance critically lowers as the voltage exceeds a certain value. Symbols
representing these resistors are shown below.
Fig:-5.12: Nonlinear resistors - a. NTC, b. PTC, c. LDR
In amateur conditions where nonlinear resistor may not be available, it can be replaced with other components.
For example, NTC resistor may be replaced with a transistor with a trimmer potentiometer, for adjusting the
required resistance value. Automobile light may play the role of PTC resistor, while LDR resistor could be
replaced with an open transistor. As an example, figure on the right shows the 2N3055, with its upper part
removed, so that light may fall upon the crystal inside.
Cds Elements (LDR)light dependent resister :
Some components can change resistance value by changes in the amount of light hitting them. One type is the
Cadmium Sulfide Photocell. (Cd) The more light that hits it, the smaller its resistance value becomes. There are
many types of these devices. They vary according to light sensitivity, size, resistance value etc.
Pictured at the left is a typical CDS photocell. Its diameter is 8 mm, 4 mm high, with a cylinder form. When
bright light is hitting it, the value is about 200 ohms, and when in the dark, the resistance value is about 2M
ohms. This device is using for the head lamp illumination confirmation device of the car, for example.
71. Fig:-5.13
Resistor Power Dissipation
If the flow of current through a resistor increases, it heats up, and if the temperature exceeds a certain critical
value, it can be damaged. The wattage rating of a resistor is the power it can dissipate over a long period of
time. Wattage rating is not identified on small resistors. The following diagrams show the size and wattage
rating:
Fig:-5.14 Resistor dimensions
Most commonly used resistors in electronic circuits have a wattage rating of 1/2W or 1/4W. There are smaller
resistors (1/8W and 1/16W) and higher (1W, 2W, 5W, etc).
In place of a single resistor with specified dissipation, another one with the same resistance and higher rating
may be used, but its larger dimensions increase the space taken on a printed circuit board as well as the added
cost.
72. Power (in watts) can be calculated according to one of the following formulae, where U is the symbol for
Voltage across the resistor (and is in Volts), I is the symbol for Current in Amps and R is the resistance in
ohms:
For example, if the voltage across an 820W resistor is 12V, the wattage dissipated by the resistors is:
A 1/4W resistor can be used.
In many cases, it is not easy to determine the current or voltage across a resistor. In this case the wattage
dissipated by the resistor is determined for the "worst" case. We should assume the highest possible voltage
across a resistor, i.e. the full voltage of the power supply (battery, etc).
If we mark this voltage as VB, the highest dissipation is:
For example, if VB=9V, the dissipation of a 220W resistor is:
A 0.5W or higher wattage resistor should be used
73. Fig:-5.15
Resistor Markings
Resistance value is marked on the resistor body. Most resistors have 4 bands. The first two bands provide the
numbers for the resistance and the third band provides the number of zeros. The fourth band indicates the
tolerance. Tolerance values of 5%, 2%, and 1% are most commonly available. The following table shows the
colors used to identify resistor values:
COLOR DIGIT MULTIPLIER TOLERANCE TC
Silver x 0.01 ±10%
Gold x 0.1 ±5%
Black 0 x1
Brown 1 x 10 ±1% ±100*10-6/K
Red 2 x 100 ±2% ±50*10-6/K
Orange 3 x1k ±15*10-6/K
Yellow 4 x 10 k ±25*10-6/K
Green 5 x 100 k ±0.5%
Blue 6 x1M ±0.25% ±10*10-6/K
Violet 7 x 10 M ±0.1% ±5*10-6/K
Grey 8 x 100 M
White 9 x1G ±1*10-6/K
Fig. 5.14: b. Four-band resistor, c. Five-band resistor, d. Cylindrical SMD resistor, e. Flat SMD
resistor
74. CAPACITORS:
The capacitor's function is to store electricity, or electrical energy. The capacitor also functions
as a filter, passing alternating current (AC), and blocking direct current (DC). This symbol ‗F‘ is
used to indicate a capacitor in a circuit diagram. The capacitor is constructed with two electrode
plates facing each other, but separated by an insulator. When DC voltage is applied to the
capacitor, an electric charge is stored on each electrode. While the capacitor is charging up,
current flows. The current will stop flowing when the capacitor has fully charged.
Types of Capacitor:
Fig. 5.15 Types of Capacitor
Breakdown voltage
when using a capacitor, we must pay attention to the maximum voltage which can be used. This
is the "breakdown voltage." The breakdown voltage depends on the kind of capacitor being used.
We must be especially careful with electrolytic capacitors because the breakdown voltage is
comparatively low. The breakdown voltage of electrolytic capacitors is displayed as Working
Voltage. The breakdown voltage is the voltage that when exceeded will cause the dielectric
75. (insulator) inside the capacitor to break down and conduct. When this happens, the failure can be
catastrophic.
Electrolytic Capacitors (Electrochemical type capacitors)
Aluminum is used for the electrodes by using a thin oxidization membrane.
Large values of capacitance can be obtained in comparison with the size of the capacitor,
because the dielectric used is very thin. The most important characteristic of electrolytic
capacitors is that they have polarity. They have a positive and a negative electrode. [Polarised]
This means that it is very important which way round they are connected. If the capacitor is
subjected to voltage exceeding its working voltage, or if it is connected with incorrect polarity, it
may burst. It is extremely dangerous, because it can quite literally explode. Make absolutely no
mistakes. Generally, in the circuit diagram, the positive side is indicated by a "+" (plus) symbol.
Electrolytic capacitors range in value from about 1µF to thousands of µF. Mainly this type of
capacitor is used as a ripple filter in a power supply circuit, or as a filter to bypass low frequency
signals, etc. Because this type of capacitor is comparatively similar to the nature of a coil in
construction, it isn't possible to use for high-frequency circuits. (It is said that the frequency
characteristic is bad.)
The photograph on the left is an example of the different values of electrolytic capacitors in
which the capacitance and voltage differ.
Fig:-5.16 Electrolytic Capacitors
From the left to right:
1µF (50V) [diameter 5 mm, high 12 mm]
47µF (16V) [diameter 6 mm, high 5 mm]
100µF (25V) [diameter 5 mm, high 11 mm]
76. 220µF (25V) [diameter 8 mm, high 12 mm]
1000µF (50V) [diameter 18 mm, high 40 mm]
The size of the capacitor sometimes depends on the manufacturer. So the sizes shown here on
this page are just examples.
Ceramic Capacitors
Ceramic capacitors are constructed with materials such as titanium acid barium used as the
dielectric. Internally, these capacitors are not constructed as a coil, so they can be used in high
frequency applications. Typically, they are used in circuits which bypass high frequency signals
to ground. These capacitors have the shape of a disk. Their capacitance is comparatively small.
The capacitor on the left is a 100pF capacitor with a diameter of about 3 mm. The capacitor on
the right side is printed with 103, so 10 x 103pF becomes 0.01 µF. The diameter of the disk is
about 6 mm. Ceramic capacitors have no polarity. Ceramic capacitors should not be used for
analog circuits, because they can distort the signal.
Fig:- 5.17Ceramic Capacitors
Variable Capacitors:
Variable capacitors are used for adjustment etc. of frequency mainly. On the left in the
photograph is a "trimmer," which uses ceramic as the dielectric. Next to it on the right is one that
uses polyester film for the dielectric. The pictured components are meant to be mounted on a
printed circuit board.
77. Fig:-5.18 Variable Capacitors
When adjusting the value of a variable capacitor, it is advisable to be careful. One of the
component's leads is connected to the adjustment screw of the capacitor. This means that the
value of the capacitor can be affected by the capacitance of the screwdriver in your hand. It is
better to use a special screwdriver to adjust these components.
78. 5.4 Motor Driver ICs: L293/L293D and L298
L293D L298
Fig:-5.19 Fig:-5.20
The current provided by the MCU is of the order of 5mA and that required by a motor is
~500mA. Hence, motor can‘t be controlled directly by MCU and we need an interface
between the MCU and the motor.
A Motor Driver IC like L293D or L298 is used for this purpose which has two H-bridge
drivers. Hence, each IC can drive two motors.
Note that a motor driver does not amplify the current; it only acts as a switch (An H bridge is
nothing but 4 switches).
Fig:-5.21
Drivers are enabled in pairs, with drivers 1 and 2 being enabled by the Enable pin. When
an enable input is high (logic 1 or +5V), the associated drivers are enabled and their
outputs are active and in phase with their inputs.
79. When the enable pin is low, the output is neither high nor low (disconnected),
irrespective of the input.
Direction of the motor is controlled by asserting one of the inputs to motor to be high
(logic 1) and the other to be low (logic 0).
To move the motor in opposite direction just interchange the logic applied to the two
inputs of the motors.
Asserting both inputs to logic high or logic low will stop the motor.
Resistance of our motors is about 26 ohms i.e. its short circuit current will be around.
0.46Amp which is below the maximum current limit.
It is always better to use high capacitance (~1000μF) in the output line of a motor driver
which acts as a small battery at times of current surges and hence improves battery life.
Difference between L293 and L293D: Output current per channel = 1A for L293 and
600mA for L293D.
80. Motor Driver:
H- Bridge Concept :
It is an electronic circuit which enables a voltage to be applied across a load in either
direction.
It allows a circuit full control over a standard electric DC motor. That is, with an H-
bridge, a microcontroller, logic chip, or remote control can electronically command the
motor to go forward, reverse, brake, and coast.
H-bridges are available as integrated circuits, or can be built from discrete components
A "double pole double throw" relay can generally achieve the same electrical
functionality as an H-bridge, but an H-bridge would be preferable where a smaller
physical size is needed, high speed switching, low driving voltage, or where the wearing
out of mechanical parts is undesirable.
The term "H-bridge" is derived from the typical graphical representation of such a
circuit, which is built with four switches, either solid-state (eg, L293/ L298) or
mechanical (eg, relays).
Fig:-5.23 Structure of an H-bridge
81. S1 S2 S3 S4 RESULT
1 0 0 1 MOTOR
ROTATE IN
ONE
DIRECTION
0 1 1 0 MOTOR
ROTATE IN
OPP.
DIRECTION
0 0 0 0 MOTOR FREE
TO
RUN(COASTS)
1 0 1 0 MOTOR
BRAKE
0 1 0 1 MOTOR
BRAKE
Fig:-5.24 H-BRIDGE MOTOR DRIVER CONCEPT
82. 5.5Sensors:
5.5.1ANALOG SENSOR
Fig:-5.24
Fig:-5.25
The IR analog sensor consists of:
Transmitter: An Infra Red emitting diode
Receiver: A Phototransistor (also referred as photodiode)
It is better to keep R2 as a variac to vary the sensitivity.
83. The output varies from 0V to 5V depending upon the amount of IR it receives, hence the name
analog.
The output can be taken to a microcontroller either to its ADC (Analog to Digital Converter) or
LM 339 can be used as a comparator.
Digital IR Sensor - TSOP Sensor
Fig:-5.26
TSOP 1738 Sensor is a digital IR Sensor; It is logic 1 (+5V) when IR below a threshold
is falling on it and logic 0 (0V) when it receives IR above threshold.
It does not respond to any stray IR, it only responds to IR falling on it at a pulse rate of
38 KHz. Hence we have a major advantage of high immunity against ambient light.
No comparator is required and the range of the sensor can be varied by varying the
intensity of the IR emitting diode (the variac in figure).
84. 5.6 8870 DTMF DECODER IC
The M-8870 is a full DTMF Receiver that integrates both band split filter and decoder functions
into a single18-pin DIP or SOIC package. Manufactured using CMOS process technology, the
M-8870 offers low power consumption (35 mW max) and precise data handling. Its filter section
uses switched capacitor technology for both the high and low group filters and for dial tone
rejection. Its decoder uses digital counting techniques to detect and decode all 16 DTMF tone
pairs into a 4-bit code. External component count is minimized by provision of an on-chip
differential input amplifier, clock generator, and latched tri-state interface bus. Minimal external
components required include a low-cost 3.579545 MHz color burst crystal, a timing resistor, and
a timing capacitor. The M-8870-02 provides a ―power-down‖ option which, when enabled, drops
consumption to less than 0.5 mW. The M-8870-02 can also inhibit the decoding of fourth
column digits
Fig:-5.27
Functional Description
M-8870 operating functions include a band split filter that separates the high and low tones of the
received pair, and a digital decoder that verifies both the frequency and duration of the received
tones before passing the resulting 4-bit code to the output bus.
85. Filter:
The low and high group tones are separated by applying the dual-tone signal to the inputs of two
6th order switched capacitor band pass filters with bandwidths
That corresponds to the bands enclosing the low and high group tones. The filter also
incorporates notches at 350 and 440 Hz, providing excellent dial tone rejection. Each filter
output is followed by a single-order switched capacitor section that smoothes the signals prior to
limiting. Signal limiting is performed by high gain
comparators provided with hysteresis to prevent detection of unwanted low-level signals and
noise. The comparator outputs provide full-rail logic swings at the frequencies of the incoming
tones.
The M-8870 decoder uses a digital counting technique to determine the frequencies of the
limited tones and to verify that they correspond to standard DTMF frequencies. A complex
averaging algorithm is used to protect against tone simulation by extraneous signals (such as
voice) while tolerating small frequency variations. The algorithm ensures an optimum
combination of immunity to talk off and tolerance to interfering signals
(Third tones) and noise. When the detector recognizes the simultaneous presence of two valid
tones (known as signal condition), it raises the Early Steering flag (Est.). Any subsequent loss of
signal condition will cause Est. to fall.
86. 5.7RELAYS
STRIP
OUT N/C
OUT N/O
SPRING
230V P
MAGNET
A relay is an electrically operated switch. The relay contacts can be made to operate in
the pre-arranged fashion. For instance, normally open contacts close and normally closed
contacts open. In electromagnetic relays, the contacts however complex they might be,
they have only two position i.e. OPEN and CLOSED, whereas in case of electromagnetic
switches, the contacts can have multiple positions.
87. NEED FOR THE USE OF RELAY
The reason behind using relay for switching loads is to provide complete electrical
isolation. The means that there is no electrical connection between the driving circuits
and the driven circuits. The driving circuit may be low voltage operated low power
circuits that control several kilowatts of power. In our circuit where a high fan could be
switched on or off depending upon the output from the telephone.
Since the relay circuit operated on a low voltage, the controlling circuit is quite safe. In
an electromagnetic relay the armature is pulled by a magnetic force only. There is no
electrical connection between the coil of a relay and the switching contacts of the relay. If
there are more than one contact they all are electrically isolated from each other by
mounting them on insulating plates and washers. Hence they can be wired to control
different circuits independently.
Some of the popular contacts forms are described below:
1. Electromagnetic relay
2. Power Relay.
3. Time Delay Relay.
4. Latching Relay.
5. Crystal Can Relay.
6. Co-axial Relay.
1. Electromagnetic relay:
An electromagnetic relay in its simplest form consists of a coil, a DC current passing
through which produces a magnetic field. This magnetic field attracts an armature, which
88. in turn operates the contacts. Normally open contacts close and normally closed contacts
open. Electromagnetic relays are made in a large variety of contacts forms.
2. Power relays:
Power relays are multi-pole heavy duty lapper type relays that are capable of switching
resistive loads of upto 25amp.. These relays are widely used for a variety of industrial
application like control of fractional horse power motors, solenoids, heating elements and
so on. These relays usually have button like silver alloy contacts and the contact welding
due to heavy in rush current is avoided by wiping action of the contacts to quench the arc
during high voltage DC switching thus avoiding the contact welding.
3. Time Delay Relay:
A time delay relay is the one in which there is a desired amount of time delay between
the application of the actuating signal and operation of the load switching devices.
4. Latching Relay:
In a Latching Relay, the relay contacts remain in the last energized position even after
removal of signal in the relay control circuit. The contacts are held in the last relay-
energized position after removal of energisation either electrically or magnetically. The
contacts can be released to the normal position electrically or mechanically.
89. 5. Crystal Can Relay:
They are so called, as they resemble quartz crystal in external shapes. These are high
performance hermetically sealed miniature or sub-miniature relay widely used in
aerospace and military application. These relays usually have gold plated contacts and
thus have extremely low contact resistance. Due to low moment of inertia of the armature
and also due to statically and dynamically balanced nature of armature, these relays
switch quite reliably even under extreme condition of shock and vibration.
6. Co-axial Relay:
A Co-axial Relay has two basic parts, an actuator which is nothing but some kind of a
coil and a cavity, housing the relay contacts. The co-axial relay are extensively used for
radio frequency switching operations of equipment