You are on page 1of 66

Jordan University of Science and Technology

Electrical Engineering Department

Graduation Project
EE 592

Car's Blind-Spot Collision Avoidance


System using Ultrasonic Sensors and
PIC Microcontroller

Prepared By:
Rami Moh'd Zaghal

ID # 20010024035
E-mail: electromeo@just.edu.jo

January 2007

Supervisor:
Bassam El-Asir, Assoc. Prof.
To my loving parents

You are all the reasons I am what I am…

To Richard Bandler

You made up NLP… It changed my life!

1
Acknowledgments

First, I want to thank Dr. Bassam El-Asir for supervising my graduation project. His continuous
support and consultation provided great help during the progress of the project. He has not only been
an excellent teacher and a caring father, but also a long-lasting mentor to me… and he will remain…

I also want to thank Jordan University of Science and Technology for completely funding my
project. Without their funding, none of this could have been accomplished.

Finally, my special thanks and gratitude go to all the people on the Internet (EDAboard,
MicroChip Forum, and MELabs PICBASIC Forums) who answered my technical questions and
provided invaluable information without even knowing me.

2
Abstract

The Blind-Spot collision voidance system is an integrated automobile system designed to assist
drivers when changing lanes. On busy highways, changing lanes can be very hazardous. There is
region called “blind spot” which is a problem for every car driver since it is not covered by the
driver’s mirrors. Relying solely on the mirrors while changing lane can lead to a collision with
another vehicle.

It is proposed to implement the collision avoidance system to address these problems and provide
a cost-effective solution that eases the process of changing lanes. The system employs ultrasonic
sensors for the detection of objects in the blind spot. The sensors are mounted to car's left and right
bumpers and the distance from the bumper of the automobile to another car is continuously updated
to the driver on an LCD display located in the cabin of the automobile. A PIC microcontroller is
used to control the sensors and the LCD.

3
Contents
Acknowledgments --------------------------------------------------------------------------------------------------------------------- 2
Abstract ------------------------------------------------------------------------------------------------------------------------------------ 3
Contents ----------------------------------------------------------------------------------------------------------------------------------- 4
Chapter 1: Introduction ---------------------------------------------------------------------------------------- 6
1.1 The Modern Car ---------------------------------------------------------------------------------------------------------- 6
1.1.1 Present and Future Car Technologies Overview -----------------------------------------------6
1.1.2 The Parking Space Finder Service-----------------------------------------------------------------7
1.1.3 Parking Assistant Systems --------------------------------------------------------------------------7
1.1.4 No-Hands Parking System--------------------------------------------------------------------------8
1.2 Blind-Spot Detection System----------------------------------------------------------------------------------------- 9
1.3.1 System Overview -------------------------------------------------------------------------------------9
1.3.2 Features and Benefits ------------------------------------------------------------------------------ 11
1.3.3 Technical Specifications--------------------------------------------------------------------------- 11
1.4 Project Objectives Summary --------------------------------------------------------------------------------------- 11
Chapter 2: Ultrasonic Waves and Sensors------------------------------------------------------------------12
2.1 Introduction to Acoustics and Ultrasonics-------------------------------------------------------------------- 12
2.1.1 Sound Propagation --------------------------------------------------------------------------------- 12
2.1.2 Sound Waves properties--------------------------------------------------------------------------- 13
2.1.2.1 Amplitude and Frequency ------------------------------------------------------------------ 13
2.1.2.2 Wavelength and Attenuation--------------------------------------------------------------- 13
2.1.2.3 Speed of Propagation ------------------------------------------------------------------------ 15
2.2 Ultrasonic Sensors------------------------------------------------------------------------------------------------------ 15
2.2.1 Types of Ultrasonic Sensors ---------------------------------------------------------------------- 15
2.2.1.1 Magnetostrictive Ultrasonic Sensors ------------------------------------------------------ 16
2.2.1.2 Piezoelectric Ultrasonic Sensors ----------------------------------------------------------- 16
2.2.2 Pro-Wave 40 kHz Piezoelectric Ultrasonic Sensors------------------------------------------ 16
2.3 Sensor Radiation Pattern--------------------------------------------------------------------------------------------- 18
2.3.1 Transmitter Sensor Excitation -------------------------------------------------------------------- 19
2.4 How Far The Sensor Could Reach? ----------------------------------------------------------------------------- 20
2.5 Sensor Equivalent Circuit ------------------------------------------------------------------------------------------- 21
2.6 Environmental Factors and Sensors ----------------------------------------------------------------------------- 23
2.7 Applications of Ultrasonic Sensors ------------------------------------------------------------------------------ 24
2.7.1 Special Applications--------------------------------------------------------------------------------- 25
Chapter 3: Microcontrollers ----------------------------------------------------------------------------------26
3.1 Introduction -------------------------------------------------------------------------------------------------------------- 26
3.1.1 What is a Microcontroller? ----------------------------------------------------------------------- 26
3.1.2 MicroChip PIC Microcontrollers---------------------------------------------------------------- 28
3.2 The PIC16F877A Microcontroller------------------------------------------------------------------------------- 29
3.2.1 PIC16F87X → PIC16F87XA Migration------------------------------------------------------- 29
3.2.2 PIC16F877A Hardware and Features ---------------------------------------------------------- 29
3.2.3 PIC16F877A Pin-out Description --------------------------------------------------------------- 30
3.3 PIC16F877A Subsystems in Use --------------------------------------------------------------------------------- 32
3.3.1 I/O Ports --------------------------------------------------------------------------------------------- 32
3.3.2 Timer1 ------------------------------------------------------------------------------------------------ 33
3.3.3 Comparator Module ------------------------------------------------------------------------------- 34
3.3.4 Comparator's Voltage Reference Module ------------------------------------------------------ 36

4
Chapter 4: Ultrasonic Ranging Systems --------------------------------------------------------------------37
4.1 Overview of Echo Ranging ----------------------------------------------------------------------------------------- 37
4.2 Pro-Wave Sonar Ranging Module ------------------------------------------------------------------------------- 38
4.3 Distance Calculation using the Microcontroller ------------------------------------------------------------ 40
Chapter 5: Design Details and Circuit Explanation ------------------------------------------------------41
5.1 The Overall System ---------------------------------------------------------------------------------------------------- 41
5.1.1 System Block Diagram ---------------------------------------------------------------------------- 41
5.1.2 System Circuit Schematic ------------------------------------------------------------------------- 42
5.1.3 Transmitter-Receiver Separation ---------------------------------------------------------------- 43
5.2 The Transmitter --------------------------------------------------------------------------------------------------------- 43
5.2.1 Design Explanation -------------------------------------------------------------------------------- 43
5.2.2 Simulation Results---------------------------------------------------------------------------------- 45
5.3 The Receiver ------------------------------------------------------------------------------------------------------------- 45
5.3.1 Design Explanation -------------------------------------------------------------------------------- 45
5.3.2 Simulation Results---------------------------------------------------------------------------------- 47
5.4 The Microcontroller --------------------------------------------------------------------------------------------------- 49
5.4.1 Biasing the PIC-------------------------------------------------------------------------------------- 49
5.4.2 Resetting the PIC ----------------------------------------------------------------------------------- 50
5.4.3 PIC Clock Frequency ------------------------------------------------------------------------------ 50
5.4.4 PIC Ports and Pins --------------------------------------------------------------------------------- 50
5.5 The Switches ------------------------------------------------------------------------------------------------------------- 50
5.5.1 The Manual SPDT Switch------------------------------------------------------------------------ 50
5.5.2 IC Electronic Switch ------------------------------------------------------------------------------- 50
5.6 The Alphanumeric LCD Module -------------------------------------------------------------------------------- 51
Chapter 6: PIC Programming and Interfacing -------------------------------------------------------------53
6.1 Programming Language --------------------------------------------------------------------------------------------- 53
6.2 PIC Programmer-------------------------------------------------------------------------------------------------------- 53
6.3 PIC Program Code----------------------------------------------------------------------------------------------------- 54
6.3.1 Code Flow ------------------------------------------------------------------------------------------- 54
6.3.2 Code Analysis --------------------------------------------------------------------------------------- 56
Chapter 7: Conclusions ----------------------------------------------------------------------------------------59
7.1 Challenges----------------------------------------------------------------------------------------------------------------- 59
7.2 Future Work-------------------------------------------------------------------------------------------------------------- 59
7.3 Recommendations ----------------------------------------------------------------------------------------------------- 60
7.4 Final Comments -------------------------------------------------------------------------------------------------------- 60
References and Readings --------------------------------------------------------------------------------------61
Web Resources --------------------------------------------------------------------------------------------------62
Appendix A ------------------------------------------------------------------------------------------------------63
List of Components Used in the Project --------------------------------------------------------------------------------- 63
Appendix B ------------------------------------------------------------------------------------------------------64
Sensors and Modules Purchase Order ------------------------------------------------------------------------------------ 64
Appendix C ------------------------------------------------------------------------------------------------------65
Selected Data Sheets------------------------------------------------------------------------------------------------------------- 65

5
Chapter 1: Introduction

1.1 The Modern Car

1.1.1 Present and Future Car Technologies Overview

As the technology advances day-after-day, cars manufacturers and developers provide us with
more sophisticated, high technology cars and vehicles. We are living in the smart car era. Figure 1.1
illustrates features available in a typical modern car. This car utilizes an engine control system that
optimizes performance and fuel combustion, a system that detects collisions and activate the airbags
in the event of a crash, a system that regulates the interior climate based on passenger preferences
and exterior climate conditions, a system that controls the braking system for maximum efficiency, a
GPS navigation system to aid driver approach his destination in most efficient ways, and much
more. In fact, modern car - nowadays - may contain up to a 100 microprocessor and microcontroller
systems that together manifest all these features.

According to statistics, vehicle accidents cause 40,000 deaths and 3.5 million injuries annually. In
a given two-hour period, 1,600 accidents, 800 injuries, and 10 deaths will occur on U.S. highways.
The ultimate goal of cars manufacturers is to come up with safe, driver-friendly add-on systems to
ensure the safety of drivers, passengers and pedestrians. This may, in some way or another
minimizes car accidents and injuries.

Figure 1.1: Example of features of a modern car.

Safe driving support systems are starting to appear on vehicles including adaptive cruise control
(ACC) systems that maintain safe distance between you and the vehicle ahead, lane keep support
(LKS) systems that prevent drivers from departing lane, and pre-crash brake systems that
automatically tighten seat belts, activate air-bags and apply brakes if a collision cannot be avoided.
Ultrasonic, Millimeter-wave and Infrared Radars and image processing cameras are the environment
sensors with the key roles of recognizing and deciding what action to take in these safe driving
support systems. These sensors must incorporate intelligent recognition technologies considering
various complex external factors they might encounter in the real world: pedestrians darting out into
the road, other vehicles cutting-in in front of you, poor visibility due to adverse weather conditions,
etc. Symbols and signals in a car must provide the driver with accurate information about the car’s
status, and with clear warnings of critical situations. The visual aspect frequently dominates in
convenience functions. A graphical icon or symbol, for instance, may clearly demonstrate available
options and appropriate actions the driver can take to back into a parking space or to change into

6
new lane. In addition, acoustic (audible) signals can denote the start and finish of required steering,
backing-up and braking actions. Figure 1.2 illustrates ACC and LKS systems.

Figure 1.2: Examples of safe driving support systems.

1.1.2 The Parking Space Finder Service

This is one of the most promising (hot) schemes in the field. The objective of the PSF service is to
use feeds from cameras installed in parking lots in a metropolitan area and allow users to make
queries about the availability of parking spots at a particular location. The microcomputers used in
this service processes the webcam feed and recognize whether the parking spots are empty or full.
Users specify a destination and constraints of their desired spot. The PSF service returns the driving
directions (using the Yahoo Maps service) to the empty parking spot that satisfies the constraints and
is the nearest to their destination.

1.1.3 Parking Assistant Systems

With increasing traffic density, especially in urban areas, parking can be a tricky maneuver and
an error can be costly, in the event of contact with other parked cars or hidden obstacles. Such
accident repairs are more and more frequent and expensive. Drivers can prevent such costly, time
consuming and stressful situations by selecting an Ultrasonic Park Assist (UPA) system when buying
a new vehicle or installing any of the commercially available kits as post-equipment, both of which
cost less than the average accident repair.

UPA is available for rear applications using two to six sensors mounted discreetly behind the rear
bumper or a combined front and rear system using eight to twelve sensors. Figure 1.3 shows a typical
four-sensor reverse parking aid. Figure 1.4 shows - from three different views - how the system is
installed and highlights the range covered by the three sensors. This system provides a visual or
acoustic warning, which alerts the driver of the presence of, and distance to any obstacles to the rear
or front of the vehicle. Various display and audio options are available.

7
Figure 1.3: Rear-bumper sensors (Blue) used to detect the distance from behind cars and walls.

Figure 1.4: Installation diagram and sensing range of a 3-sensor parking assistant.

1.1.4 No-Hands Parking System

Also referred to as “Autonomous Parallel


Parking System”. It is very similar to the well-known
aircraft's auto-pilot system. It helps drivers park their
cars in tight spaces between other cars along the
street (parallel parking). This system would be an
option (although probably not a cheap one!) that a
car buyer could purchase with a new car in the very
soon future. Figure 1.5 demonstrates the operation of
the No-Hands Parking System.

Although not yet applied to real-life cars, the


same idea is applied in Robot Homing Systems,
where a pre-programmed autonomous robot moves
in a prescribed path to reach its final destination with
an intelligent capability to adjust its route in case
some obstacle "popped-up" and encountered its way.

However, my project is concerned only in one of


safe driving support systems, namely, the Blind-Spot
Collision Avoidance System. The next section will
deal in-detail with this system.

Figure 1.5: Autonomous Parallel Parking System.

8
1.2 Blind-Spot Detection System
1.3.1 System Overview

It is every driver's nightmare: you change lanes suddenly, glancing in the rearview mirror without
looking over your shoulder... and you merge directly into a car hidden in one of your car's blind
spots. Yes, that is true. Every car has a blind spot; the area behind the car where cannot be seen from
driver seat. According to recent statistics, more than 800,000 vehicles are involved in lane-change
blind-spot collisions annually. Furthermore, the U.S. National Highway Traffic Safety
Administration says that "lane change situations" are involved in 4 to 10 percent of all car crashes.
So, we are talking about a serious problem here!

To solve this problem and maintain car's safety, the driver must make sure that the blind-spots of
the vehicle are clear before he attempts to change lanes. My design goal is to implement a system
that would detect objects present within the blind-spot, on either side of the vehicle (left/right), and
appropriately warn the driver if the turn signal was on. The warning mechanism can be audio
warning by a buzzer, or beeper. In addition, we wanted to display the distance measurement of the
object present in the blind-spot on an LCD. The system will detect the presence of vehicles within the
detection zone, as shown in Figure 1.6 by use of sensors. The detection zone is fixed. The zone
extends from one to three and a half meters to the side of the vehicle to allow for traffic in the
adjacent lane of traffic. The zone does not extend more than two meters back from the rear of the
car. Objects detected will not be limited to cars, as vehicles such as motorcycles will be present in
some situations. Sensors employed in design are so sensitive that they ensure the detection of an
object the size of a pole or broom's handle!

Figure 1.6: Blind-Spot detection region.

9
During initial design stages, various design alternatives were explored. The Blind Spot Detection
system can be realized in two ways:

Scheme Alternative 1: Always On

The first scheme involves continuous monitoring of the rear blind spots on both sides of the
vehicle. When a vehicle is present in either blind spot, for example, an overtaking vehicle, the driver
is alerted to this potential hazard by a visible icon displayed in the door rear view mirror or a
warning buzzer goes off when the distance becomes less than certain critical value to warn the driver
of a possible collision.

Scheme Alternative 2: Instant On

The second scheme is illustrated in figure 1.7. When the driver gives the turn signal for a lane
change to either left or right side, vibroactuators mounted on the wheel actuate the related sensor
(left or right). The system uses microcontrollers to calculate the distance and indicate whether the car
can turn left or right. The driver can be warned by means similar to those in scheme 1. I chosen this
scheme over the first one because it saves power (only one sensor is activated) and electronic
circuitry (the timer, transmitter and receiver can be shared between the two sensors).

Figure 1.7: Functional Block Diagram of the Blind-spot Detection System (Scheme 2).

One sensor or array of sensors

During my initial research to find the best possible sensor for this application, I considered
whether to get one sensor or an array of sensors. I had initially thought that we would require an
array of sensors to cover all the detection region of Figure 1.6. Later on, I found one sensor that
covered the entire detection region. Hence, at the end, I decided to go for one sensor since it also
made controlling it much easier compared to controlling an array of sensors. Details on sensors
radiation patterns, beam width and coverage area will be explained later in Section 2.3.

10
1.3.2 Features and Benefits

• The device will warn the driver of the presence of an object within the blind spot of the
vehicle when the driver gives the turn signal for a lane change (Scheme 2).
• The system will provide measurements of the object’s distance relative to the vehicle to the
driver.
• The system will decrease the probability of an accident occurring due to any reason related
changing lanes.
• The system will help the driver focus on road by taking care of his blind spot region.
• The device will only notify the driver when the turn signal is activated (Scheme 2).
• The device should withstand typical weather conditions.
• The device will not significantly alter the outward appearance of the vehicle.

1.3.3 Technical Specifications

Operating voltage: 12 V (from car's battery).


Operating frequency: 40 kHz.
Range: 25 to 225 cm.
Resolution: 1 mm.
Microcontroller clock (speed): 20 MHz.
Wide operating temperature range.

1.4 Project Objectives Summary:


Building a reliable, accurate, robust ultrasonic blind-spot collision warning system.

Having sufficient number of sensors and ranging modules (ICs) available at the beginning of
summer course.

Operating and evaluating various types of ultrasonic sensors, for research's sake.

Building a high-speed, fast-response system by minimizing stages delays and optimizing


microcontroller's software code.

Reducing the number of sensors used by replacing transmitter-receiver pair with a single
transceiver.

Reducing the power consumption of the overall system to minimum.

Implementing the final system using PCB technology.

Reducing the number of used microcontrollers to minimum.

Designing a compact system with minimum size (area).

Installing and testing the system board and sensors on a miniature remote-controlled car.

Not exceeding the available funding budget (low-cost system).

11
Chapter 2: Ultrasonic Waves and Sensors

There are several ways to measure distance without contact. Some products have infrared light
emitters and receivers that determine an object’s distance by implementing the optical triangulation
method. Other devices have laser-based systems that increase accuracy and precision. For electrically
conductive metal objects, the eddy current method is an option, and capacitive sensors that are
independent of the metal used in the measured objects can be used. I decided to use ultrasonic
sensors. This chapter discusses ultrasonic waves and sensors with details.

2.1 Introduction to Acoustics and Ultrasonics

Ultrasonics is the science of sound waves above the limits of human audibility. The frequency of
a sound wave determines its tone or pitch. Low frequencies produce low or bass tones. High
frequencies produce high or treble tones. Ultrasound is a sound with a pitch so high that it can not be
heard by the human ear. Frequencies above 18 kHz are usually considered to be ultrasonic. The
frequencies used for ultrasonic cleaning range from 20,000 cycles per second or kilohertz to over
100,000 kHz. Although ultrasound behaves in a similar manner to audible sound, it has a much
shorter wavelength. This means it can be reflected off very small surfaces such as defects inside
materials. This very property makes ultrasound useful for nondestructive testing of materials, and
hence can be used in distance measurement systems.

The Acoustic Spectrum in Figure 2.1


breaks down sound into 3 ranges of
frequencies. The Ultrasonic Range is then
broken down further into three subsections. I
am interested in the frequency band (20-100
kHz) as the operating frequency is 40 kHz.

Figure 2.1: Acoustic Spectrum.

2.1.1 Sound Propagation

In order to easily illustrate the generation and propagation of sound waves, I'll make use of the
resemblance of sound waves propagation through transmission media and mechanical waves
traveling through a spring as depicted in Figure 2.2.

The source of the sound in the model is at the left. The compression generated by the sound
source as it moves propagates down the length of the spring as each adjacent coil of the spring pushes
against its neighbor. It is important to note that, although the wave travels from one end of the spring
to the other, the individual coils remain in their same relative positions, being displaced first one way
and then the other as the sound wave passes. As a result, each coil is first part of a compression as it
is pushed toward the next coil and then part of a rarefaction as it recedes from the adjacent coil. In
much the same way, any point in a sound conducting medium is alternately subjected to
compression and then rarefaction. At a point in the area of a compression, the pressure in the
medium is positive (as indicated by the meter under the spring). At a point in the area of a
rarefaction, the pressure in the medium is negative (as indicated by the meter under the spring).

12
Figure 2.2: The Nature of Sound Waves.

2.1.2 Sound Waves properties

2.1.2.1 Amplitude and Frequency

Amplitude is very important property of sound waves. The illustrations below in Figure 2.3
demonstrate amplitude and frequency using the spring model introduced earlier. If “A” is the
reference sound wave, “B” with less displacement of the media (less intense compression and
rarefaction) as the wave front passes, represents a sound wave of less amplitude or “loudness”. “C”
represents a sound wave of higher frequency indicated by more wave fronts passing a given point
within a given period of time.

Figure 2.3: Illustration of


frequency and amplitude
properties of sound waves.

2.1.2.2 Wavelength and Attenuation

The wavelength of sound changes as a function of both speed of sound and frequency, as shown
by the well-known expression:

13
As the sound travels, the amplitude of the sound pressure is reduced due to friction losses in the
transmission medium. The attenuation (also known as absorption) of sound in air increases as the
frequency increases, and at any given frequency the attenuation varies as a function of humidity. The
value of humidity that produces the maximum attenuation is not the same for all frequencies. For
example, above 125 kHz the maximum attenuation occurs at 100% relative humidity; however, at 40
kHz the maximum attenuation occurs at 50% relative humidity.

Since an ultrasonic sensor usually is required to operate at all possible humidities, target range
calculations should use the largest value of attenuation. A good estimate for the maximum
attenuation in air at room temperature over all humidities for frequencies up to 50 kHz is given by:

For frequencies between 50 kHz and 300 kHz, the maximum attenuation over all humidities is:

I will take the first equation into account when calculation maximum detectable distance as the
nominal operating frequency is 40 kHz. Substituting 40 in the first equation gives:

α(40) = 0.4 dB/ft = 0.1886 dB/m

This value will be used in Section 2.4 in some important calculations. Figure 2.4 depicts the
relation between sound waves absorption and frequency. Calculating the attenuation at 40 kHz using
the curve gives the same result as the equation.

Figure 2.4: Sound Waves Absorption (Attenuation) due to distance traveled.

14
2.1.2.3 Speed of Propagation

The speed of sound waves propagation depends on many factors including temperature and the
nature of the medium itself (gas type). For an ideal gas, the speed of sound is mainly a function of
temperature. At 0° C, the speed of sound is 13,044 in /s (332 m/s). At other temperatures, the speed
is given by:

C= γ×R×T

Where:
C = Speed of sound in meters per second
γ = Ratio of specific heats.
R = Gas constant.
T = Absolute temperature (Kelvin), where 0˚C = 273.16 K

For dry air (as in my case):


γ = 1.4 (non-dimensional)
R = 286.9 N.m/(kg.K)

Therefore, the speed of sound at room temperature (22˚C) is:


C = 1.4 × (22 + 273.16) × 286.9 = 344.31 meters per second (m/s)
This calculated value will be used in distance measurement formula in later chapter.

2.2 Ultrasonic Sensors


A transducer or sensor, by definition, is any device that converts one form of energy to another.
An ultrasonic transducer converts electrical energy to mechanical energy, in the form of sound, and
vice versa. When operating as transmitters, ultrasonic transducers transform electrical energy into
acoustic energy that propagates through a medium, which is usually air or water. When operating as
receivers, they transform the acoustical energy into electrical energy. The main components of
ultrasonic sensors are the active element, backing, and wear plate.

The active element can be piezo- or ferro-electric material. The most commonly used materials
are polarized ceramics, which can be cut in a variety of manners to produce different wave modes.
Recently, new materials such as piezo polymers and composites are also being employed for
applications where they provide benefit to transducer and system performance.

The operating frequency of an ultrasonic transducer, f, is predetermined by mechanical design. It


should be selected after considering a number of factors such as transducer size, measurement
resolution, background noise and attenuation, and the range to the receiving transducer.

2.2.1 Types of Ultrasonic Sensors

The variations of the employed active element material give rise to two general types of ultrasonic
transducers in use today: Magnetostrictive and Piezoelectric.

15
2.2.1.1 Magnetostrictive Ultrasonic Sensors

Magnetostrictive transducers (also known as Ferroelectric transducers) utilize the principle of


magnetostriction in which certain materials expand and contract when placed in an alternating
magnetic field.

Alternating electrical energy from the ultrasonic generator is first converted into an alternating
magnetic field through the use of a coil of wire. The alternating magnetic field is then used to induce
mechanical vibrations at the ultrasonic frequency in strips of nickel or other magnetostrictive
material which are attached to the surface to be vibrated. Because magnetostrictive materials behave
identically to a magnetic field of either polarity, the frequency of the electrical energy applied to the
transducer is ½ of the desired output frequency. Magnetostrictive transducers were first to supply a
robust source of ultrasonic vibrations for high power applications such as ultrasonic cleaning.

Because of inherent mechanical constraints on the physical size of the hardware as well as
electrical and magnetic complications, high power magnetostrictive transducers seldom operate at
frequencies much above 20 kHz. Piezoelectric transducers, on the other hand, can easily operate well
into the megahertz range.

2.2.1.2 Piezoelectric Ultrasonic Sensors

Piezoelectric ultrasonic sensors are known for what are called the piezoelectric and reverse
piezoelectric effects. The piezoelectric effect causes a crystal to produce an electrical potential when
it is subjected to mechanical vibration. In contrast, the reverse piezoelectric effect causes the crystal
to produce vibration when it is placed in an electric field. Of piezoelectric materials, Rochelle salt
and quartz have long been known as single-crystal piezoelectric substances. However, these
substances have had a relatively limited application range chiefly because of the poor crystal stability
of Rochelle salt and the limited degree of freedom in the characteristics of quartz. Later, barium
titanate (BaTiO3), a piezoelectric ceramic, was introduced for applications in ultrasonic transducers,
mainly for fish finders. More recently, a lead titanate, lead zirconate system (PbTiO3.PbZrO3)
appeared, which has electromechanical transformation efficiency and stability (including
temperature characteristics) far superior to existing substances. It has dramatically broadened the
application range of piezoelectric ceramics.

Magnetostrictive transducers are generally less efficient than their piezoelectric counterparts are.
This is due primarily to the fact that the magnetostrictive transducer requires a dual energy
conversion from electrical to magnetic and then from magnetic to mechanical. Some efficiency is lost
in each conversion. Hysteresis effects also detract from the efficiency of the magnetostrictive
transducer.

I am willing to use piezoelectric transducers in my project. As a result, all subsequent discussion


and analysis is concerned only with piezoelectric ceramic ultrasonic transducers.

2.2.2 Pro-Wave 40 kHz Piezoelectric Ultrasonic Sensors

The most important part of this project is to choose and buy necessary sensors. Unfortunately,
their availability is limited in the Jordanian market. I spent lot of time searching for suitable sensors
that can be shipped with the limited quantity we need. That was a quite difficult task. Here are all the
cited manufacturers:
1. Mobicon Electronic Components.
2. MuRata Corp.
16
3. PANASONIC.
4. Sanwa.
5. Pro-Wave Electronics Corp.
6. SensComp.
7. Quantelec.
8. KOBITONE.
9. Sencera and Kwang Hwa Elect. Material.

Pro-Wave Electronics Corp. provides various sensor solutions for all applications (some shown in
Figure 2.5) and they were ready to ship us the quantity we want (refer to Appendix: B for more
details) by their middle east distributor, Farnell.

Ultrasonic piezoelectric ceramic transducers come in different types. They are:


• Open-type Transmitter.
• Open-type Receiver.
• Open-type Transceiver.
• Enclosed-type Transceiver.

The “open” type ultrasonic transducer design exposes the piezo bender bonded with a metal
conical cone behind a protective screen. The “enclosed” type transducer design has the piezo bender
mounted directly on the underside of the top of the case which is then machined to resonant at the
desired frequency. The “PT and EP” type transducer has more internal damper for minimizing
“ringing”, which usually operates as a transceiver, oscillating in a short period and then switching to
receiving mode. The later type is used in my project and the maximum ringing duration plays an
essential role in determining the minimum measurable distance by the sensor and the system.

When compared to the enclosed transducer, the open type receiver will develop more electrical
output at a given sound pressure level (high sensitivity) and exhibit less reduction in output as the
operating frequency deviates from normal resonant frequency (greater bandwidth). The open type
transmitter will produce more output for a specific drive level (more efficient). The enclosed type
transducer is designed for very dusty or outdoor applications. The face of the transducer must be kept
clean and free of damage to prevent losses.

Pro-Wave and other manufacturer provide different Housing Materials as well. This include:
• Natural Aluminum Housing (Silver Color).
• White Painted Plastic Housing.
• Black Aluminum Housing.
• Black Painted Plastic Housing.

Figure 2.5: Various 40 kHz piezoelectric ultrasonic sensors manufactured by Pro-Wave Corp.

17
2.3 Sensor Radiation Pattern
The acoustic radiation pattern, or beam pattern, is the relative sensitivity of a transducer as a
function of spatial angle. This pattern is determined by factors such as the frequency of operation and
the size, shape and acoustic phase characteristics of the vibrating surface. The beam patterns of
transducers are reciprocal, which means that the beam will be the same whether the transducer is
used as a transmitter or as a receiver.

Transducers can be designed to radiate sound in many different types of patterns, from
omnidirectional to very narrow beams. For a transducer with a circular radiating surface vibrating in
phase, as is most commonly used in ultrasonic sensor applications, the narrowness of the beam
pattern is a function of the ratio of the diameter of the radiating surface to the wavelength of sound at
the operating frequency. The larger the diameter of the transducer as compared to a wavelength of
sound, the narrower the sound beam.

As can be seen in Figure 2.6, the sensor produces a narrow


conical beam and a number of secondary lobes of reduced
amplitude separated by nulls. Even though the beam is called
conical, it does not have straight sides and a flat top as the word
"conical" may imply.

The beam angle, alpha (α), is usually defined as the


measurement of the total angle where the sound pressure level of
the main beam has been reduced by 3 dB (half its peak value) on
both sides of the on-axis peak. However, the transducer still has
the sensitivity at greater angles, both in the main beam and in the
secondary lobes.

Figure 2.6: Directivity Plot.

When describing the beam patterns of transducers, two-dimensional plots are most commonly
used. They show the relative sensitivity of the transducer vs. angle in a single plane cut through the
three-dimensional beam pattern. For a symmetrical conical pattern, such as that shown in Figure
2.7a, a simple single two-dimensional plot will describe the entire three-dimensional pattern. Figure
2.7b shows an asymmetric beam pattern. Two perpendicular 2-D beam plots are required to fully
describe its directivity. One of which is along the narrow angle and the other is along the wide angle.

When using transducers, it is important to be aware that nearby unwanted targets that are beyond
the beam angle can inadvertently be detected, because the transducers are still sensitive at angles
greater than the beam angle. Some transducers used in sensing applications are specially designed to
minimize or eliminate the secondary lobes to avoid detecting unwanted targets. Narrow beam angle
systems are also less susceptible to background ultrasonic noise, and the systems will also operate
over a greater range.

18
(a) (b)
Figure 2.7: (a) Symmetric Beam Pattern for 400EP18A sensor. (b) Asymmetric Beam Pattern for 400EP14D sensor.

2.3.1 Transmitter Sensor Excitation

1. Continuous Excitation:

A sine wave drive should be used to minimize harmonics that may excite the transducer in an
overtone mode (vibrate at a multiple of the resonant frequency). For most models, the maximum
amplitude of the drive waveform varies between to 50 - 140 V p-p. The transmitter dissipation must be
limited to an effective or average level of 200 mW by reducing the duty cycle when the transmitter is
dissipating more than 200 mW. This type of excitation can be used in TX-RX pair system.

2. Pulse Excitation:

The ultrasonic transmitters may also be driven with a pulse waveform. Application of a DC Pulse
of 10 – 20 volts will cause the transducer to “ring” at the selected resonant frequency. The ultrasonic
output will be a damped ringing waveform as illustrated in Figure 2.8. This type of excitation can be
used in single-sensor (transceiver) system.

(a) (b)

Figure 2.8: (a) Pulse Wave Excitation of Sensor (b) A waveform: Periodic generates a short pulse that drives the
transmitter into conduction. B waveform: A 40 kHz short burst emitted by transducer.

19
2.4 How Far The Sensor Could Reach?
One of the most frequently asked questions is “How far the sensor could reach?”. This question
can be answered by a simple calculation that is based on the published specifications in the
Ultrasonic Ceramic Transducer Data Sheets. The basic procedure is to first determine the minimum
sound pressure level (S.P.L.) developed at the front end of the receiver for a specific transmitter
driving voltage and distance between the transmitter and receiver (transceiver has double distance
between reflect target). This SPL must then be converted “Pa” (Pascal) or “μbar” (microbar) units.
The sensitivity of the receiver must then be converted from a dB reference to an absolute mV/Pa or
μbar level present to obtain the final output.

Assume a 400PT160 transmitter is driven


at a level of 8.49 Vrms (12 Vp-p periodic pulses)
and a 400PT160 receiver is located 4.5 meters
from the transmitter and loaded with a
100KΩ resistor (loaded resistor value varies
receiver sensitivity, see Figure 2.9). 4.5 meter
separation between TX-RX is equal to 2.25
meters from the target/object in echo ranging.

Figure 2.9: 400PT160 Sensor's Sensitivity


Variation vs. Loaded Resistor.

Under the above conditions, I am going to perform the worst-case analysis to find the level of
output voltage from the receiver for maximum detectable distance in my design specification. Worst-
case analysis includes the minimum values of S.P.L. and sensitivity for transmitter and receiver,
respectively. Data sheet of 400PT160 (refer to Appendix: C) states the following:
1. Transmitting Sound Pressure Level at 40.0kKHz is 117dB min (0dB corresponding to
0.0002μbar per 10Vrms at 30cm).
2. Receiving Sensitivity at 40.0kHz is –65dB min (0dB = 1 volt/μbar).

Determining S.P.L. at the front end of Receiver


S.P.L. Gain for 8.49Vrms (12Vp-p) driving voltage = 20 × log (8.49V / 10V) = –1.422 dB
S.P.L. Reduction at 4.5 meters (maximum distance) = 20 × log (30 cm / 450 cm) = –23.522 dB
Wave absorption (refer to Figure 2.4) = 0.1886 dB/m × 4.5m = 0.8487 dB
The S.P.L. at 4.5 meters becomes = 117 – 1.422 – 23.522 – 0.8487 = 91.207 dB

Converting S.P.L. to μbar:


91.207 dB = 20 × log (X / 0.0002 μbar)
X = 7.268 μbar

Determining Receiver Sensitivity in Volts/μbar


Converting Sensitivity to Volt/μbar:
-65 dB = 20 × log (X / 1 Volt/μbar)
X = 0.56 mV/μbar
Voltage generated under 7.268 μbar = 0.56 × 7.268 = 4.07 mV

This calculated voltage developed under the assumed conditions is output voltage from the
receiver sensor for maximum measurable distance. Of course, it needs to be amplified before
processing. The actual voltage output will be varied depending on the environmental conditions and
absorption or reflection characteristics of target materials.

20
The previous two sections (2.3 and 2.4) revealed the comparative characteristics of piezo-electric
ultrasonic transducers. They are:

1. Transmitter Sound Pressure Level:


The higher, the better. (e.g. 118 dB S.P.L. is better than 100 dB)
2. Receiving Sensitivity:
The higher, the better. (e.g. -78 dB sensitivity is better than -85 dB)
3. Total Beam Angle:
Application dependent. The narrower the beam, the more directional the transducer.

A compromise (tradeoff) should be made when desiring high S.P.L, sensitivity and wide coverage
(wide beam). The designer, then, have to judge whether this receiving voltage level is large enough
for electronic processing.

2.5 Sensor Equivalent Circuit


The equivalent circuit of piezoelectric ceramic ultrasonic transducer is similar as the well-known
crystal, which is composed of a series branch of Ls, Cs and Rs and a parallel branch of Cd as shown in
Figure 2.10, where:

Cd: Clamping Capacity, measured at the frequency far away from resonant
frequency, which approximates to static capacity.

Cs: Equivalent Inductor = 1/(4π2 fs2 Cs)

Ls: Equivalent Capacity = Cd × [(fp2/fs2) – 1]

Rs: Real part of the impedance at resonant frequency

The values can be simply obtained from calculation of the impedance data.

Figure 2.10: Equivalent


circuit of a crystal.
400PT160 Open-Type Transceiver Equivalent Circuit:
A transducer of model 400PT160 has impedance characters shown as below.

Figure 2.11: 400SPT160 Sensor's Impedance/Phase Angle vs. Frequency.

fs = 39.0 kHz
fp = 40.6 kHz
Zfs = 900 Ω
21
θfs = -46.5°
Zfp = 1200 Ω
Cd = 2400 pF (From Data Sheet)

Impedance (Z∟θ) at resonant frequency of 39.0 kHz is (900∟-46.5°).


Cs = 2400 × [(40.62/39.02) – 1] = 188.17 pF
Ls = 1/[4 × 3.142 × 390002 × (188.17 × 10-12)] = 88.59 mH
Rs = 900 × cos (-46.5°) = 619.5 Ω

These values are used in the simulation of transmitter circuit (refer to Section 5.2 for results)

400ST120 Open-Type Transmitter Equivalent Circuit:


A transducer of model 400ST/R120 has impedance characters shown as below. The equivalent
circuit parameters of 400ST120 (Transmitter) are calculated below.

Figure 2.12: 400ST/R120 Sensor's Impedance/Phase Angle vs. Frequency.

fs = 40.25 kHz
fp = 41.50 kHz
Zfs = 510 Ω
θfs = -33.0°
Zfp = 1330 Ω
Cd = 2400 pF (From Data Sheet)

Impedance (Z∟θ) at resonant frequency of 40.25 kHz is (510∟-33.0°).


Cs = 2400 × [(41.502/40.252) – 1] = 151.38 pF
Ls = 1/[4 × 3.142 × 402502 × (151.38 × 10-12)] = 103.39 mH
Rs = 510 × cos (-33.0°) = 427.7 Ω

From Figures 2.11 and 2.12, one can infer that ultrasonic transmitter impedance characteristics
vary with operating frequency and temperature in complex manner that is different for each
construction. In general, for frequencies approximately 0.1 octave on either side of the resonant
frequency, the transmitter looks like a capacitor. The current through the transmitter will lead the
voltage developed across the transmitter by 90 degrees. As the resonant frequency is approached, the
voltage drop across the transmitter will decrease to a minimum at the resonant frequency (minimum
series impedance) and the current will increase proportionally. The phase lead to this current relative
to the voltage will decrease to zero near the resonant frequency and the transmitter will then appear
to be a pure resistance. As the frequency is increased above the resonant point, the current may now
22
lag the voltage by an increasing amount (maximum of 90 degrees) as the voltage across the
transmitter climbs to a peak, which is defined as the anti-resonant frequency. During this transition,
the transmitter appears to have an inductive characteristic.

2.6 Environmental Factors and Sensors


Since the sensors will be mounted outside the vehicle, they have to be such that they can
withstand the changes in the surrounding environment. Many environmental factors affect the
performance of an ultrasonic sensor such as temperature, humidity, atmospheric pressure, acoustic
interference, air turbulence and convection currents. Each of these factors is discussed briefly.

Temperature

Temperature is an important factor since it can negatively affect the performance of an ultrasonic
sensor. For example, the speed of the sound through air changes 0.18% for every Celsius degree. So
at a target distance of 1 meter, a 25°C change in air temperature throws off the reading by 4.5 cm.
However, most modern ultrasonic sensors have a built-in temperature compensator to solve this
problem, and I can use one of these sensors. Figure 2.13 Illustrates an ultrasonic transmitter and
receiver performance for wide temperature range.

Figure 2.13: 400ST/R120 Temperature characteristics:


(Left) Sensitivity Variation vs. Temperature (Right) SPL Variation vs. Temperature.

Air Turbulence and Convection Currents

A particular temperature problem is posed by convection currents that contain many bands of
varying temperature. If these bands pass between the sensor and the target, they will abruptly change
the speed of sound while present. No type of temperature compensation (either temperature
measurement or reference target) will provide complete high-resolution correction at all times under
these circumstances. In some applications it may be desirable to install shielding around the sound
beam to reduce or eliminate variations due to convection currents. Averaging the return times from a
number of echoes will also help reduce the random effect of convection currents. Users addressing
applications requiring high accuracy and resolution should evaluate these suggestions carefully.
Temperature variations and wind produce air turbulence that has various effects on the total
performance of any ultrasonic sensing system, causing bending and distortion of the sound waves.
The narrower the angle of the sound beam and the greater the distance to the target, the greater the
turbulence. Additional signal processing may be able to filter data under high turbulence conditions
to improve ranging information.

23
Atmospheric Pressure

Normal changes in atmospheric pressure will have little effect on measurement accuracy. Reliable
operation will deteriorates however, in areas of unusually low air pressure, approaching a vacuum.

Humidity

Humidity does not significantly affect the operation of an ultrasonic measuring system. Changes
in humidity do have a slight effect, however, on the absorption of sound. If the humidity produces
condensation, sensors designed to operate when wet must be used (enclosed-type). Since the used
ultrasonic sensor is required to operate almost at all possible humidity conditions, target range
calculations should use the largest value of attenuation.

Acoustic Interference

Special consideration must be given to environments that contain background noise in the
ultrasonic frequency spectrum. For example, air forced through a nozzle, such as air jets used for
cleaning machines, generates a whistling sound with harmonics in the ultrasonic range. When in
close proximity to a sensor, whether directed at the sensor or not, ultrasonic noise at or around the
sensor's frequency may affect system operation. Typically, the level of background noise is lower at
higher frequencies, and narrower beam angles work best in areas with a high ultrasonic background
noise level. Often a baffle around the noise source will eliminate the problem. Because each
application differs, testing for interference is suggested.

2.7 Applications of Ultrasonic Sensors


Ultrasonic sensors are not ideal and do have drawbacks. The emitted pulse has a nonideal cone
shape and it is not possible to discern between small objects, such as a broomstick, and large objects
such as a chair or wall for this reason as both will return an echo. Also, The broad ultrasonic beam
leads to inaccurate echoes. These drawbacks can be overcome by using multiple or rotating sensors.
Other disadvantages are there because ultrasonic sensors produce inaccurate measurements due to
acoustic drift in the open air. Moreover, The operating range becomes restricted when it is foggy.
The range is approx. 1.5 times the human vision.

Nonetheless, Ultrasonic Sensors found their way into industry and are used in a wide variety
of applications, such as:
• Car parking and reversing.
• Blind-spot detection.
• Pre-crash detection.
• Occupant position and motion sensing.
• Cruise control and collision avoidance.
• Remote control equipments.
• Range Finders.
• Automatic doors.
• Water (liquid) level measurements.
• Intrusion alarms.
• Tape measurements.
… And much more!
24
2.7.1 Special Applications

Ultrasonic Cleansing
All hermetically sealed and wash-proof components can be cleaned using standard aqueous and
solvent based cleaning methods. Units with tuning holes, open covers and other openings should not
be soaked or cleaned in an environment where the cleaning solution can penetrate the openings.
Exceptions are units that are designed for wash-through and are clearly marked or specified as such.
Ultrasonic cleaners use low frequencies (< 20kHz) and typically do not cause damage.

Robotics
Ultrasonic Sensors are the eyes by which Robots can see and find their paths. Ultrasonic Eyes or
Ultrasonic Vision is applied widely to various autonomous robots and in Robot Homing schemes.

Crane collision avoidance


In crane applications, the distance between traveling cranes running on the same tracks is
estimated by crane-operating staff. Accidents can often occur, particularly where cranes have to be
moved in restricted areas. At present, ultrasonic and microwave sensors are used.

25
Chapter 3: Microcontrollers

3.1 Introduction
The microcontroller is the intelligent part of the system and its most important component that
integrates the transmitter and receiver together. The microcontroller is a very common component in
modern electronics control systems. It consists of a processor, memory, input/output ports, timers,
PWM and analog to digital converter. This configuration facilitates the widespread of using
microcontrollers in many applications such as:

Engine management systems in automobiles.


Keyboard of a PC.
Electronic measurement instruments (such as digital multi-meters, frequency synthesizers, and
oscilloscopes).
Printers.
Mobile phones.
Televisions, radios, CD players, tape recording equipment.
Hearing aids.
Security alarm systems, fire alarm systems, and building services systems.
… And much more! As a matter of fact, we are living in the Microcontrollers era!

3.1.1 What is a Microcontroller?


Basically, a microcontroller is a device, which integrates a number of the components of a
microprocessor system onto a single microchip (System On-Chip, or SoC).
So a microcontroller combines onto the same microchip:
• The CPU core
• Memory (both ROM and RAM)
• Some parallel digital I/O

Most microcontrollers will also combine other devices such as:


• A timer module to allow the microcontroller to perform tasks for certain time periods.
• A serial I/O port to allow data to flow between the microcontroller and other devices such as
a PC or another microcontroller.
• An Analog to Digital Converter (ADC) to allow the microcontroller to accept analog input
data for processing.
• PWM, or formally pulse width modulation, creates a square wave with duty cycle and
frequency depending on user demand.

Figure 3.1 illustrates a typical microcontroller device and the different sub units integrated onto the
microcontroller microchip. Where the heart of the microcontroller is the CPU core.

26
Figure 3.1: A single chip microcontroller.

CPU Core in microcontroller


In the past this has traditionally been based on an 8-bit microprocessor unit. For example,
Motorola uses a basic 6800 microprocessor core in their 6805/6808 microcontroller devices. In
recent years, microcontrollers have been developed around specifically designed CPU cores. For
example, the 10-Bit Microchip PIC range of microcontrollers.

Memory in a microcontroller
The amount of memory contained within a microcontroller varies between different
microcontrollers. Some may not even have any integrated memory. However, most modern
microcontrollers will have integrated memory. The memory will be divided up into ROM and RAM,
with typically more ROM than RAM. Typically, the amount of ROM type memory will vary
between around 512 bytes and 4096 bytes, although nowadays we can see microcontrollers with
more ROM memory. ROM type memory is used to store the program code. ROM memory can be
classified into three types:
• ROM: memory is manufactured containing program that cannot be erased or programmed
so program code must be stable that’s why ROM is least expensive.
• EPROM (Erasable Programmable Read Only Memory): here we have Ceramic package
has quartz window. The microcontroller can be erased using an ultraviolet eraser and
reprogrammed many times typical erase times range between 5 and 30 minutes. EPROM is
the most expensive version of program memory due the high cost of the windowed ceramic
package.
• EEPROM (FLASH): Electrically Erasable Programmable Read Only Memory provides
the ultimate flexibility because it can be electrically erased by a programmer in just a few
seconds and reprogrammed. Devices such as the PIC16F77 and PIC16F877 use FLASH
program memory, and are denoted with an “F” in the part number.
The amount of RAM memory is usually somewhat smaller, typically ranging between 25 bytes to
4 Kbytes. RAM is used for data storage and stack management tasks. It is also used for register
stacks (as in the microchip PIC range of microcontrollers).

27
3.1.2 MicroChip PIC Microcontrollers

There is a large variety of microcontrollers on the market. Selection the most suitable
microcontroller was crucial and time-consuming. The most popular manufacturers are:
1. Micochip's PIC.
2. Atmel's AVR.
3. Intel's 80xx.
4. Motorola's MCxxx.
5. Cypress PSoC.

Most of them support more than one programming language, such as Assembly Language, Pascal, C
Language, and Basic Language. I went for Microchip's PIC microcontrollers.

Microchip provides solutions for the entire performance range of 8-bit and 16-bit
microcontrollers, with a powerful architecture, flexible memory technologies, comprehensive easy-
to-use development tools, complete technical documentation and post design-in support through a
global sales and distribution network. Benefits realized by selecting Microchip’s microcontroller
solutions are:

● Easy migration across product families.


● Low-risk product development and faster time to market.
● Lower total system cost.
● Excellent product support and programming services.
● Certified quality.
● Microchip is #1 in worldwide 8-bit microcontroller shipment serving 50000+ customers.

Figure 3.2 shows Microchip's PIC MCU and dsPIC families. In the early 1980s, the term PIC
stood for Peripheral Interface Controller. Microchip's microcontroller solutions come in different IC
packaging and pin numbers such as 8-, 14-, 18-, 28-, 40-, 64-, 68-, or 84-Pin IC.

Figure 3.2

Generally speaking, developing a PIC-based project takes only six easy steps:
1. Type in the program.
2. Assemble the program into a binary file.
3. Simulate the program and debug it.
4. Load the binary program into the PIC’s memory.
5. Wire up the circuit.
6. Switch on and test.
28
3.2 The PIC16F877A Microcontroller
From all Microchip's PICmicro products, I decided to use PIC16F877A in my project. Many
reasons stand behind that choice, most importantly the availability of its programmer device in the
lab. Others factors will be revealed in the following paragraphs.

3.2.1 PIC16F87X → PIC16F87XA Migration

This is the title of an application note released by Microchip. This document is intended to
describe the functional differences and the electrical specification differences present when migrating
from one device to the next. Simply put, PIC16F877A is a newer version of PIC16F877, which is
obsolete now. PIC16F877A is designed to be pin-to-pin, and functionally compatible with the
PIC16F877 product family. As a result, all information in PIC16F877 applies to PIC16F877A. Many
improvements and updates were added by Microchip in the migration from PIC16F877 to
PIC16F877A. To me, the most important are the new comparator and comparator voltage reference
modules in PIC16F877A.

3.2.2 PIC16F877A Hardware and Features

The hardware specification of the PIC16F877A is:


• The program memory is 8K Words
• RAM memory is 368 bytes.
• EEPROM is 256 bytes.
• Three kinds of timers.
• Analog Digital converter.
• Hardware PWM.
• Flash memory is used for PIC16F877A. So, the PIC programmer can easily rewrite the
program.

The PIC16F877A microcontroller core features are:


• High performance Reduced Instruction Simplified Computer (RISC) CPU.
• Only 35 single word instructions to learn.
• Operating speed: 20 MHz clock input.
• Up to “8 K X 14” words of FLASH Program memory.
• Up to “368 X 8” bytes of Data Memory (RAM).
• Up to “256 X 8” bytes of EEPROM Data Memory.
• Interrupt capability (up to 14 sources).
• Eight level hardware stack.
• Direct, indirect and relative addressing modes.
• Power-on Reset (POR).
• Power-up Timer (PWRT) and Oscillator Start-up Timer (OST).
• Watchdog Timer (WDT) with its own on-chip.
• RC oscillator for reliable operation.
• Programmable code protection.
• Power saving SLEEP mode.
• Selectable oscillator options.
• Low power, high speed CMOS FLASH/EEPROM technology.
• In-Circuit Serial Programming (ICSP) via two pins.
29
• Single 5V In-Circuit Serial Programming capability.
• In-Circuit Debugging (ICD) via two pins.
• Processor read/write access to program memory.
• Wide operating voltage range: 2.0V to 5.5V.
• High Sink/Source Current: 25mA.
• Commercial, Industrial and Extended temperature ranges.
• Low-power consumption:
1- < 0.6 mA typical @ 3V, 4 MHz
2- 20 μA typical @ 3V, 32 kHz
3- < 1μA typical standby current.

Figure 3.3 illustrates PIC16F877A's block diagram.

Figure 3.3: PIC16F877A block diagram.

3.2.3 PIC16F877A Pin-out Description

Figure 3.4 illustrates PIC16F877A's pin configuration. While Table 3.1 shows PIC16F877A's pin-
out configuration (description). every pin is based depends on: its name, its order on the chip, its type
(P-power, I-input, and O-output), Buffer type (ST-Schmitt trigger, TTL, CMOS), and brief
description. Every pin may be multiplexed with more than one input or output. Its state can be
controlled by defining the special register related to.

30
Figure 3.4: PIC16F877A pin configuration.

Pin Name DIP I/O/P Buffer Description


Pin# Type Type
OSC1/CLKIN 13 I ST/CMOS(4) Oscillator crystal input/external clock source input.
OSC2/CLKOUT 14 O — Oscillator crystal output. Connects to crystal or resonator in
crystal oscillator mode. In RC mode, OSC2 pin outputs CLKOUT
which has 1/4 the frequency of OSC1, and denotes the instruction
cycle rate.
MCLR/VPP 1 I/P ST Master Clear (Reset) input or programming voltage input. This
pin is an active low RESET to the device.
PORTA is a bi-directional I/O port.
RA0/AN0 2 I/O TTL RA0 can also be analog input0.
RA1/AN1 3 I/O TTL RA1 can also be analog input1.
RA2/AN2/VREF- 4 I/O TTL RA2 can also be analog input2 or negative analog reference
voltage.
RA3/AN3/VREF+ 5 I/O TTL RA3 can also be analog input3 or positive analog reference
voltage.
RA4/T0CKI 6 I/O ST RA4 can also be the clock input to the Timer0 timer/counter.
Output is open drain type.
RA5 can also be analog input4 or the slave select for the
RA5/SS/AN4 7 I/O TTL synchronous serial port.
PORTB is a bi-directional I/O port. PORTB can be software
programmed for internal weak pull-up on all inputs.
RB0/INT 33 I/O TTL/ST(1) RB0 can also be the external interrupt pin.
RB1 34 I/O TTL
RB2 35 I/O TTL
RB3/PGM 36 I/O TTL RB3 can also be the low voltage programming input.
RB4 37 I/O TTL Interrupt/on/change pin.
RB5 38 I/O TTL Interrupt/on/change pin.
RB6/PGC 39 I/O TTL/ST(2) Interrupt-on-change pin or In-Circuit Debugger pin. Serial
programming clock.
RB7/PGD 40 I/O TTL/ST(2) Interrupt-on-change pin or In-Circuit Debugger pin. Serial
programming data.

RC0/T1OSO/T1CKI 15 I/O ST RC0 can also be the Timer1 oscillator output or a Timer1 clock
input.
RC1/T1OSI/CCP2 16 I/O ST RC1 can also be the Timer1 oscillator input or Capture2
input/Compare2 output/PWM2 output.
RC2/CCP1 17 I/O ST RC2 can also be the Capture1 input/Compare1 output/PWM1
output.
RC3/SCK/SCL 18 I/O ST RC3 can also be the synchronous serial clock input/output for
both SPI and I2C modes.
RC4/SDI/SDA 23 I/O ST RC4 can also be the SPI Data In (SPI mode) or data I/O (I2C
mode).
RC5/SDO 24 I/O ST RC5 can also be the SPI Data Out (SPI mode).

RC6/TX/CK 25 I/O ST RC6 can also be the USART Asynchronous Transmit or


Synchronous Clock.
RC7/RX/DT 26 I/O ST RC7 can also be the USART Asynchronous Receive or
Synchronous Data.

31
Dip I/O/P Buffer
Pin Name Description
Pin# Type Type

RD0/PSP0 19 I/O ST/TTL(3)


RD1/PSP1 20 I/O ST/TTL(3)
RD2/PSP2 21 I/O ST/TTL(3)
PORTD is a bi-directional I/O port or parallel slave port when
RD3/PSP3 22 I/O ST/TTL(3) interfacing to a microprocessor bus.
RD4/PSP4 27 I/O ST/TTL(3)
RD5/PSP5 28 I/O ST/TTL(3)
RD6/PSP6 29 I/O ST/TTL(3)
RD7/PSP7 30 I/O ST/TTL(3)
PORTE is a bi-directional I/O port.
RE0/RD/AN5 8 I/O ST/TTL(3) RE0 can also be read control for the parallel slave port, or analog
input5.
RE1/WR/AN6 9 I/O ST/TTL(3) RE1 can also be write control for the parallel slave port, or analog
input6.
RE2/CS/AN7 10 I/O ST/TTL(3) RE2 can also be select control for the parallel slave port, or analog
input7.
VSS 12,31 P — Ground reference for logic and I/O pins.
VDD 11,32 P — Positive supply for logic and I/O pins.
NC — — These pins are not internally connected. These pins should be left
unconnected.

Table 3.1: PIC16F877A Pinout Configuration.


Legend:
I = input O = output I/O = input/output P = power
— = Not used TTL = TTL input ST = Schmitt Trigger input

* Notes:
1- This buffer is a Schmitt Trigger input when configured as an external interrupt.
2- This buffer is a Schmitt Trigger input when used in Serial Programming mode.
3- This buffer is a Schmitt Trigger input when configured as general purpose I/O and a TTL input when used in the
Parallel Slave Port mode (for interfacing to a microprocessor bus).
4- This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a CMOS input otherwise.

3.3 PIC16F877A Subsystems in Use


PIC16F877A contains several independent subsystems and modules for various applications. For
this project, I only used some of these subsystems. The employed modules are described in what
follows.

3.3.1 I/O Ports

The digital/analog I/O ports are the means by which the PIC microcontroller interfaces to
the environment. Usually, I/O tends to be grouped into byte wide ports (8 digital bits) that can be
configured as either input bits or output bits by defining the special register related to the port.
The PIC16F877A microcontroller ports are:
1. Port A: has 6 bits/pins.
2. Port B: has 8 bits/pins.
3. Port C: has 8 bits/pins.
4. Port D: has 8 bits/pins.
5. Port E: has 3 bits/pins.

32
3.3.2 Timer1

PIC16F877A has three timers Timer0, Timer1 and Timer2. Each one of these timers has its own
properties and specifications. All three timers can be used in the same time in one application or any
one can be used depending on the application requirement. After a thorough study of each timer, I
decided to use Time1 in my design.

The Timer1 module is a 16-bit timer/counter having the following features:


• Two 8-bit registers (TMR1H and TMR1L).
• Readable and writable
• 8-bit software programmable prescaler
• Internal or external clock select
• Interrupt on overflow from FFFFh to 0000h
• Edge select for external clock
• (TMR1H: TMR1L) increments from 0000h to FFFFh and rolls over to 0000h

Timer1 can operate in one of two modes: as a timer, or as a counter. The operating mode is
determined by the clock select bit, TMR1CS (T1CON<1>). In Timer mode, Timer1 increments
every instruction cycle. In Counter mode, it increments on every rising edge of the external clock
input. Timer1 can be enabled/disabled by setting/clearing control bit TMR1ON (T1CON<0>).
Register 3.1 shows the Timer1 control register.

Since Timer1 is a 16-bit timer, when the timer overflows, it reaches a count of 65535 (216–1).
Different prescaler ratios can also be attached to Timer1 allowing it to increment on every 1, 2, 4, or
8 instruction cycles. If 1:1 prescaler was assigned to it, this means that the Timer1 will increment on
every instruction cycle (FOSC/4). If 20 MHz crystal was used as clock:

FOSC/4 = 5 MHz
Increment = (5 MHz)-1 = 200 ns

This means that each count of Timer1 using 1:1 prescalar ratio and 20 MHz clock equals to 200
ns. In other words, Timer1 can count up to (200 ns × 65535) 13.107 ms. Table 3.2 includes Timer1
maximum timing and the equivalent measured distance for each prescalar ratio (using 20 MHz
clock). Thus, 1:1 prescalar ratio is suitable to my design.

Timer1
Prescaler Ratio Maximum Timing (ms) Equivalent Distance (m)
1:1 13.107 4.5088
1:2 26.214 9.0176
1:4 52.428 18.035
1:8 104.85 36.070

Table 3.2: Timer1 full time and equivalent distance for different prescaler ratios.

33
Register 3.1: Timer1 control register.

3.3.3 Comparator Module

The comparator module contains two analog comparators. The inputs to the comparators are
multiplexed with I/O port pins RA0 through RA3, while the outputs are multiplexed to pins RA3
and RA4. The on-chip Voltage Reference (described in the next section) can also be an input to the
comparators. The CMCON register (Register 3.2) controls the comparator input and output
multiplexors. A block diagram of the various comparator configurations is shown in Appendix C.

A single comparator is shown in Figure 3.5, along with the relationship between the analog input
levels and the digital output. When the analog input at VIN+ is less than the analog input VIN-, the
output of the comparator is a digital low level. When the analog input at VIN+ is greater than the
analog input VIN-, the output of the comparator is a digital high level. The shaded areas of the output
of the comparator in Figure 3.5 represent the uncertainty due to input offsets and response time.

34
Register 3.2: Comparator control register.

Figure 3.5: Comparator Operation.


35
3.3.4 Comparator's Voltage Reference Module

The comparator voltage reference generator is a 16-tap resistor ladder network that provides a
fixed voltage reference when the comparators are in mode ‘010’. A programmable register controls
the function of the reference generator. Register 3.3 lists the bit functions of the CVRCON register.

The comparator reference supply voltage (also referred to as CVRSRC) comes directly from VDD. It
should be noted, however, that the voltage at the top of the ladder is (CVRSRC – VSAT) where VSAT is
the saturation switch transistor. The output of the reference connected to the
RA2/AN2/CVREF/VREF- pin. This can be used as a simple D/A function by high impedance load is
used. The primary function is to provide a test reference generator function.

Register 3.3: Voltage reference control register.

For example, using the high range of the D/A, i.e.:

CVREF = (¼ × CVRSRC) + (VR3:VR0/32 × CVRSRC)

And assuming CVRSRC = 4.8 V (this means that VSAT = 0.2 V) gives:

For VR3:VR0 = 0110 → CVREF = 2.10 V


For VR3:VR0 = 0111 → CVREF = 2.25 V
For VR3:VR0 = 1000 → CVREF = 2.40 V
36
Chapter 4: Ultrasonic Ranging Systems

4.1 Overview of Echo Ranging


Ultrasonic ranging systems are used to determine the distance to an object by measuring the time
required for an ultrasonic wave to travel to the object and return to the source. This technique is
frequently referred to as “echo ranging”. Figure 4.1 illustrates the reflection principle. The transmitter
is designed to have low impedance at the resonant frequency to obtain high mechanical efficiency.
The receiver is constructed to maximize the impedance at the specified anti-resonant frequency to
provide high electrical efficiency.

The amplitude of the reflected wave is directly


proportional to how much surface is available on the
object for coherent reflection. Surface size, shape and
orientation (normal or oblique incidence), are major
factors contributing to the strength of the reflected
signal. Material composition of the object is a decisive
factor too. A part of the wave landing on the surface
of the material is reflected, while a part of the wave
penetrates the material and is eventually reflected of
any surface boundaries encountered while traveling
within the material (delayed reflection).
Figure 4.1: Reflection of ultrasonic waves is
used in distance measurements systems.

Any ranging system should contain a timer to estimate the Time-of-Flight (TOF), that is, the time
required for the ultrasonic wave to hit the target/object, reflect, and reach the receiver back. TOF is
equivalent to double the distance between the distance sensor and the target. This should be taken
into consideration.

The past few years witnessed an increased use of ultrasonic sensors in ranging and distance
measurement applications. This popularity made the manufacturers to extend their products to
include a complete ultrasonic system consisting of transmitter, receiver, and sensor. These ranging
modules became widely used by designers, since they save the efforts to design the transmitter and
receiver electronic circuits, and interface it to the sensor. The whole system is integrated into one
board using PCB technology. All what the user have to do is to connect the ranging module to MCU
(Microprocessor Control Unit) such as a microcontroller. The user's focus is more concentrated on
the programming of the microcontroller (task becomes more software oriented).

Commercial modules such as Devantech Sonic RangeFinder (SRF04, SRF08, and SRF10),
SensComp 6500 Ranging Module (Polaroid), and Pro-Wave Sonar Ranging Module (SRM400) are
available in the market. I chose Pro-Wave's Sonar Ranging Modules (SRM400) for my project.
Unfortunately, they have not arrived yet! This was a turning point in the progress of my project,
since I was forced to design my own transmitter and receiver sensor-compatible circuits.

37
4.2 Pro-Wave Sonar Ranging Module
Pro-Wave's Sonar Ranging Module (SRM400) in Figure 4.2 is being discussed in what follows:

The SRM400 is a sonar ranging module utilizing


our new developed Sonar Ranging IC, PW-0268,
which can work with all our PT or EP type
transducers. SRM400 provides as a shortcut to
develop car reversing systems or some other distance
measurement systems for design engineers who are
not very familiar with analog circuit and/or the
operation of ultrasonic transducers. By using this
module engineers can focus firstly on the other fields
of digital circuit and software designs as well as
some other mechanical issues. After first stage then
you can either design your own analog circuit based
on the module construction or consult with Figure 4.2: Pro-Waves' Sonar Ranging Module.
factory for making your own module for your
special needs.

Features:
Operating Voltage: 6 – 10Vdc single source
Operating Frequency: broadband output
ranging up to 250KHz
Built-in variable RC oscillator matching
transducers with different frequencies
High Gain Amplifier: varies with time over
32 steps
Integrated Band Pass Filter: reduces
external component count,
Bi-direction I/O Pin: simplifies the control
function for transmitting a pulse and
receiving an echo
An adjustable System Clock: enables the
control of, the number of pulses transmitted,
the slope of the variable gain amplifier, and
the pulse repetition rate
Board size: 27.9 * 18 mm (L*W)

Table 4.1: SMR400 Specifications.


SRM400 includes:
1. Module board
2. 400EP14D enclosed type transducer of asymmetrical beam patterns.
3. Detail electrical schematic

38
Figure 4.3: Electronic Circuit Diagram.

Figure 4.4: Waveforms and Operations of SRM400.

Waveforms at different test points:


Figure 3.7 (above) shows how the module works with transducer model 400EP14D against a
hard target of size of 20cmL×20cmW×1cmT at distance of 50cm.

39
4.3 Distance Calculation using the Microcontroller
The electrical parameter in this system is time and is proportional to the distance separating the
object from the source (car in my case). It is straightforward to trigger a timer (stopwatch) when the
ultrasonic burst is transmitted and stop the timer when the transmitted burst is received. The distance
traveled is related to time-of-flight and speed by the well-known relation:

Distance = (Time-of-Flight / 2) × Speed

Or using mathematical notation:

D = 0.5 × C × (T1 - T0)

Where:
D = Distance to Object
C = Speed of Sound in transmission medium
T0 = Time at which ultrasonic wave is transmitted
T1 = Time at which ultrasonic wave is received

PIC16F877A's Timer1 is used as a stopwatch. It was shown in Section 3.3.2 that Timer1 can be
incremented once every 200 nanoseconds. In Section 2.1.2.3, the speed of sound waves in dry air in
rooms temperature was found to be 344.31 meters per second. The value stored in the two 8-bit
registers of Timer1 represents the time-of-flight. Thus:

D(in mm) = ½ × Timer1 register value × 200 (ns) × 344310 (mm/s)

With some mathematical manipulations, the formula becomes:

TimerV alue
D(in mm) = Timer1 register value ÷ 29.04 (mm-1) ≈
29

This is the formula used in PIC16F877A to calculate distance in millimeters.

Instrument's Resolution is the smallest change in the measured value to which the instrument will
respond. Using the last formula to evaluate the distance produces a resolution of one millimeter for
the designed ranging system.

40
Chapter 5: Design Details and Circuit Explanation

5.1 The Overall System


The car's blind-spot collision avoidance system was described in Section 1.2 in terms of design
requirements, technical specifications, and general overview. This chapter deals with design details
and circuit schematic, and hardware implementation of the system. The most important advantage
of ultrasonic sensors will become evident. That is, their ease of interface to electronic circuitry
(digital and analog).

5.1.1 System Block Diagram

Unlike the simplified, functional block diagram of the blind-spot collision avoidance system
presented in Figure 1.7, the block diagram in Figure 5.1 is detailed gives a closer look to the system
details. As shown in the block diagram, the microcontroller is the brain of the system that controls
and coordinates between the other parts. The switch is controlled by the driver's turning signal when
he decides to change lane. The appropriate sensor is selected (left or right) and connected to the
transmitter and receiver. The state of the switch is known to the microcontroller so the correct sensor
side is displayed on the LCD.

Figure 5.1: System's Block Diagram.

Throughout my design, I adapted a modular approach towards the development and building of
the system. After testing and verifying the operation of each module (subsystem) alone, all modules
are connected and interfaced together to give the complete system.

41
5.1.2 System Circuit Schematic

Figure 5.2 shows the complete system schematic drawn using PREOTEUS ISIS Professional,
version 6.9 SP3. Figure 5.3 shows a photo of the system realized on solderless breadboard.

Figure 5.2: Complete System Schematic.

From Figure 5.2, one can notice that the implemented system consists mainly from these
components:

1. Transmitter (has red wires).

2. Receiver (has blue wires).

3. Microcontroller (the largest block).

4. Switches (have green wires).

5. LCD (has purple wires).

Each of these components will be explained in detail in the following sections.

42
Figure 5.3: System Implementation on Test Board.

5.1.3 Transmitter-Receiver Separation

The use of a single transceiver sensor instead of using a dedicated transmitter and receiver sensors
means that the sensor will be connected directly to the both the transmitter and receiver circuits.
Some sort of physical separation between these two circuits is required. This was done by use of
diodes (1N4148 small-signal diode). Figure 5.4 illustrates the separating action of the two groups pf
parallel-opposite diodes.

On the receiver side: These diodes just limit


(clip) any transmitted signal to prevent receiver
circuit damage. Any input signal to the receiver's
circuit is limited to ± 0.6 V (the threshold "ON"
voltage of the diode).

On the transmitter side: Since the received


signal voltage is very small, (about few milli-
Volts) the diodes' dynamic impedance is very
high and they separate the transmitter circuit
from the receiver.

Figure 5.4: Diodes configuration to separate


the receiver from the transmitter.

5.2 The Transmitter


5.2.1 Design Explanation

The generation of 40 kHz signal is done by the PIC. An output pin goes high and low
continuously. The output pulses have 5V amplitude. We need to transmit as large a signal as possible
in order to carry enough energy (large S.P.L.) to have a portion of it reflected back to the receiver.
This can be achieved via a transistor, which switches a larger power supply, jacking up the voltage to
the supply voltage instead of the 5V.

43
The transmitter circuit design shown in Figure 5.2 (with red connections) or in Figure 5.3 was
inspired from the well-known TTL to CMOS interface circuit which converts the voltage levels (0-5)
to (0-10). The transmitter circuit operation explanation follows:

Figure 5.5: Ultrasonic transmitter schematic.

1. When RB2 (or F.G. output) is at logic low (0V):


The NPN transistor Q1 is OFF (BE1 junction is reverse biased VBE < VBE ON) and is taken out of
the circuit. The PNP transistor Q2 is OFF too (EB2 is also reverse biased VEB < VEB ON) and is
taken out of the circuit. This means that VC2 is zero.

2. When RB2 (or F.G. output) is at logic high (5V):


The NPN transistor Q1 will be in SAT mode if IB1 > IB1(EOS).

Assuming that Q1 is SAT (this results in VC1= VCE1 SAT =0.3 V)

V C 2 V CC −V EC 2SAT 12 − 0.3
IC2 SAT = = = = 4.3 mA
RC 1 RC 1 2.7k
IC 2SAT 4.3m
IB2(EOS) = = = 53.75 μA
β 80
V B 2 −V C 1 V CC −V EB 2ONACT −V C 1 12 − 0.6 − 0.3
IB2 = = = = 4.1 mA
RB 1 RB 1 2.7 k
Since IB2 > IB2(EOS) → Q2 is SAT.

V CC −V CE 1SAT 12 − 0.3
IC1 SAT = + IB2 = + 4.1 m = 8.4 mA
RC 1 2.7 k
IC 1SAT 8.4m
IB1(EOS) = = = 112.6 μA
β 75
5 −V BE 1ONACT V BE 1ON ACT 5 − 0.6 0.6
IB1 = – = – = 2 mA
2.7 k 2.7 k 2.7 k 2.7 k
Since IB1 > IB1(EOS) → Q1 is SAT. My assumption is verified correct! So, VC2 equals 11.7 V

The analysis above has shown that 5V pulses entering the circuit becomes approximately 12V
pulses. Transistors data was taken from their data sheets (refer to Appendix: C for more data).

44
5.2.2 Simulation Results

The simulation circuit of Figure 5.5 was drawn using Electronics Workbench MultiSim version 9
Power-Pro. The Agilent function generator simulates the pulses produced by the PIC pin RB2 in
Figure 5.2. Agilent two-channel oscilloscope displays the input and the output of the transmitter
circuit. These waveforms are shown in Figure 5.6. The waveform in purple color is input signal
generated by PIC while the waveform in red color shows the output, which is the input to the
transmitting ultrasonic sensor.

Figure 5.6: Transmitter operation simulation using EWB MultiSim.

5.3 The Receiver


5.3.1 Design Explanation

The signal picked up from the ultrasonic transducer is extremely small and has a large fluctuation
depending on the size, angle, surface shape, moving speed, distance of the reflector body for the
receiver. Therefore, in order to be of any use it needs quite a significant amount of amplification. In
fact, every enhancement in the amplification gives increment to the detection range (distance) and
more sensitivity to smaller bodies.

Unlike other receivers, a typical ultrasonic receiver does not require filtering before the
amplification stage, because the receiver unit is a resonator itself. As a result, it oscillates only at a
certain frequency (40 kHz), and it filters out other frequencies. In other words, the receiver sensor is
naturally sensitive to signals around 40 kHz only.

Using a single operational amplifier with large voltage gain will be very problematic. Any
amplification of more that 50 V/V may introduce noise to the 40 kHz signal, and sophisticated
filtering is required. I had to split amplification into two cascaded stages. The overall gain is the

45
product of each individual gains. The gain value usually depends on the sensor type and detection
range that a designer needs for his application.

Figure 5.7 below shows the ultrasonic receiver schematic. It is very simple, consisting of two
main components; amplifier and comparator. The receiver sensor is loaded with a 100kΩ resistor to
provide a direct signal path to ground and to increase (improve) the receiver's sensitivity as the curve
in Figure 2.9 in Section 2.4 indicates.

Figure 5.7: Ultrasonic receiver schematic.

R2, R3 and R7 10kΩ potentiometer form a voltage divider that supplies the op-amps with about
half the 5V-regulated voltage. The reason for this is that the input signal is true AC, and the
operational amplifier has a single positive power supply (5V-regulated). This commonly named
"floating ground" eliminates the need for a negative supply by lifting the input signal up. C1 is used
for ripple suppression.

Each of the operational amplifiers along with its negative input terminal series capacitor and
resistor, and the feedback resistor is essentially a "high-pass" filter. The first active high-pass filter has
cut-off frequency (2πR1C2)-1 Hz and high-frequency gain (R6/ R1) V/V. The same analogy applies to
the second Op-Amp.

The output of U1B is now sufficiently large enough to be useful, but is not suitable for interfacing
directly to the PICmicro microcontroller. The PICmicro expects a clean high or low on its IO pin,
but the output of the Op-Amp is an amplified AC signal with a midpoint DC voltage in the range
1.67V to 3.33 V depending on the potentiometer position. This is were the use of some sort of wave
shaping comes in. In order to convert the AC signal into discernable highs and lows, I use
PIC16F877A built-in comparator (which is simulated by the LM393 comparator IC in Figure 5.7).

PIC16F877A comparator's operation was illustrated by Figure 3.5 in Section 3.3.3. Without
any input signal to the two-stage amplifier, the output of U1B will be a steady DC voltage. This is fed
directly to the negative input of the PIC16F877A comparator. The positive input of the comparator is
connected to the PIC16F877A voltage reference module (which is simulated by the 2.2V voltage
source Figure 5.7).

46
Initially, the potentiometer's position will be set to produce about 2.5V DC level "floating
ground" to the amplified AC signal. Therefore, when there is no reflected wave (no obstacle/object
state) the voltage on the negative input is slightly higher than the positive input, and the output of the
comparator is low.

When an echo is received, an amplified version of the signal appears on the output of U1B and is
fed to the negative input of the comparator, which now goes both higher and lower than before as the
AC signal is super-imposed on the original 2.5 DC voltage. So, if the received signal on the negative
input should go lower than the voltage on the positive input, the comparator output will go high, and
hence, the output from the comparator will be a series of positive going pulses that can be recognized
by the PICmicro processor.

By adjusting 10kΩ potentiometer, the voltage difference varies between the positive and negative
inputs of the comparator and makes it more or less sensitive. Higher DC voltages set by the
potentiometer makes the receiver less sensitive.

5.3.2 Simulation Results

The LM358 IC is a low noise high gain dual operational amplifier that needs a single positive
supply to work. Referring to the data sheet, I found its gain bandwidth product (also known as "unity
gain") equals to 1 MHz. This means that for 40 kHz signal input, the maximum attainable gain from
the amplifier is:
GainMax = (Unity Gain)/(signal frequency)
= 1M/40K
= 25 V/V (27.96 dB)

In other words, if the ratio of the feedback resistor to the negative input terminal resistor, i.e.,
(R6/ R1) or (R10/ R4) is more than 25, the actual voltage gain is reduced to 25.

Once again, simulation was done using Electronics Workbench MultiSim version 9 Power-Pro.
In the first case shown by Figure 5.7, the SPDT switch is closed enabling a 40 kHz signal from the
function generator to enter the circuit (The receiving sensor is modeled by an AC voltage source
represented by the F.G.). Worst-case analysis was performed in Section 2.4 where the minimum
detectable signal has 8 mVp-p amplitude. This signal is generated by the F.G. in Figure 5.7. Tektronix
four-channel oscilloscope displays the input AC signal, the output of first amplifier, the output of
second amplifier, and the output of comparator as in Figure 5.8. The results were as expected
theoretically, the gain of the first stage is 25V/V, while the second stage gives gain of 10V/V.
Detection is confirmed by the PIC when the comparator's output becomes high. Being high for about
12.5 μs is enough to be recognized by the PIC. Notice the 4.7k pull-up resistor at the output of
LM393 in Figure 5.7. This is because its output is open collector requiring a pull-up resistor.

The second case when there's no received signal is shown in Figure 5.9. The simulation results for
the four channels are displayed simultaneously on the scope screen in Figure 5.10 and they are
expected.

47
(a) (b)

(c) (d)
Figure 5.8: Receiver operation simulation using EWB MultiSim (Switch is closed):
(a) Input signal (b) Output of first amplifier (c) Output of second amplifier (d) Output of comparator

Receiver's practical experimentation and measurements in the lab gave the following results:

G1 = VO1/VIN1 = 370m/19.75m
= 18.73 V/V (25.45 dB)
G2 = VO2/VIN2 = 2.935/370m
= 7.93 V/V (17.98 dB)
Gtot = G1×G2 = 18.73 × 7.93
= 148.53 V/V (43.44 dB)
The actual results are close to the computer simulation results.

48
Figure 5.9: Ultrasonic receiver schematic.

Figure 5.10: Receiver operation simulation using EWB MultiSim (Switch is open).

5.4 The Microcontroller


5.4.1 Biasing the PIC

PIC16F877A has wide operating voltage range: 2.0V to 5.5V. However, the available voltage is
12 V from car's battery. Voltage level step-down is performed by the voltage regulator IC LM7805
(U3 in Figure 5.2). The 7805 takes a 12V input and convert it to 5V output suitable for PIC. These
five volts are fed to one of PIC's VDD pins (11 or 32). They are internally connected. Ground (0V)
connection is required to any of PIC's VSS pins (12 or 31). The Two capacitors, C4 and C5, suppress
high- and low-frequency noise on the 5-V supply line, respectively.

49
5.4.2 Resetting the PIC

PIC16F877A reset can be achieved via its MCLR pin (Master CLear Reset) numbered one. Being
active low dictates the use of a 4.7 kΩ pull-up (current-limiting) resistor. Pressing the push-button
makes the input "low" and resets the PIC.

5.4.3 PIC Clock Frequency

For maximum processing speed, I used a 20 MHz crystal as a clock by connecting it across pins
13 and 14. This results in 200 ns instruction cycle.

5.4.4 PIC Ports and Pins

PIC16F877A connection in Figure 5.2 uses 9 pins of the 33 available Ports pins. These are:
RA1: Second amplifier output.
RA4: Switch state.
RB2: Transmitter drive.
RD2: LCD Register Select line.
RD3: LCD Enable line.
RD4-RD7: LCD Data lines.

5.5 The Switches


5.5.1 The Manual SPDT Switch

The left and right sensors are selected and switch using a Single-pole Double-through switch
(SPDT). For car's application, this switch is controlled by the turning signal. Before changing lane,
the driver should give a pre-turn signal, similar to the manual switching action. In Figure 5.2, the
collector C3 is connected to the control input of the IC switch connected to the left sensor. While the
Base B3 is connected to the control input of the IC switch connected to the right sensor. Thus, the
electronic switch cannot be in the same state. One of them is ON (closed), while the other if OFF
(open).

When the SPDT SW is in the upper position, Q3 (inverter configuration) is in saturation mode.
The signal fed into pin 13 of the 4066 IC switch is low and Switch A is closed. Switch B, on the other
hand, is open and the left sensor is selected (connected to the transmitter-receiver side).

When the SPDT SW is in the lower position, Q3 is off. The signal fed into pin 12 of the 4066 IC
switch is low and Switch B is closed. Switch A, on the other hand, is open and the right sensor is
selected (connected to the transmitter-receiver side).

5.5.2 IC Electronic Switch

The CD4066 IC is a quad bilateral switch intended for the transmission or multiplexing of analog
or digital signals. Each switch has three pins, input "X", output "Y", control "C". When the control
signal is low, the switch is closed, otherwise it's open. This switch has many attractive features that
made me consider it in my design. It has wide supply voltage range, extremely low "ON" resistance,
high noise immunity, low crosstalk, and high degree linearity

50
5.6 The Alphanumeric LCD Module
One of the best solutions for devices that require visualizing the data is the Alphanumeric Dot-
Matrix Liquid Crystal Display (LCD). I used the 16×2 LCD to display the distance to the driver.
There are two main types of these LCDs, serial and parallel LCDs. The serial LCD requires uses one
"serial" line for data transmission. However, it works on voltages of -10V and +10V but the output
coming out of the PIC16F877A serial output port is the standard digital voltages of 0V and +5V.
Voltage level conversion to standard TTL is required. This can be done by use of MAX232 chip. On
the other hand, parallel LCD requires 4 to 8 "parallel" data pins to be connected to the PIC. The
availability of parallel LCD modules in the lab and the fact that they do not need voltage level
conversion made me decide on them. Figure 5.11 Shows the available LCDs. Its connection to
PIC16F877A is shown in Figure 5.2.

Figure 5.11: Available LCD Modules.

The pin-out for standard parallel LCD is shown in table. Description of each pin's function is
presented below.

Pin No. Name Function


1 Vss Ground
2 Vdd Positive Supply
3 Vee Contrast
4 RS Register Select
5 R/W Read/Write
6 E Enable
7 D0 Data bit 0
8 D1 Data bit 1
9 D2 Data bit 2
10 D3 Data bit 3
11 D4 Data bit 4
12 D5 Data bit 5
13 D6 Data bit 6
14 D7 Data bit 7
Table 5.1: Pin-out designation for most standard LCDs.

Pins 1 and 2 are power supply lines, Vss and Vdd. The Vdd pin should be connected to the positive
supply, and Vss to the 0V supply or ground.

51
Pin 3 is a control pin, Vee, which is used to alter the contrast of the display. ideally, this pin should be
connected to a variable voltage supply. For simplicity, I connected it to the ground for maximum
contrast.

Pin 4 is the Register Select (RS) line, the first of the three-command control input. When this line is
low, data bytes transferred to the display are treated as commands. By setting the RS line high,
character data can be transferred to and from the module.

Pin 5 is the Read/Write line. This line is pulled low in order to write commands or character data to
the module because communication is one-way (toward LCD).

Pin 6 is the Enable line this input is used to initiate the actual transfer of commands or character data
between the module and the data lines. When writing to the display data is transfer only on the high
to low transition of this signal.

Pins 7 to 14 are the eight data bus lines (D0–D7).data can be transferred to and from the display,
either as single 8-bit or as 4-bit. I decided to use 4-bit mode to save engaged pins in the PIC.

52
Chapter 6: PIC Programming and Interfacing

Programming PIC microcontrollers is a simple three-step process: Write the code, compile the
code, and upload the code into a microcontroller. Following is discussion about the used
programming language, compiler, programmer, and program code explanation.

6.1 Programming Language


There are a number of compilers on the market that allow users to write programs (codes) in
different high-level languages. High-level language frees the programmer from wrestling with and
controlling the microcontroller’s registers when writing code and accessing the different aspects of
the microcontroller’s features and memory. There are various programming languages such as
Assembly, BASIC, C, Pascal, …etc.

The high-level language I used is a derivative of the BASIC language. It is called PicBasic. (The
PicBasic and PicBasic Pro compilers used to write PicBasic programs are products and trademarks of
microEngineering Labs, Inc.) PicBasic is similar to the PBasic language used in programming the
Basic Stamp series. Programming microcontrollers directly using the PicBasic (or PicBasic Pro)
compiler offer two major advantages over the Basic Stamp series of microcontrollers which use
external serial EEPROM for memory storage, faster program execution speed, and reduced cost.
When compared to other high-level languages, BASIC is still considered by many PC users to be the
easiest programming language to use. It allows faster and much easier development of applications
for PIC. I had to learn about 30 different instructions to write my program code.

The compiler I used is "MicroCode Studio", which compiles PicBasicPro (PBP) programming
language. The program code is written and edited in MicroCode Studio window. Then it saves the
work as PBP file (program.pbp). When compiled, the program.pbp file is converted to Assembly
language code file (program.asm) and HEX file (program.hex). This file is the one that should be
loaded to the PIC using its programmer. To accomplish this, an application called "IC-Prog" has to
be used to interface the programmer to MS-Windows. It loads the hexadecimal file to the PIC's
memory.

6.2 PIC Programmer


Microcontroller Programmer is a circuit (hardware) by which HEX files (program code) are
transferred (loaded) from a computer to the microcontroller's memory. The used programmer was
already available in the lab. Its circuit is very simple and can be homemade (there are lot of ready-to-
use programmer schematics on he Internet). Figure 6.1 shows the circuit schematic for the
programmer. Its photo is shown in Figure 6.2.

53
Figure 6.1: Programmer computer interface diagram and circuit.

Figure 6.2: PIC Programmer.

6.3 PIC Program Code


6.3.1 Code Flow

The PicBasic program code shows the "big picture" of the whole system. The code flow diagram
in Figure 6.3 tells the whole story of how distance is measured.

The program starts by introducing the surrounding environment to the PIC microcontroller. The
clock oscillator and the LCD are defined, along with the variables intended to be used later (so their
memory locations are stored). Initial settings are set by storing correct values in the controlling
registers of Ports A and B (determine input and output pins), comparator module, and voltage
54
reference module (D/A). A delay of half second allows the PIC to stabilize its clock and registers.
Then, the selected sensor is recognized by the PIC by checking the logic state of Port A's pin 4
(RA4).

Figure 6.3: Code Flow Diagram.

The program then calls the subroutine "Send40k" which transmits ten cycles of 40 kHz ultrasonic
pulses. This is immediately followed by resetting and restating Timer1 which works as a stopwatch.
Another delay (No operation) of 1.2 ms is required before staring the detection of any reflected waves
to make sure that Ringing (residual vibrations) is over to avoid false detection. Before starting the
detection loop, a check on the selected sensor state is made. If the selected sensor hasn't changed
since its recognition at the beginning, the program starts the detection process, otherwise the new
state is saved and the program returns to the transmitting phase. The detection loop aims to check
the internal comparator's output repeatedly. When it goes high, detection of reflected wave is
confirmed and Timer1 is stopped. The value in Timer1 registers (low and high) is then divided by 29
to evaluate the distance in millimeters. The calculated value is then displayed on the LCD.

55
If Timer1 overflows without any detection, an "out of range" message is displayed on the LCD.
After displaying either the distance measured by the selected sensor or out of range messages on the
LCD, the program returns to the beginning to send another cycles of ultrasonic waves. And so on.

6.3.2 Code Analysis

Now comes the actual PicBasic code. The comments (in blue) clarify each line of the code in
detail. I wrote a self-explanatory code so there is no need to say more!

'****************************************************************
'* Name : Documentation.BAS *
'* Author : Rami M. Zaghal *
'* Notice : Copyright (c) 2006 J.U.S.T. *
'* : All Rights Reserved *
'* Date : 09-Dec-06 *
'* Version : 1.5 *
'* Notes : *
'* : *
'****************************************************************

'' ------------ [ Includes / Defines ] ----------------------- ''

define osc 20 'Inform PBP compiler that 20MHz is used as clock

DEFINE LCD_DREG PORTD 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 4 'Define first pin of PORTD connected to LCD DB4
DEFINE LCD_RSREG PORTD 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 2 'Define PORTD pin used for RS connection
DEFINE LCD_EREG PORTD 'Define PIC port used for E line of LCD
DEFINE LCD_EBIT 3 'Define PORTD pin used for E connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent

'' ------------ [ Variables, Aliases and Constants ] --------- ''

T1_LowerByte var word 'Variable used to store lower byte value of TIMER1
T1_UpperByte var word 'Variable used to store upper byte value of TIMER1
TOF var word 'Variable used to store the whole word value of TIMER1
Distance var word 'Variable used to store current measured Distance value
Sensor_old var byte 'Variable used to store initial value of PORTA4 (Sensor select)
Sensor_new var byte 'Variable used to store new value of PORTA4 (Sensor select)
Loop_cnt var byte 'Variable used to determine the number of 40k ultrasonic cycles
'to be sent

'' ------------ [ Initialization ] --------------------------- ''

TRISA = %11111011 'Set PORTA to all input except RA2


TRISB = %00000000 'Set PORTB to all output
CMCON = %00000101 'Set Comparator Module to one independent comparator mode
'with its output not inverted
CVRCON = %11000110 'Set Comparator Voltage Reference Module to generate about
'2.15V at PORTA.2 (Comparator's positive terminal)

'' ------------ [ Main Code ] -------------------------------- ''

INTCON = 0 'Make sure that all interrupts are OFF


LCDOUT $FE, 1 'Clear display screen
pause 500 'Wait for PICmicro to stabilize

56
Main: 'Main program's loop

T1CON = %00000000 'Stop TIMER1


PIR1.0 = 0 'Make sure that TIMER1 overflow flag is clear

'If CMCON.7 = 0 then the Comparator's positive terminal voltage is less than the negative terminal (NO
'detection occurred! No echo!)
'If CMCON.7 = 1 then the Comparator's positive terminal voltage is greater than the negative terminal
'(Detection occurred! Echo Received!)
if CMCON.7 = 1 then PORTA.1 = 1 'Make sure that Echo pin is initially high
'"Comp. out is low"

'If PORTA.4 = 0 then the Right sensor is activated/chosen


'If PORTA.4 = 1 then the Left sensor is activated/chosen
Sensor_old = PORTA.4 'Store initial value of PORTA.4 (Initially
'selected sensor)
T1CON = %00000001 'Enable TIMER1 with Prescaler 1:1
Gosub Send40k 'Start transmission of 40kHz ultrasonic waves
TMR1L = 0 'Clear lower byte of TIMER1 and start TIMER1
TMR1H = 0 'Clear upper byte of TIMER1
pauseus 1200 'Wait until Ringing finishes

Sensor_new = PORTA.4 'Store current value of PORTA.4 (Currently


'selected sensor)
if Sensor_new != Sensor_old then Main 'Check if selected sensor has changed and return
'to "Main" if it has

repeat 'Loop until TIMER1 overflows


if CMCON.7 = 1 then 'If detection occurred:
T1CON = %00000000 'Stop TIMER1
goto Calculate_Dist 'Then start distance calculation process
endif
until PIR1.0 = 1 'Timeout if TIMER1 overflow flag is set "TIMER1
'overflowed"
if PORTA.4 = 0 then 'Check which sensor is currently selected
LCDOUT $FE, 1, "Object is out of range from RIGHT sensor!" 'Clear display screen
and
'show "out of range"
'message
else
LCDOUT $FE, 1, "Object is out of range from LEFT SENSOR!" 'Clear display screen
and
'show "out of range"
'message
endif
pause 1000 'Wait 1 second "LCD Delay"
Goto Main 'Start a new program cycle

Calculate_Dist: 'Distance calculation process


T1_LowerByte = TMR1L 'Store lower byte value of TIMER1 in variable
T1_UpperByte = TMR1H 'Store upper byte value of TIMER1 in variable
TOF = T1_LowerByte + (T1_UpperByte * 256) 'Calculate total time of flight
Distance = TOF/29 'Calculate distance in millimeters
if PORTA.4 = 0 then 'Check which sensor is currently selected
LCDout "DISTANCE from RIGHT sensor (in mm) = ", dec Distance 'Display decimal value
'of distance in
'millimeters on the
'screen
else
LCDout "DISTANCE from LEFT sensor (in mm) = ", dec Distance 'Display decimal value
'of distance in
'millimeters on the
'screen
endif
pause 1000 'Wait 1 second "LCD Delay"
Goto Main 'Start a new program cycle

57
'' ------------ [ Subroutines ] ------------------------------ ''

Send40k: 'Function that generates 10 cycles of 40kHz


'ultrasonic pulses at PORTB.2
for Loop_cnt = 10 to 0 step -1 'Count from 10 to 0 by 1
PORTB=%00000100 'First half of the cycle
pauseus 11 'Create delay of 11 us (ON Time)
PORTB=%00000000 'Second half of the cycle
pauseus 10 'Create delay of 10 us (OFF Time)
next Loop_cnt 'Go back to and do next count
return

One last point worth mentioning here regards the subroutine "Send40k", you can notice that it's
simply a loop that is repeated 10 times. The aim of each cycle in "Send40k" is to make PortB's pin 2
high for the first half cycle, and low for the second half. Duty cycle of 50% is very difficult to obtain
using this technique. Instead, PortB.2 can be "high" for 12 μs, and "low" for 13 μs. That's a 40 kHz
waveform of 48% duty cycle. From my experimentation, I found that the PAUSEUS command used
in the “MicroCode Studio” compiler takes 1μs to be executed. This delay of 2 μs should be taken into
account. Extra delay is caused by the looping action, i.e., decrementing the loop counter, going back
to the start, and checking that it did not reach zero value. This is approximately 2 μs delay. So, for
the period to be 25 μs (40 kHz), The no-operation delay should be 11 μs and 10 μs for the ON and
OFF times, respectively. That is:

1μs + 11μs + 1μs + 10μs + 2μs = 25μs

58
Chapter 7: Conclusions

7.1 Challenges
During my work on the project, I faced the following challenges:

1. Studying various microcontrollers to choose the most suitable one with no previous
background.

2. Learning PIC programming from scratch.

3. Delay in arrival of ranging modules (SRM400) changed the course of the project significantly.
I didn't see that coming!

7.2 Future Work


This project can be a starting point for several other projects in distance measurement using
ultrasonic sensors and microcontrollers area. Some modifications and improvements are suggested
below:

1. The measurement process is based on a typical air temperature of 22°C. This can be limiting
when the specific application involves a wide operating temperature range. It would be an
improvement to implement an external integrated temperature sensor to measure the air
temperature.

2. Serial LCD can be used instead of the parallel one with only one data input to the PIC.

3. LEDs with three or four levels or colors can be used to alert the driver. The LEDs flashes
depending on the distance between the car and the obstacle/object in a pre-determined color
convention.

4. With slight modifications, the system can be converted into a reverse parking assistant.

5. With slight modifications, the system can be converted into ultrasonic radar by simply
mounting the sensor on a stepper motor that rotates to scan the required areas.

6. Improvement the PIC code could be achieved by implementing ISR (Interrupt Service
Routine) using the interrupt-on-change-pin supported by PIC to switch (select) sensors.

7. The system can have the ability to increase the volume of the audible warning sound as the
object distance decreases when turn signal is activated with the extra option to switch off the
sound warning by the user. Moreover, the distance range for sounding the audio warning may
be changed or controlled by the user.

8. The system can have the ability to change units of distance being displayed on LCD.

59
7.3 Recommendations
After completing the project, I realized that the following improvements could be made by the
department of Electrical Engineering any future projects including microcontrollers:

1. Providing PIC Programmer and development Kits and boards for students working on
projects involving PIC microcontrollers. Such kits have built-in LCD, ICD (In-Circuit
Debugging) feature and much more. The programmer can program PIC chips with different
pin numbers, which enhance the experimentation with PIC experience for the students. More
information is available on MicroChip's and mikroelektronika websites.

2. Getting a licensed version of PICmicro Simulators and IDE (Integrated Development


Environment) tools such as PROTEUS. Licensed fully functional versions of the well known
C and BASIC programming languages compilers, such as mikroBasic, PICBASIC Pro, PICC,
CCS PCWH, …etc.

3. Add an introductory course on microcontrollers in new plan for Electrical Engineering


students.

7.4 Final Comments


The work on this project was very challenging and entertaining. It involved precise selection of
sensors and microcontroller, programming the microcontroller, designing ultrasonic transmitter and
receiver circuits, simulating the designed circuits and written code, and finally, implementing the
whole system and testing it. To sum up, my project involved all what it takes for a real electronics
engineer or designer to build a reliable practical system.

My Internet research skills have improved remarkably. I joined many internet forums &
communities related to CAD simulation and microcontrollers. My reading speed even increased!
Another advantage worth mentioning is the interaction with Dr. Bassam El-Asir (Project supervisor).
It was my pleasure to work with him. This was the richest experience I had in my academic life.

One of the most important lessons I learnt from this experience is the power of question, or let us
call it "the power of courtesy". You must ask properly, precisely and in good timing about unknown
or unclear things in order to get fulfilling useful answers. As they say, ask gently and you will be
given.

All in all, I was 95% satisfied with my graduation project. ☺

60
References and Readings
"Top 10 Tech Cars", IEEE Spectrum Magazine, April 2006, pp.24-33.
J. David N. Cheeke, "Fundamentals and Applications of Ultrasonic Waves", CRC Press, 2002.
F. Alton Everest, "The Master Handbook of Acoustics", Fourth Edition, McGraw-Hill, 2001.
R. A. Serway and R. J. Beichner, "Physics for Scientists and Engineers, with Modern Physics", Fifth
Edition, Saunders College Publishing, 2000.
J. Borenstein, H.R. Everett and L. Feng, "Where Am I?, Sensors And Methods For Mobile Robot
Positioning", The University of Michigan, April 1996.
Donald Massa, "Part 2: Optimizing Sensor Selection", Sensors Magazine, March 1999.
Ming C. Lin, "Efficient Collision Detection for Animation and Robotics", Department of Electrical
Engineering and Computer Science, University of California, Berkeley, 1993.
"PICmicro Mid-Range MCU Family Reference Manual", Microchip Technology Inc., 1997.
"What’s A Microcontroller - Student Guide v2.2 ", Parallax Inc., 2004.

Myke Predko, "PICmicro Microcontroller Pocket Reference", McGraw-Hill, 2001.

John Iovine, "PIC Robotics - A Beginner’s Guide to Robotics Projects Using the PICmicro", McGraw-Hill,
2004.
John Iovine, "PIC Microcontroller Project Book", McGraw-Hill, 2000.

Fred Stevens, "Getting Started With PIC Microcontrollers", 1997.

"PicBasic Pro Compiler", microEngineering Labs, Inc., 2004.

Chuck Hellebuyck, "Programming PIC Microcontrollers with PicBasic", Newnes, Elsevier Science, 2003.
Les Johnson, "Experimenting with the PICBasic Pro Compiler", CROWNHILL Associates Ltd, 2000.
Adel Sedra and Kenneth Smith, "Microelectronic Circuits", Fifth Edition, Oxford University Press,
2004.
K. "Gopal" Gopalan, "Introduction to Digital Microelectronic Circuits", Prentice-Hall.

William Hayt, Jack Kemmerly and Steven Durbin, "Engineering Circuit Analysis", Sixth Edition,
McGraw-Hill, 2002.

61
Web Resources
Pro-Wave Electronics Corp. application notes:

http://www.prowave.com

MuRata Corp. application notes:

http://www.murata.com

MicroChip Technology Inc. application notes:


http://www.microchip.com
MicroChip Forum:
http://forum.microchip.com/
MELabs PICBASIC Forums:
http://www.picbasic.co.uk/forum/
Basic Micro Forums:
http://forums.basicmicro.net/Default.aspx
Proton PICBASIC Development Forums:
http://www.picbasic.org/forum/
mikroElektronika Forum:
http://www.mikroe.com/forum/search.php?mode=results
EDABoard:

http://www.edaboard.com

Farnell Distributor:

http://www.farnell.com

62
Appendix A
List of Components Used in the Project
♦ Resistors:
1. 100 Ω (× 1).
2. 2.7 kΩ (× 5).
3. 4.7 kΩ (× 3).
4. 10 kΩ (× 4).
5. 100 kΩ (× 2).
6. 1 MΩ (× 1).
7. 10 kΩ potentiometer (× 1).

♦ Capacitors:
1. 0.1 μ F radial electrolytic (× 1).
2. 1 μ F radial electrolytic (× 1)
3. 100 μ F radial electrolytic (× 1)
4. 10 nF ceramic disc (× 2).
5. 10 pF ceramic disc (× 2).

♦ Switches:
1. Manual SPDT-SW (× 1).
2. CD4066 quad bilateral switch (× 1).
3. Mini push-button (× 1).

♦ Sensors:
1. 400PT160 open-type transceiver ultrasonic sensor (× 2).

♦ Discrete Semiconductor Components:


1. 1N4148 small-signal diode (× 4).
2. 2N2222 NPN bipolar transistor (× 1).
3. 2N2907 PNP bipolar transistor (× 1).
4. 2N3904 NPN bipolar transistor (× 1).

♦ Integrated Circuits:
1. PIC16F877A Microcontroller (× 1).
2. LM358N dual operational amplifier (× 1).
3. LM7805 voltage regulator (× 1).

♦ Miscellaneous:
1. 20 MHz crystal (× 1).
2. 16×2 standard parallel alphanumeric LCD (× 1).
3. NEWSTAR voltage adapter [12V voltage source] (× 1).
4. Solderless breadboard (× 3).
5. Connection cords.

63
Appendix B

Sensors and Modules Purchase Order

Manufacturer and Supplier Info:

Manufacturer: Pro-Wave Electronics Corp. http://www.prowave.com


Distributor: Farnell. http://www.farnell.com
Agent (Dealer): Madhoun Electronics and Trade.

Order Details:

Part Part Order Unit Qty Total Status


Number Description Code Price Cost
(JD) (JD)
SRM400 Sonar Ranging 1007370 39.76 4 159.04 Has not
PROWAVE Module (Includes arrived yet!
One 400EP14D)
PW0268 Sonar Ranging 1007371 5.70 2 11.40 Arrived
PROWAVE SMT IC
400EP18A Ultrasonic Txr, 1007355 11.4 3 34.20 Arrived
PROWAVE Enc, 40kHz
400PT160 Ultrasonic Txr, 1007353 7.15 3 21.45 Arrived
PROWAVE Open, 40kHz
400PT120 Ultrasonic Txr, 1007354 7.40 3 22.20 Has not
PROWAVE Open, 40kHz arrived yet!
400ST120 Ultrasonic Tx, 1007339 6.90 4 27.60 Arrived
PROWAVE Open, 40kHz
400SR120 Ultrasonic Rx, 1007340 6.90 4 27.60 Arrived
PROWAVE Open, 40kHz
303.49 Sub Total
48.56 16% Sales Tax
352.05 Total

64
Appendix C
Selected Data Sheets

This appendix contains data sheets for the following components:

1. 400PT160 Ultrasonic Sensor


2. 400ST/R120 Ultrasonic Sensor
3. 400EP18A Ultrasonic Sensor
4. 400EP14D Ultrasonic Sensor
5. PIC16F877A Comparator Configuration
6. LM358N Dual Operational Amplifier
7. CD4066 Quad Bilateral Switch
8. 2N2222 NPN Bipolar Transistor
9. 2N2907 PNP Bipolar Transistor
10. 1N4148 Small-Signal Diode

65

You might also like