You are on page 1of 88

INDEX

CONTENTS PAGE NO

CHAPTER 1. EMBEDDED SYSTEMS

1.1. Introduction 1

1.2 Characteristics 2

1.3 CPU Platforms 2

1.4 Tools Embedded Systems 3

CHAPTER 2: CONCEPTS AND BACKGROUND INFORMATION

2.1Project_Specification 5

2.2 Problems 6

2.3 Literature Survey 7

CHAPTER 3: OVERVIEW OF THE PROJECT

3.1 Problem Description 9

3.2 Introduction 9

3.3 Aim - Project Outline 11

3.4 Project Specification 11

3.5 MAT LAB 15

3.6 Over view 16


3.6.1 Description 17

3.6.1.1 Hardware components 17

CHAPTER 4 SYSTEM ANALYSIS

4.1 Introduction 21

4.1.1 Eyes 21

4.2 sleep and road accidents 23

4.3 vehicles and microprocessors 25

4.3.1 Led Display Type 18

4.4 Power Supply 21

4.4.1circuit Explanation 21

4.4.2 Basic Principle 21

4.4.3 Bridge Rectifier 26

4.4.4 Voltage Regulator 28

4.5 Buzzer 29

4.6 Gsm Technology 30

4.6.1 Introduction 30

4.6.2 Architecture Of Gsm Network 32


4.6.3 Sms Service 33

4.7 Switches 33

4.8 Fingerprint Sensor 35

CHAPTER 5: DESIGN AND IMPLEMENTATION

5.1. Power Supply 27

5.1.1.transformer 27

5.1.2 rectifier 28

5.2. Alcohol Detection Sensor 31

5.3.Buzzer 32

5.4 Camera 33

5.5 Lcd 36

5.6 Motor 37

5.7 LM 35 39

5.4 MCP3208 40

5.9 ARM controller 41

5.9 .2ARM TDMI 41

5.10 GSM Technology 64


5.10.1 Introduction 64
5.10.2 Architecture 65
5.10.3 SMS service 66

CHAPTER 6: SOFTWARE ANAYSIS

6.1 keil software 67

6.2 Proteus 74

CHAPTER 7: RESULT AND DISCUSSION 79

CHAPTER 8: FUTURE SCOPE & CONCLUSION 80

REFERENCES 81
FIGURES

LIST OF FIGURES PAGE NO

FIG.2.1: Vehicle Controlling Unit 5

FIG.2.2: Light Reflection 6

FIG.3.1: Driver Drowsyness 9


FIG. 3.2 Accident view 10
FIG. 3.3 Driver fatigue 10

FIG. 3.4 Functional Schematic 13

FIG. 3.5 eye detection 15

FIG. 3.6 Testing 16

FIG 3.7: Block diagram 17

FIG. 4.1: Elements of the eye. 21

FIG. 5.1: Half wafe rectifier 28

FIG. 5.2:full wafe rectifier 29

FIG. 5.3:full wafe rectification 30

FIG. 5.4 Wiring up a regulator IC 31

FIG. 5.5: Alcohol sensor 31


FIG. 5.6 : Buzzer 33
FIG. 5.7: Image of face using standard low resolution CMOS camera 34
Fig 5.8 : Omni vision CMOS camera with fish eye lens 35
Fig 5.9 : standard CMOS high resolution camera 35
Fig 5.10 : Image showing difference between (A) un-illuminated pupil captured
with IR camera and (B) illuminated pupil showing reflected IR light.
Image Source 36

Fig 5.11: LCD display 37

Fig 5.12: Motor 37

Fig 5.13 : ARM Architecture 45


Fig : 5.14 Over view of GSM 65

Fig 5.15: GSM Architecture 65


CHAPTER-1

EMBEDDED SYSTEMS

1.1 INTRODUCTION

An embedded system is a special-purpose computer system designed to perform one or a few


dedicated functions, often with real-time computing constraints. It is usually embedded as part
of a complete device including hardware and mechanical parts. In contrast, a general-purpose
computer, such as a personal computer, can do many different tasks depending on
programming. Embedded systems control many of the common devices in use today .Since the
embedded system is dedicated to specific tasks; design engineers can optimize it, reducing the
size and cost of the product, or increasing the reliability and performance. Some embedded
systems are mass-produced, benefiting from economies of scale.

Physically, embedded systems range from portable devices such as digital watches
and MP3 players, to large stationary installations like traffic lights, factory controllers, or the
systems controlling nuclear power plants. Complexity varies from low, with a single
microcontroller chip, to very high with multiple units, peripherals and networks mounted
inside a large chassis or enclosure

In general, "embedded system" is not an exactly defined term, as many systems have
some element of programmability. For example, Handheld computers share some elements
with embedded systems such as the operating systems and microprocessors which power them
but are not truly embedded systems, because they allow different applications to be loaded
and peripherals to be connected. Embedded systems span all aspects of modern life and there
are many examples of their use. Telecommunications systems employ numerous embedded
systems from telephone switches for the network to mobile phones at the end-user. Computer
networking uses dedicated routers and network bridges to route data.

1
1.2 CHARACTERISTICS:

1. Embedded systems are designed to do some specific task, rather than be a general-purpose
computer for multiple tasks. Some also have real-time performance constraints that must be
met, for reasons such as safety and usability; others may have low or no performance
requirements, allowing the system hardware to be simplified to reduce costs.
2. Embedded systems are not always standalone devices. Many embedded systems consist of
small, computerized parts within a larger device that serves a more general purpose. For
example, the Gibson Robot Guitar features an embedded system for tuning the strings, but the
overall purpose of the Robot Guitar is, of course, to play music. Similarly, an embedded
system in an automobile provides a specific function as a subsystem of the car itself.
3. The software written for embedded systems is often called firmware, and is usually stored
in read-only memory or Flash memory chips rather than a disk drive. It often runs with limited
computer hardware resources: small or no keyboard, screen, and little memory.

1.3 CPU PLATFORMS:

Embedded processors can be broken into two broad categories: ordinary


microprocessors (P) and microcontrollers (C), which have many more peripherals on chip,
reducing cost and size. Contrasting to the personal computer and server markets, a fairly large
number of basic CPU architectures are used; there are Von Neumann as well as various
degrees of Harvard architectures, RISC as well as non-RISC and VLIW; word lengths vary
from 4-bit to 64-bits and beyond (mainly in DSP processors) although the most typical remain
8/16-bit. Most architecture comes in a large number of different variants and shapes, many of
which are also manufactured by several different companies.

ASIC and FPGA solutions:

A common configuration for very-high-volume embedded systems is the system on a


chip (SoC), an application-specific integrated circuit (ASIC), for which the CPU core was
purchased and added as part of the chip design. A related scheme is to use a field-
programmable gate array (FPGA), and program it with all the logic, including the CPU.

2
Peripherals:

Embedded Systems talk with the outside world via peripherals, such as

Serial Communication Interfaces (SCI): RS-232, RS-422, RS-485 etc


Synchronous Serial Communication Interface: I2C, JTAG, SPI, SSC and ESSI
Universal Serial Bus (USB)
Networks: Ethernet, Controller Area Network, LAN networks, etc
Timers: PLL(s), Capture/Compare and Time Processing Units
Analog to Digital/Digital to Analog (ADC/DAC)

1.4 TOOLS EMBEDDED SYSTEMS:


As for other software, embedded system designers use compilers,
assemblers, and debuggers to develop embedded system software. However, they may also use
some more specific tools:

In circuit debuggers or emulators


Utilities to add a checksum or CRC to a program, so the embedded system can check if the
program is valid.
For systems using digital signal processing, developers may use a math workbench such as
MATLAB, Simulink, MathCad, or Mathematica to simulate the mathematics. They might also
use libraries for both the host and target which eliminates developing DSP routines as done in
DSPnano RTOS and Unison Operating System.
Custom compilers and linkers may be used to improve optimization for the particular
hardware.
An embedded system may have its own special language or design tool, or add enhancements
to an existing language such as Forth or Basic.
Another alternative is to add a Real-time operating system or Embedded operating system,
which may have DSP capabilities like DSP nano RTOS.

Software tools can come from several sources:

Software companies that specialize in the embedded market

3
Ported from the GNU software development tools
Sometimes, development tools for a personal computer can be used if the embedded processor
is a close relative to a common PC processor

As the complexity of embedded systems grows, higher level tools and operating
systems are migrating into machinery where it makes sense. For example, cell phones,
personal digital assistants and other consumer computers often need significant software that
is purchased or provided by a person other than the manufacturer of the electronics

4
CHAPTER-2

CONCEPTS AND BACKGROUND INFORMATION

2.1_PROJECT_SPECIFICATION
A significant cause of road accidents is driver fatigue, which results in loss
of concentration and ultimately loss of the control of the vehicle.
The purpose of this project is to investigate the development of a system for detecting the
likelihood that a driver is about to fall asleep in control of the vehicle, and to sound an alarm
or carry out some other function if this occurs. The system will be primarily based on the use
of a small camera mounted on the vehicle dashboard which will locate and "track" the
driver's eyes, and on this basis attempt to detect if the driver is about to fall asleep.

For example, if the eyes close and remain closed for a certain period of time,
this may indicate that the driver has fallen asleep and that a crash is imminent. Alternatively,
if the eyes start to fall towards the bottom of the image (in a video sequence), this might
suggest that the driver's head is starting to droop. At the same time, the system should not
react inappropriately to "natural" movement of the driver's eyes, e.g. if the driver turns
his/her head to look out the side window.

Fig 2.1:Vehicle Controlling Unit

5
The Reliability And robustness of the system may be enhanced by making use of
additional sensing devices and combining all of the information in a "sensor fusion"
environment. For example, pressure sensors could be located in the steering wheel to indicate
how "tightly" the wheel is being gripped; if the pressure suddenly drops, this may indicate
that the driver is relaxing his/her hands because of fatigue. On the other hand, the pressure
may drop simply because the driver is relaxing, so visual information may be required to
"confirm" the hypothesis that the driver is falling asleep. Initial algorithm development will
be carried out in Mat lab, with the intention of porting some of the functionality to a suitable
embedded system (e.g. based on the ARM microprocessor or alternative).

2.2 PROBLEMS:

A major problem is recognising the eyes, the processes currently detect many
circular objects on the face i.e. tip of nose and area around eye.

Fig 2.2:Light Reflection

Another major problem is the light conditions present to illuminate the drivers
face. In too dark conditions the eyes are hidden by shadow of the eye sockets and in too
bright conditions, curved areas such as the forehead and nose reflect most of the light and
appear extremely bright in the frame

6
Drivers with glasses also pose a problem, the glare from glasses over the eyes
hide the pupils making it difficult to track or impossible for the pupils to be seen in some
cases.

Irregular eye and head movements of the driver may cause the alarm to
incorrectly signal, i.e. should the driver look at their mirrors or outside the prescribed range
of view

2.3 LITERATURE SURVEY:

Sweat sensors , Saab Alco Key , straw like tube on the driver seat are used to check
drunken condition of the drivers in cars. But these devices lead to misreading, inaccurate
testing and circuit complexity is high. Hongjie Leng and Yingzi Lin developed a novel carbon
nanotube (CNT)- based alcohol sensor with a particular focus on the response delay problem
presented in CNT based sensors. William R. Reagen developed a system for locating missing
vehicles. Shegeyuki Kojima et al designed a new algorithm to distinguish between the normal
and intoxicated state of a person which is proposed as the basic theory of the sensing system.
The entire solution requires only a mobile phone placed in vehicle and with accelerometer and
orientation sensor. A program installed on the mobile phone computes accelerations based on
sensor readings, and compares them with typical drunk driving patterns extracted from real
driving tests. Jiangpeng Dai et al focused on drunken driving, or officially driving under the
Influence (DUI) of alcohol, which is a major cause of traffic accidents throughout the world.
Lei Wang et al suggested that the integrity of PPG signal and accuracy of heart rate detection
were evaluated and the results showed that with adequate optical shielding and the proposed
passive motion cancellation, the device was able to reliably detect heart rate both during rest
and moderate exercise. Aditya et al suggested that biometrics can be used in the security
mechanism for the motor vehicles, as an anti theft Darnell et al invention comprises a portable
locating unit to provide location information signals. Heng et al suggested compulsory helmet
laws for bicyclists and expanding anti-drunk driving campaigns to target alcohol-intoxicated
bicyclists. Alex Tay et al presented a path-planning algorithm and a novel global navigation
strategy for autonomous unmanned ground vehicles in an unstructured terrain. It is able to
chart a path along roadways and off-road terrain. From this review, each and every paper gives
only a particular application to provide a safety to the drivers. To overcome the major

7
problems on road accidents and drunken driving, we designed an intelligent system in the
vehicle to avoid drunken driving. In addition to this, we have adopted few more applicatoins to
avoid parking of vehicles in No parking/ No entry area The features incorporated in our system
are
1) Confirmation of helmet wearing
2) Alcohol detection
3) No entry/ No parking indication
4) Accident intimation and
5) Theft detection

8
CHAPTER-3

OVERVIEW OF THE PROJECT

3.1 PROBLEM DESCRIPTION

A significant cause of road accidents is driver fatigue, which results in loss of


concentration and ultimately loss of the control of the vehicle. This aspect of road safety has
been highlighted by the Road Safety Authority through its publicity campaigns.

Fig 3.1:Driver Drowsyness

The AP Transport Safety Council state that driver fatigue conservatively estimated to
be a factor in about 20% of road crashes in Europe

The purpose of this project is to investigate the development of a system for detecting
the likelihood that a driver is about to fall asleep in control of the vehicle, and to sound an
alarm or carry out some other function if this occurs.

3.2 INTRODUCTION

Road safety is a topic discussed almost every day in the papers and on our airwaves in
this country and worldwide, unfortunately though this is usually because of the lack of safety
and precaution taken by road users. While dangerous and drunken driving may be highly
publicised a major contributing factor in many accidents on our roads is driver fatigue,
according to the National Roads Authority, driving tired is as lethal as driving drunk.

9
Fig 3.2: Accident view

"Up to 20% of fatal crashes may be linked to driver fatigue Latest research
indicates that driver fatigue could be a contributory factor in up to a fifth of driver deaths in
Ireland. They also say that driving when very tired is as dangerous as driving while over the
drink drive limit.

It also means that this silent killer could have been a contributory factor in
almost 200 driver deaths in a recent five year period.

The critical points at which driver fatigue related collisions happen are between 2am to
6 am and mid afternoon between 2pm to 4 pm when our "circadian rhythm" or body clock is
at its lowest point. Males aged 18 to 30 are in the high risk category. They tend to be over
confident about their driving ability and believe they can handle the situation. Women are
less likely to be involved in sleep related crashes.If a driver persists in fighting sleep while
driving the impairment level is the same as driving while over the drink drive limit.
Eventually a driver will drift in and out of consciousness and experience "micro sleeps"
which can last for up to 10 seconds. In this time a driver has no control of the vehicle. Drivers
can experience such a micro sleep with their eyes wide open.

Fig 3.3: Driver fatigue


10
Driver fatigue not only impairs driving in a similar way to alcohol it also
magnifies the damage alcohol does. It is estimated that alcohol is twice as potent mid
afternoon and in the early hours of the morning because we are more likely to be tired at
these times. Consequently, people who think they are driving under the legal limit should be
aware that even small amounts of alcohol consumed at these key times when we are tired
combine to render a driver completely unfit to the driving

3.3 AIM - PROJECT OUTLINE

While the NRA tell us "micro sleeps" can occur with the drivers eyes open, the aim of
the project is to detect fatigue in the driver through monitoring their eye movements and
detect such "micro sleeps" when the driver closes their eyes for an extended period of time.

By using a camera to track the movement of the driver's eyes, we can sound an alarm to
alert the driver should the focus of the eyes fall from the road or close due to the driver
falling asleep. Incorporating auxiliary data inputs into the decision making process will
increase the robustness of the algorithm and improve the usability of the system, such inputs
include pressure sensors on the steering wheel, time of day and temperature.

3.4 Project Specification

The purpose of this project is to investigate the development of a system for detecting
the likelihood that a driver is about to fall asleep in control of the vehicle, and to sound an
alarm or carry out some other function if this occurs. The system will be primarily based on
the use of a small camera mounted on the vehicle dashboard which will locate and "track" the
driver's eyes, and on this basis attempt to detect if the driver is about to fall asleep.

For example, if the eyes close and remain closed for a certain period of time, this may
indicate that the driver has fallen asleep and that a crash is imminent. Alternatively, if the
eyes start to fall towards the bottom of the image (in a video sequence), this might suggest
that the driver's head is starting to droop. At the same time, the system should not react

11
inappropriately to "natural" movement of the driver's eyes, e.g. if the driver turns his/her head
to look out the side window.

The reliability and robustness of the system may be enhanced by making use of
additional sensing devices and combining all of the information in a "sensor fusion"
environment. For example, pressure sensors could be located in the steering wheel to indicate
how "tightly" the wheel is being gripped; if the pressure suddenly drops, this may indicate
that the driver is relaxing his/her hands because of fatigue. On the other hand, the pressure
may drop simply because the driver is relaxing, so visual information may be required to
"confirm" the hypothesis that the driver is falling asleep. Initial algorithm development will
be carried out in Matlab, with the intention of porting some of the functionality to a suitable
embedded system.

3.4.1 Area of application

Road users have long been known to fall asleep whilst driving. Driving long hours can
induce fatigue causing lack of concentration and occasionally road accidents.

This is even more critical on motorways where traffic travels at higher speeds and
drivers can succumb to motorway hypnosis as the repetitive and somewhat passive
experience of driving on long, wide, straight roads can cause the driver to relax and lose
concentration from the road and traffic around them.

This allows drivers who legally are fit to drive but physically are not, on the roads. Many of
these drivers are unaware of their fatigue and danger they pose to themselves and other road
users. A main application of this system is primarily to protect such people described by
alerting them to their fatigue.

3.4.2 Functionality

A standard CMOS (Complementary Metal Oxide Semiconductor) camera is mounted in


the front of the car to view the drivers face but not obstruct their observation of the road

ahead. The functionality of the system is illustrated in Figure 1.1.

12
Fig 3.4: Overall Functional Schematic

The frame grabber receives the camera feed from which it takes in the current image
data in digital form and allows access to the data for processing. This procedure repeats itself
at the start of every cycle once the previous frame is processed.

The image is captured and taken into the system where it is pre-processed before the
Hough Transform is applied; the image is reduced in size to the region surrounding the eyes,
using cropping tools.

Then the cropped image is converted from RGB (Red Green Blue) colour to a greyscale
image with 255 levels of intensity. This reduces the amount of data in the image while
retaining much of the critical information needed.

As the colour image was captured, data from the pressure sensors located on the
steering wheel are sampled at a rate 10 times greater than that of the camera. The sensors
provide a voltage reading corresponding to the level of pressure exerted by the user, this
sampled data has 212 (4096) different levels. This is minimised to 25 levels to reduce
complexity of the data and over sensitivity from the sensors. This is done to control
unnecessary sensitivity on the sensors and to acquire a reliable reading of the pressure being

13
applied to the wheel. The voltage levels are graded against set threshold levels - ok, marginal
or too light. These levels can be defined by the user to suit their style of driving.

Once the pressure is processed and image data pre-processed the sensor fusion aspect of
this project uses the information given to it to vary the sensitivity of the analysis of the image
data. Should the steering wheel pressure be marginal the eye detection function will increase
its scrutiny for signs of fatigue.

Once sensor data has been considered the Hough Transform is applied to the cropped
grayscale image and circular object data is referenced to a minimum threshold to remove
spurious detections and interferences.

The data is analyzed further for the detection of eyes in the image. This involves the
application of the geometric features of the eye to the data, resulting in a more accurate
detection. Resulting data is then further analyzed to check if the points selected resemble
eyes, using the color data from the original image.

Combining the resulting image information and the sensor data, the fatigue detection
system is able to decide whether the alarm procedure is activated or returns to the start where
it re-initializes and the process starts over again. The functionality of this system should be
unobservable to the driver during normal conditions and the driver should only be aware of
the system, should the alarm procedure be activated.

ALGORITHM

1. Initialise the system

2. Monitor the driver condition(alcoholic value, fatigue, temparature)

3.check the threshold values sensors

4. if threshold value exceeds

5. engine stops.

14
FLOW CHART

INITIALIZATION

MONITOR THE
PARAMETERS

ALCOHOL/FA
TIGUE/TEMP

VEHICLE CONTROLL

3.5 MATLAB :

The main area of development in the project to date has been the Matlab coding of the
functions to detect and track the objects.

Initially the project was to be based around code using Hough transform
function that used many loops to work its way through the image. While the function did
detect circular objects as we can see in figure 1, it was found to be difficult to specify which
objects.

Fig 3.5: eye detection

15
Also for the purposes intended, the function was unusable as the process was highly
demanding on the processing power as larger ranges of radii sizes required exceptionally
large amounts of computations in comparison to smaller ranges. This caused the function to
be slow and did not come near the time constraints demanded by this project.

Using another faster Hough transform function I have been able to meet these time
constraints and using indexed AVI files have been able to test sample video footage and find
circular objects in the facial region.

Fig 3.6: Testing

In the testing the area of the frames are restricted to the region where the eyes
are located, this would be typical of normal operation and can be processed in real time.
Using global searches for each frame to create the worst case scenario in terms of image
processing, It's found that this does take longer but is near real time and using lower frame
sampling rates the function meets the constraints.

3.6 OVERVIEW

The main unit of this project is an Alcohol sensor. If the person inside car has
consumed alcohol then it is detected by the sensor. Sensor gives this signal to a comparator IC.
The output of comparator is connected to the microcontroller. Microcontroller is the heart of this
project. It is the CPU of the complete circuit. Microcontroller gives high pulse to the buzzer
circuit and the buzzer is turned on. At the same time a relay is turned off. Due to this the ignition
of the car is deactivated.

16
Block diagram:

Fig 2.1: Block diagram

3.6.1 BLOCK DIAGRAM DESCRIPTION:

The following hardware and software is used in this system. Detailed explanations of
these components follow in the later sections.

3.6.1.1 HARDWARE COMPONENTS:

1. Power supply.

17
2. ARM7(LPC2148)
3. Alcohol detection sensor.
4. Buzzer.
5. Buzzer Driver circuit.
6. Transformer.
7. LCD.
8. Engine/Motors.

Video Input

This is the indexed AVI frames that are fed into the image process. The use of the
indexed frames is to facilitate the Image processing to loop back on frames or skip sequences
of frames if necessary.

Image Process

This is the main processing function. Taking a video frame input and performing eye
detection and tracking functions on the image. The output is the pupil location data in the
frame.

Information Collation

This function takes in the pupil location or null data depending on the success of
finding the pupils and stores it in memory. Also inputted are the data from the steering wheel
which is logged to memory and the time of day and temperature. The latter two inputs are
important factors in deciding how strictly to apply the alarm rules. A moderately high
temperature would encourage fatigue in the driver and make them more likely lose
concentration.

Research presented by the NRA states that the critical times for fatigue in drivers and
micro sleeping are night times "between 2am to 6am and mid afternoon between 2pm and
4pm when our 'circadian rhythm' (body clock) is at its lowest point".For this reason the time
of day is important in deciding if the driver is suffering fatigue.

18
The data from the pressure sensors is logged to see if the driver loosens their grip on the
steering wheel and this with the current and previous visiual data, time and temperature are
used to make the decision, "Is the driver asleep?"

Alarm Process

If the alarm is selected a signal is sent to the driver to increase their alertness
and the monitoring process begins again.If the alarm is not set the process begins again.

Hardware:

Live video feeds into the matlab code and pressure sensors need to be
calabrited for their inputs into the process.The code has been previously tested on recorded
footage only . This section needs to be developed further.

Eye Tracking

For the tracking to be successful and efficient at searching for the eyes between
frames, one can assume that the eyes, initially, do not move very much as this would be
typical of normal driver behaviour.

Once the pupils are found, the data is retained and the next frame uses the previous
frames data as a starting point for the search. The image need only be processed initially in
the area around the previous frames pupil locations, thus saving time and processing power.

Should the pupil search return negative in the current frame a full frame search will
commence. A negative result from this will be recorded and the next frame will be processed.
A negative result for a period of time with other data collected about the driver and
environment will result in an alarm to increase the drivers awareness.

ADVANTAGES:
19
Low cost.
Automated operation.
Low Power consumption.
It provides an automatic safety system for cars and other vehicles as well.

20
CHAPTER-4

SYSTEMANALYSIS

4.1 INTRODUCTION

In this section some of the relevant anatomical aspects of the eye are discussed to
give a good grounding of its role and functions. This includes a brief description of visual
fatigue symptoms that a driver can experience over long car journeys that can affect their
perceptiveness and concentration levels. In addition the relevancy of reaction times and the
undeniable link between sleep and road accidents is presented. The use of microprocessors in
vehicles is also discussed.

4.1.1 Eyes

The eye is a sensory organ which is used to detect contrast in objects illuminated
by light. The human eye has many components, but for the purpose of this report we will
look at the functions of the iris, pupil, sclera, cornea, retina, lens and their interactions with
each other.

The iris makes up the coloured part of the eye. Its function is to regulate the
amount of light that enters the eye. This is achieved by regulation of the pupil, the dark centre
spot in the iris which allows light to enter the eye.

21
Figure 4.1 Elements of the eye.

The pupillary sphincter muscle controls the size of the iris, automatically adjusting to
control the amount of light entering the eye. This action is known as the papillary reflex. In
low light the pupillary sphincter muscle causes the pupil to dilate allowing more light to enter
the eye and hit the retinal layer. The retina is the nerve layer that lines the back of the eye,
senses light and creates impulses that travel through the optic nerve to the brain.

Diameters of a healthy pupil in dim conditions can be enlarged to 8mm. In bright


light the pupillary sphincter muscle causes the iris to contract. This makes the pupil smaller,
in the region of 1.5mm, which allows the eye to function more efficiently in this condition. In
ambient light conditions a normal pupil will range from 3 to 4 mm in diameter.

The sclera is the outer protective layer of the eye. This layer is opaque and usually
white in healthy eyes. The optic nerve connects to the eye through this layer and muscles
attached to the sclera allow the eye to move.

The cornea is the transparent window of the eye. It sits over the pupil and iris,
transmitting and focusing light into the eye. Beneath the cornea is the lens, the transparent
structure inside the eye that focuses light rays onto the retina. The optic nerve connects the
eye to the brain. It transmits the electrical impulses from the retina to the visual cortex in the
brain.

After excessive stress on any of the functions of the eye, especially over long car
journeys, visual fatigue arises. The symptoms include painful irritation (burning) of the eye
accompanied by watering of the eye, reddening of the eye and conjunctivitis, double vision
and headaches. Visual fatigue also reduces the powers of accommodation and convergence of
the eye, sensitivity to contrast and speed of perception. All types of visual work can
contribute to visual fatigue. Driving calls for more rapid and precise eye movements which
make heavier demands on perception, concentration and motor control

4.1.2 Reactions

22
To create a system to inform and alert a driver they are suffering from fatigue and
are not in control of their vehicle, we must look at driver reaction to determine the most
appropriate method to do this.

According to Marc Green, University of West Virginia medical school, Human


perception & break reaction time studies, have reported a wide variety of results. The most
important variable is the drivers expectation. This affects reaction time by a factor of two. A
fully conscious driver can react, being fully aware of time and location in approximately 0.75
seconds. This can be doubled for unanticipated events, and cause a reaction time of around
1.55 seconds

These figures show that even when alert and awake, drivers can take some time to
react to events, especially to unexpected events. The studies presented show much of the data
has been collected for driver reaction to visual stimuli, this is somewhat irrelevant for the
purposes of this project as the driver will have their eyes closed and cannot respond to visual
marker.

Auditory signs do however improve a drivers reaction time but this is based on the
driver knowing the reaction, to then signal. As the driver would be fatigued this could
seriously impact the reaction time and compound the problem.

A solution to this is to use an audiovisual signal, using an audio signal to alert the
driver and a visual signal to trigger a learned response. One such response is to a tail break
light in front of the driver. Many drivers reported in the studies presented that they found
themselves depressing the break before they were cognitively aware of the break light in front
of them This is an example of a learned response which is automatic upon a trigger.

4.2 Sleep and Road Accidents

Road safety is a topic discussed almost every day in the papers and on our
airwaves in this country and worldwide, unfortunately though this is usually because of the
lack of safety and precaution taken by road users.

While dangerous and drunken driving may be highly publicised a major


contributing factor in many accidents on our roads is driver fatigue. According to the Road

23
Safety Authority, driving tired is as lethal as driving drunk .Up to 20% of fatal crashes may
be linked to driver fatigue, latest research indicates that driver fatigue could be a contributory
factor in up to a fifth of driver deaths in Ireland. It also means that this silent killer could have
been a contributory factor in almost 200 driver deaths in a five year period.

The critical points at which driver fatigue related collisions happen are between
2am and 6am and mid afternoon between 2pm and 4pm when our "circadian rhythm" or body
clock is at its lowest point. Males aged 18 to 30 are in the high risk category. They tend to be
over confident about their driving ability and believe they can handle the situation. Women
are less likely to be involved in sleep related crashes

If a driver persists in fighting sleep while driving, the impairment level is the same
as driving while over the drink drive limit. Eventually a driver will drift in and out of
consciousness and experience "micro sleeps" which can last for up to 10 seconds. In this time
a driver has no control of the vehicle. Drivers can experience such a micro sleep with their
eyes wide open.

Driver fatigue not only impairs driving in a similar way to alcohol it also
magnifies the damage alcohol does. It is estimated that alcohol is twice as potent in mid
afternoon and in the early hours of the morning because we are more likely to be tired at
these times. Consequently, people who think they are driving under the legal limit should be
aware that even small amounts of alcohol consumed at these key times, when we are tired,
combine to render a driver totally unfit for driving.

In a survey of drivers involved in accidents in Norway they were asked if sleep or


fatigue was a contributing factor in their accident. While only 3.9% of drivers who responded
and were at fault for their accident, admitted that fatigue was a contributing factor, this 3.9%
overall translates to a much higher figure for night time accidents , contributing to
approximately one fifth of accidents (18.9%).

Although not all instances of Driver Fatigue resulted in accidents, 10% of men and
4% of women who responded to the survey admitted to falling asleep at the wheel in the 12
months previous to the survey and 27% said that fallen asleep whilst driving at some point in
their driving lives.

24
Only 4% of these occurrences of driver fatigue resulted in accidents but 40%
reported crossing the boundary lines on the side of the road before regaining control and 16%
reported crossing the centre line of the road before regaining consciousness.

These figures show the increased safety risk of driving while fatigued. The drivers'
unawareness of the on-setting fatigue coupled with reluctance to rest is pointed out as likely
contributors to sleep-related accidents. This project aims to highlight to the driver that they
may be suffering from fatigue, thus removing these contributory factors.

Figure 2.2 shows a graphical breakdown of the reported occurrences of falling asleep whilst
driving.

Figure 2.2 Breakdown of results occurring from falling asleep while driving. Data Source

4.3 Vehicles and microprocessors

The integration of vehicles and microprocessors began on a very basic level in 1978
with the use of a modified 6802 chip in a Cadillac Seville, to drive the cars trip computer-a
system to display mileage and other information on the dashboard . From humble beginnings
their integration has come a long way and today almost every vehicle on the road contains

25
between 30 and 50 microprocessors, improving the safety, efficiency and control of their
vehicle.

Microprocessors control everything from electric windows and door locks to anti-
lock braking systems and airbags. Take ABS as an example. This is a system which prevents
the wheels of a vehicle locking when the driver breaks, giving greater control, which would
not be possible without the use of microprocessors. This system undoubtedly saves lives.

Microprocessors in vehicles improve efficiency in two ways; time efficiency,


finding out what is wrong with your vehicle can be determined far quicker, and also fuel
efficiency. This is monitored by the Engine Control Unit (ECU) [5] and subsequent
adjustments are made. The use of microprocessors has drastically changed and simplified the
control of cars and their operation, bulky electronic cables are now replaced with tiny chips
with far higher capabilities.

Nowadays microprocessors and vehicles truly do go hand in hand, the statistics


speak for themselves. On average, a new car carries almost 200 pounds of electronics and
more than a mile of wiring. There are microprocessors integrated into almost every aspect of
vehicles, they can be found in wing mirrors, headrests, and even wheel rims.

Aside from in-car entertainment which is developing rapidly, the future for
computers and cars looks very promising. Currently in development are innovations such as
wireless controls, i.e. wireless steering and a system to warn drivers if the air pressure in their
tyres drop. The development and integration of computer systems which improve driving
safety is a growth area with many new systems currently in design, this project giving
testament to this.

Another of these new safety systems in development is the fly by wire system.
This system imitates one used in modern aircraft, in which a fail-safe computer network will
allow the car in which it is implemented to steer and brake by wire. This, if implemented,
would mean changing the transmission technology of a vehicle from its mechanical and
hydraulic basis to electronic. The system would have speed and precision far greater than
previous technologies and could assist the driver in all situations in a matter of milliseconds.

26
CHAPTER-5

DESIGN AND IMPLEMENTATION

This section describes the components used in the implementation of the Driver
Fatigue Detection System. In addition the process of choosing some of the components is
discussed with analysis and reasoning behind omitting other components from the design.

Also discussed are the implementation decisions that were made and difficulties
encountered.

5.1 POWER SUPPLY:

Power supply is a supply of electrical power. A device or system that supplies electrical
or other types of energy to an output load or group of loads is called a power supply unit or PSU.
The term is most commonly applied to electrical energy supplies, less often to mechanical ones,
and rarely to others.

A power supply may include a power distribution system as well as primary or secondary
sources of energy such as:

Chemical fuel cells and other forms of energy storage systems.


Solar power and batteries.
Generators or alternators.
A brief description:
Transformer-steps down high voltage AC mains to low voltage AC
Rectifier-converts AC to DC, but the DC output is varying.

5.1.1 TRANSFORMER:
A suitable ready-built mains power supply unit, such as those used to control model
trains, will include a transformer. I wouldn't recommend building your own due to the safety

27
Considerations when dealing with mains voltages if such a unit does not incorporate
smoothing, rectification, and regulation, then you will need to build these blocks as
described in part 1 of this series. If the unit does not have a fuse or a cut-out on the output of
the transformer, you will also need to add a fuse of an appropriate rating. This fuse is in
addition to the mains fuse in the unit's plug and is needed to protect the low voltage winding
of the transformer and any circuits you connect to it. Although we won't be building the
transformer block of our 5V regulated power supply, it is interesting to know how it works.

5.1.2 RECTIFIER:

The purpose of a rectifier is to convert an AC waveform into a DC waveform. There are


two different rectification circuits, known as 'half-wave' and 'full-wave' rectifiers. Both use
components called diodes to convert AC into DC.

5.1.3 HALF-WAVE RECTIFIER:

The half-wave rectifier is the simplest type of rectifier since it only uses one diode, as
shown in figure

Fig 5.1: Half-wave rectifier

Figure 2 shows the AC input waveform to this circuit and the resulting output. As you can
see, when the AC input is positive, the diode is forward-biased and lets the current through.

28
Fig 4.8: Half-wave rectification

While the output of the half-wave rectifier is DC (it is all positive), it would not be suitable
as a power supply for a circuit.

5.1.4 FULL-WAVE RECTIFIER:

The circuit in figure 3 addresses the second of these problems since at no time is
the output voltage 0V.

Fig 5.2: Full-wave rectifier

29
Fig 5.3: Full-wave rectification

When the AC input is positive, diodes A and B are forward-biased, while diodes C and D are
reverse-biased. When the AC input is negative, the opposite is true - diodes C and D are
forward-biased, while diodes A and B are reverse-biased.

5.1.5 REGULATOR:
While there are many circuits that will tolerate a smoothed power supply, some must
have a completely regular supply with no ripple voltage.

THE 78XX SERIES OF REGULATORS:

There are many types of regulator IC and each type will have different
pin-outs and will need to be connected up slightly differently. Therefore, this article will
only look at one of the common ranges of regulator, the 78xx series.

Type Number Regulation Maximum Minimum


voltage current voltage

7805 +5V 1A +7V

7812 +12V 1A +14.5V

Table 4.2: Regulator voltage representation

30
If you are using a regulator after the smoothing block of the power supply, then you
shouldn't need to worry about the ripple voltage, since the whole point of using a regulator is
to get a stable, accurate, known voltage for your circuits.

Fig 5.4 : Wiring up a regulator IC

5.2 ALCOHOL DETECTION SENSOR:


The alcohol detector sensor used in our project is MQ-3 Sensor.

Fig 5.5: MQ-3 alcohol detection sensor

The features and applications of the alcohol sensor are as follows:


5.2.1 DESCRIPTION:
This alcohol sensor is suitable for detecting alcohol concentration on your breath, just
like your common breathalyzer. It has a high sensitivity and fast response time. Sensor provides

31
an analog resistive output based on alcohol concentration. The drive circuit is very simple, all it
needs is one resistor. A simple interface could be a 0-3.3V ADC.

5.2.2 FEATURES:
High sensitivity to alcohol and small sensitivity to benzene.
Fast response and high sensitivity.
Stable and long life.

5.2.3 APPLICATIONS:
They are suitable for alcohol checker, breath analyzer.

5.3 BUZZER:

A buzzer or beeper is a signaling device, usually electronic, typically used in


automobiles, household appliances such as a microwave oven, or game shows.

It most commonly consists of a number of switches or sensors connected to a control unit


that determines if and which button was pushed or a preset time has lapsed, and usually
illuminates a light on the appropriate button or control panel, and sounds a warning in the form
of a continuous or intermittent buzzing or beeping sound. Initially this device was based on an
electromechanical system which was identical to an electric bell without the metal gong . Often
these units were anchored to a wall or ceiling and used the ceiling or wall as a sounding board.
Another implementation with some AC-connected devices was to implement a circuit to make
the AC current into a noise loud enough to drive a loudspeaker and hook this circuit up to a
cheap 8-ohm speaker. Nowadays, it is more popular to use a ceramic-based piezoelectric
sounder like a Son alert which makes a high-pitched tone. Usually these were hooked up to
"driver" circuits which varied the pitch of the sound or pulsed the sound on and off.

32
In game shows it is also known as a "lockout system," because when one person signals
("buzzes in"), all others are locked out from signaling. Several game shows have large buzzer
buttons which are identified as "plungers".

The word "buzzer" comes from the rasping noise that buzzers made when they were
electromechanical devices, operated from stepped-down AC line voltage at 50 or 60 cycles.
Other sounds commonly used to indicate that a button has been pressed are a ring or a beep.

Fig 5.6: Buzzer

5.3.1 FEATURES:
These high reliability electromagnetic buzzers are applicable to automobile equipment.
Compact, pin terminal type electromagnetic buzzer with 2048Hz output.
Pin type terminal construction enables direct mounting onto printed circuit boards.

5.3.2 APPLICATIONS:
Clocks, travel watches, keyboards, toys, various alarms of automobile equipment.

5.4 CAMERA

A number of cameras were used in the development of this system. Each had
different advantages over each other.

The first camera used was a basic CMOS web cam with a picture resolution of
352x288 pixels. This was used to create test video, on which the initial versions of the Hough
transform were used to test. The camera images were quite small so there were obvious
advantages in the processing power which was relatively less than large still images. The

33
small image size however was a cause of difficulty also as the Hough transform results
proved difficult to analyse from the small amount of data that could be extracted from the
image about the eye, only a small number of pixels contained the information displaying the
circular iris.

Figure 5.7 Image of face using standard low resolution CMOS camera

The second camera used was an Omni vision CMOS camera fitted with a fish eye
lens. This camera had a higher resolution at 640x480 pixels per frame, this resolved the issue
of the previous cameras low resolution.

However, test data recorded using this camera, highlighted the importance of
adequate lighting on the subjects face, as shadows and varying light conditions proved
problematic in the detection of the eyes.

This camera was fitted with a fish eye lens which gave the image curvature
towards its edges, this is apparent from the skewed wall and ceiling edges in the background
of figure 4.2. The curvature was at its least in the centre of the image where the subjects face
was being tracked, despite this it was hazardous to introduce such variances in the system
given that the aim of the image capture was to detect circles. Allowing for straight lines to
gain curvature in the photo was deemed unwise and for this reason the camera was not used
in the project.

34
Figure 5.8 taken using Omni vision CMOS camera with fish eye lens

The last camera to be test with the system was a high-resolution CMOS web cam
with a manually variable focus lens. This was similar to the first camera used but had the
higher resolution of 1028 x 840.

This camera also implemented a face tracking system which could be run in
parallel with the fatigue detection system. This involved a digital zoom to the region of the
face and output this frame to the fatigue detection system which allowed for the redundancy
of much of the pre-cropping of the image. This solved the issue of initial face detection as the
camera software would always deliver the facial image to the system provided the subject
stayed within the range of the high-resolution image.

Figure 5.9 Image taken using standard CMOS high resolution camera
Because of the difficulties encountered with shadows hiding the eyes in the eye
sockets under ambient light conditions, thus an IR (Infrared) camera was considered as an
image source for low light conditions.

These cameras would perform under ambient light conditions in a similar manner
to the cameras previously discussed but in low light conditions it would provide a workable

35
solution to this difficulty. Applying an IR light source to illuminate the subjects face would
allow the IR camera to capture the necessary facial data to apply eye detection on the image.
As IR light is outside the electro magnetic wavelength range of visible light, the subject
would be unaware of this illumination. In addition this would not cause the discomfort to the
driver whilst driving at night that illumination by light in the visible spectrum would cause.

Another advantage of the IR system is the reflection of IR light from the eyes. This
is a result of the eyes inability to absorb or diffuse all of the IR light as it can do with visible
light. This is the reason why the pupil has a black appearance. The reflection of the IR light
causes the pupils to be visible as bright, white, luminescent points in the eye. Figure 4.4
shows this effect of IR light. This would allow for easier processing of the image as the eye
detection process would give more consistent results in many lighting conditions.

It was also noted that the IR light reflection from the eye would be dependant on
the camera and the IR light source being on the same axis as the eye, i.e. the camera and IR
light source would be directly in front of the subjects eye. Considering the area of application
for this project, this was a major difficulty as the camera would obstruct the drivers vision of
the road ahead. This is discussed further in Real Time Visual Cues Extraction for Monitoring
Driver Vigilance by Qiang Ji and Xiaojie Yang

It was decided to retain the standard CMOS camera in an effort to develop the
algorithm for use with this type of technology as much as possible despite its limitations.

Fig 5.10: Image showing difference between (A) un-illuminated pupil captured with IR
camera and (B) illuminated pupil showing reflected IR light. Image Source

36
5.5 LCD:

Fig 5.11: LCD display

LCD (Liquid Crystal Display) screen is an electronic display module and find a wide
range of applications. A 16x2 LCD display is very basic module and is very commonly used in
various devices and circuits. These modules are preferred over seven segments and other multi
segment LEDs. The reasons being: LCDs are economical; easily programmable; have no
limitation of displaying special & even custom characters (unlike in seven segments).

A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In
this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely,
Command and Data.

5.6 MOTORS:

The speed of a DC motor is directly proportional to the supply voltage, so if we reduce


the supply voltage from 12 Volts to 6 Volts, the motor will run at half the speed. How can this
be achieved when the battery is fixed at 12 Volts.

Fig 5.12: Motor

37
The speed controller works by varying the average voltage sent to the motor. It could do this
by simply adjusting the voltage sent to the motor, but this is quite inefficient to do. A better way
is to switch the motors supply on and off very quickly. If the switching is fast enough, the
motor doesnt notice it, it only notices the average effect.

5.7 LM35 (Temperature sensor)

The LM35 series are precision integrated-circuit temperature sensors, whose


output voltage is linearly proportional to the Celsius (Centigrade) temperature. The
LM35 thus has an advantage over linear temperature sensors calibrated in Kelvin, as
the user is not required to subtract a large constant voltage from its output to obtain
convenient Centi- grade scaling. The LM35 does not require any external calibration
or trimming to provide typical accuracies of 14C at room temperature and 34C
over a full 55 to +150C temperature range. Low cost is assured by trimming and
calibration at the wafer level. The LM35s low output imped- ance, linear output, and
precise inherent calibration make interfacing to readout or control circuitry especially
easy. It can be used with single power supplies, or with plus and minus supplies. As it
draws only 60 A from its supply, it has very low self-heating, less than 0.1C in still air.
The LM35 is rated to operate over a 55 to +150C temperature range, while the LM35C
is rated for a 40 to +110C range (10 with improved accuracy). The LM35 series is
available pack-aged in hermetic TO-46 transistor packages, while the LM35C,
LM35CA, and LM35D are also available in the plastic TO-92 transistor package. The
LM35D is also avail- able in an 8-lead surface mount small outline package and a plastic
TO-220 package.

5.7.1 FEATURES

1. Calibrated directly in Celsius (Centigrade)


2. Linear + 10.0 mV/C scale factor
3. 0.5C accuracy guaranteeable (at +25C)
4. Rated for full 55 to +150C range
5. Suitable for remote applications
6. Low cost due to wafer-level trimming

38
7. Operates from 4 to 30 volts
8. Less than 60 A current drain
9. Low self-heating, 0.08C in still air
10. Nonlinearity only 14C typical
11. Low impedance output, 0.1 for 1 mA load

5.7.2 Block Diagram

The LM35 can be applied easily in the same way as other integrated-circuit
temperature s e n s o r s . It can be glued or cemented to a surface and its temperature will
be within about 0.01C of the surface temperature.

This presumes that the ambient air temperature is almost the same as the surface
temperature; if the air temperature were much higher or lower than the surface
temperature, the actual temperature of the LM35 die would be at an intermediate temperature
between the surface temperature and the air temperature. This is especially true for the TO-
92 plastic package, where the copper leads are the principal thermal path to carry heat into
the device, so its temperature might be closer to the air temperature than to the surface
tempera- true.

To minimize this problem, be sure that the wiring to the LM35, as it leaves the
device, is held at the same tempera- ture as the surface of interest. The easiest way to do this

39
is to cover up these wires with a bead of epoxy which will insure that the leads and
wires are all at the same tempera- ture as the surface, and that the LM35 dies temperature
will not be affected by the air temperature.

The TO-46 metal package can also be soldered to a metal surface or pipe without
damage. Of course, in that case the V terminal of the circuit will be grounded to that
metal. Alternatively, the LM35 can be mounted inside a sealed-end metal tube, and can then
be dipped into a bath or screwed into a threaded hole in a tank. As with any IC, the LM35
and accompanying wiring and circuits must be kept insulated and dry, to avoid leakage and
corrosion. This is especially true if the circuit may operate at cold temperatures where
condensation can occur. Printed-circuit coatings and varnishes such as Humiseal a n d epoxy
paints or dips are often used to insure that moisture cannot corrode the LM35 or its
connections.

These devices are sometimes soldered to a small light-weight heat fin, to


decrease the thermal time constant and speed up the response in slowly-moving air. On
the other hand, a small thermal mass may be added to the sensor, to give the steadiest
reading despite small deviations in the air temperature.

5.8 MCP3208
The MCP3208 12-bit Analog-to-Digital Converter (ADC) combines high performance
and low power consumption in a small package, making it ideal for embedded control
applications. The MCP3208 features a successive approximation register (SAR) architecture and
an industry-standard SPI serial interface, allowing 12-bit ADC capability to be added to any
PIC micro microcontroller. The MCP3208 features 100k samples/second, 8 input channels,
low power consumption (5nA typical standby, 400 A max.active), and is available in 16-pin
PDIP and SOIC packages. Applications for the MCP3208 include data acquisition,
instrumentation and measurement, multi-channel data loggers, industrial PCs, motor control,
robotics, industrial automation, smart sensors, portable instrumentation and home medical

40
Features

12-bit resolution
Eight single-ended inputs
SPI interface
1 LSB DNL
1 LSB INL
100 ksps sample
-40 to +85C temperature range

5.9 ARM 7 Microcontroller


5.9.1 INTRODUCTION:

The ARM was originally developed at Acorn Computers Limited of Cambridge ,


England, between 1983 and 1985. It was the first RISC microprocessor developed for
commercial use and has some significant differences from subsequent RISC architectures. In
1990 ARM Limited was established as a separate company specifically to widen the exploitation
of ARM technology and it is established as a market-leader for low-power and cost-sensitive
embedded applications. The ARM is supported by a toolkit which includes an instruction set
emulator for hardware modelling and software testing and benchmarking, an assembler, C and
C++ compilers, a linker and a symbolic debugger.

41
The 16-bit CISC microprocessors that were available in 1983 were slower than standard memory
parts. They also had instructions that took many clock cycles to complete (in some cases, many
hundreds of clock cycles), giving them very long interrupt latencies.As a result of these
frustrations with the commercial microprocessor offerings, the design of a proprietary
microprocessor was considered and ARM chip was designed.

5.9.2 ARM 7TDMI-S Processor :


The ARM7TDMI-S processor is a member of the ARM family of general-purpose 32-bit
microprocessors. The ARM family offers high performance for very low-power consumption
and gate count. The ARM7TDMI-S processor has a Von Neumann architecture, with a single
32-bit data bus carrying both instructions and data. Only load, store, and swap instructions can
access data from memory. The ARM7TDMI-S processor uses a three stage pipeline to increase
the speed of the flow of instructions to the processor. This enables several operations to take
place simultaneously, and the processing, and memory systems to operate continuously. In the
three-stage pipeline the instructions are executed in three stages.

The three stage pipelined architecture of the ARM7 processor is shown in the above figure.
ARM7TDMIS stands for
T: THUMB
D for on-chip Debug support, enabling the processor to halt in response to a debug request,
M: enhanced Multiplier, yield a full 64-bit result, high performance
I: Embedded ICE hardware (In Circuit emulator)
S : Synthesizable

42
5.9.3 FEATURES OF ARM PROCESSORS

The ARM processors are based on RISC architectures and this architecture has provided
small implementations, and very low power consumption. Implementation size, performance,
and very low power consumption remain the key features in the development of the ARM
devices.

The typical RISC architectural features of ARM are :

A large uniform register file


A load/store architecture, where data-processing operations only operate on register
contents, not directly on memory contents
Simple addressing modes, with all load/store addresses being determined from register
contents and instruction fields only uniform and fixed-length instruction fields, to
simplify instruction decode.
Control over both the Arithmetic Logic Unit (ALU) and shifter in most data-processing
instructions to maximize the use of an ALU and a shifter
Auto-increment and auto-decrement addressing modes to optimize program loops
Load and Store Multiple instructions to maximize data throughput
Conditional execution of almost all instructions to maximize execution throughput.
There are three basic instruction sets for ARM.
A 32- bit ARM instruction set
A 16 bit Thumb instruction set and
The 8-bit Java Byte code used in Jazelle state
The Thumb instruction set is a subset of the most commonly used32-bit ARM
instructions.Thumb instructions operate with the standard ARM register configurations
,enabling excellent interoperability between ARM and Thumb states.This Thumb state is nearly
65% of the ARM code and can provide 160%of the performance of ARM code when working
ona 16-bit memory system. This Thumb mode is used in embedded systems where memory
resources are limited. The Jazelle mode is used in ARM9 processor to work with 8-bit Java
code.

43
5.9.4 ARCHITECTURE OF ARM PROCESSORS:
The ARM 7 processor is based on Von Neman model with a single bus for both data and
instructions..( The ARM9 uses Harvard model).Though this will decrease the performance of
ARM, it is overcome by the pipe line concept. ARM uses the Advanced Microcontroller Bus
Architecture (AMBA) bus architecture. This AMBA include two system buses: the AMBA
High-Speed Bus (AHB) or the Advanced System Bus (ASB), and the Advanced Peripheral Bus
(APB).
The ARM processor consists of
Arithmetic Logic Unit (32-bit)
One Booth multiplier(32-bit)
One Barrel shifter
One Control unit
Register file of 37 registers each of 32 bits.
In addition to this the ARM also consists of a Program status register of 32 bits, Some
special registers like the instruction register, memory data read and write register and
memory address register ,one Priority encoder which is used in the multiple load and
store instruction to indicate which register in the register file to be loaded or stored and
Multiplexers etc.

44
Fig 5.13 : Architecture
ARM Registers :
ARM has a total of 37 registers .In which - 31 are general-purpose registers of 32-bits,
and six status registers .But all these registers are not seen at once. The processor state and
operating mode decide which registers are available to the programmer. At any time, among
the 31 general purpose registers only 16 registers are available to the user. The remaining 15
registers are used to speed up exception processing. there are two program status registers:
CPSR and SPSR (the current and saved program status registers, respectively
In ARM state the registers r0 to r13 are orthogonalany instruction that you can apply to r0
you can equally well apply to any of the other registers.

45
The main bank of 16 registers is used by all unprivileged code. These are the User mode
registers. User mode is different from all other modes as it is unprivileged. In addition to this
register bank ,there is also one 32-bit Current Program status Register(CPSR)

In the 15 registers ,the r13 acts as a stack pointer register and r14 acts as a link register and r15
acts as a program counter register. Register r13 is the sp register ,and it is used to store the
address of the stack top. R13 is used by the PUSH and POP instructions in T variants, and by
the SRS and RFE instructions from ARMv6.

Register 14 is the Link Register (LR). This register holds the address of the next
instruction after a Branch and Link (BL or BLX) instruction, which is the instruction used to
make a subroutine call. It is also used for return address information on entry to exception
modes. At all other times, R14 can be used as a general-purpose register.
Register 15 is the Program Counter (PC). It can be used in most instructions as a pointer to the
instruction which is two instructions after the instruction being executed.
The remaining 13 registers have no special hardware purpose.
CPSR :
The ARM core uses the CPSR register to monitor and control internal operations. The
CPSR is a dedicated 32-bit register and resides in the register file. The CPSR is divided into
four fields, each of 8 bits wide : flags, status, extension, and control. The extension and status
fields are reserved for future use. The control field contains the processor mode, state, and
interrupt mask bits. The flags field contains the condition flags. The 32-bit CPSR register is
shown below.

46
Processor Modes:
There are seven processor modes .Six privileged modes abort, fast interrupt request,
interrupt request, supervisor, system, and undefined and one non-privileged mode called user
mode.
The processor enters abort mode when there is a failed attempt to access memory. Fast interrupt
request and interrupt request modes correspond to the two interrupt levels available on the ARM
processor. Supervisor mode is the mode that the processor is in after reset and is generally the
mode that an operating system kernel operates in. System mode is a special version of user mode
that allows full read-write access to the CPSR. Undefined mode is used when the processor
encounters an instruction that is undefined or not supported by the implementation. User mode is
used for programs and applications.
Banked Registers :
Out of the 32 registers , 20 registers are hidden from a program at different times. These
registers are called banked registers and are identified by the shading in the diagram. They are
available only when the processor is in a particular mode; for example, abort mode has banked
registers r13_abt , r14_abt and spsr _abt. Banked registers of a particular mode are denoted by
an underline character post-fixed to the mode mnemonic or _mode.
When the T bit is 1, then the processor is in Thumb state. To change states the core executes a
specialized branch instruction and when T= 0 the processor is in ARM state and executes ARM
instructions. There are two interrupt request levels available on the ARM processor core
interrupt request (IRQ) and fast interrupt request (FIQ).

V, C , Z , N are the Condition flags .

V (oVerflow) : Set if the result causes a signed overflow


C (Carry) : Is set when the result causes an unsigned carry
47
Z (Zero) : This bit is set when the result after an arithmetic operation is zero, frequently
used to indicate equality
N (Negative) : This bit is set when the bit 31 of the result is a binary 1.

PIPE LINE :
Pipeline is the mechanism used by the RISC processor to execute instructions at an
increased speed. This pipeline speeds up execution by fetching the next instruction while other
instructions are being decoded and executed. During the execution of an instruction ,the
processor Fetches the instruction .It means loads an instruction from memory.And decodes the
instruction i.e identifies the instruction to be executed and finally Executes the instruction and
writes the result back to a register.
The ARM7 processor has a three stage pipelining architecture namely Fetch , Decode and
Execute.And the ARM 9 has five stage Pipe line architecture.The three stage pipelining is
explained as below.

To explain the pipelining ,let us consider that there are three instructions Compare, Subtract and
Add.The ARM7 processor fetches the first instruction CMP in the first cycle and during the
second cycle it decodes the CMP instruction and at the same time it will fetch the SUB
instruction. During the third cycle it executes the CMP instruction , while decoding the SUB
instruction and also at the same time will fetch the third instruction ADD. This will improve the

48
speed of operation. This leads to the concept of parallel processing .This pipeline example is
shown in the following diagram.

As the pipeline length increases, the amount of work done at each stage is reduced, which allows
the processor to attain a higher operating frequency. This in turn increases the performance. One
important feature of this pipeline is the execution of a branch instruction or branching by the
direct modification of the PC causes the ARM core to flush its pipeline.

Exceptions, Interrupts, and the Vector Table :

Exceptions are generated by internal and external sources to cause the ARM processor to
handle an event, such as an externally generated interrupt or an attempt to execute an Undefined
instruction. The processor state just before handling the exception is normally preserved so that
the original program can be resumed after the completion of the exception routine. More than
one exception can arise at the same time.ARM exceptions may be considered in three groups
1. Exceptions generated as the direct effect of executing an instruction.Software interrupts,
undefined instructions (including coprocessor instructions where the requested coprocessor is
absent) and prefetch aborts (instructions that are invalid due to a memory fault occurring during
fetch) come under this group.
2. Exceptions generated as a side-effect of an instruction.Data aborts (a memory fault during a
load or store data access) are in this group.
3. Exceptions generated externally, unrelated to the instruction flow.Reset, IRQ and FIQ are in
this group.

49
The ARM architecture supports seven types of exceptions.
i.Reset
ii.Undefined Instruction
iii.Software Interrupt(SWI)
iv. Pre-fetch abort(Instruction Fetch memory fault)
v.Data abort (Data access memory fault)
vi. IRQ(normal Interrupt)
vii. FIQ (Fast Interrupt request).
When an Exception occurs , the processor performs the following sequence of actions:
It changes to the operating mode corresponding to the particular exception.
It saves the address of the instruction following the exception entry instruction in r14 of the
new mode.
It saves the old value of the CPSR in the SPSR of the new mode.
It disables IRQs by setting bit 7 of the CPSR and, if the exception is a fast interrupt, disables
further fast interrupts by setting bit 6 of the CPSR.
It forces the PC to begin executing at the relevant vector address

Excdption / Interrupt Name Address High Address


Reset RESET 0X00000000 0Xffff0000
Undefined Instruction UNDEF 0X00000004 0Xffff0004
Software Interrupt SWI 0X00000008 0Xffff0008
Pre-fetch Abort PABT 0X0000000C 0Xffff000c
Data Abort DABT 0X00000010 0Xffff0010
Reserved --- 0X00000014 0Xffff0014
Interrupt Request IRQ 0X00000018 0Xffff0018
Fast Interrupt Request FIQ 0X0000001C 0Xffff001c

The exception Vector table shown above gives the address of the subroutine program to
be executed when the exception or interrupt occurs. Each vector table entry contains a form of
branch instruction pointing to the start of a specific routine.

50
Reset vector is the location of the first instruction executed by the processor when power
is applied. This instruction branches to the initialization code.

Undefined instruction vector is used when the processor cannot decode an instruction.

Software interrupt vector is called when you execute a SWI instruction. The SWI instruction is
frequently used as the mechanism to invoke an operating system routine.

Pre-fetch abort vector occurs when the processor attempts to fetch an instruction from an address
without the correct access permissions. The actual abort occurs in the decode stage.
Data abort vector is similar to a prefetch abort but is raised when an instruction attempts to
access data memory without the correct access permissions.

Interrupt request vector is used by external hardware to interrupt the normal execution flow of
the processor. It can only be raised if IRQs are not masked in the CPSR.

ARM Processor Families

There are various ARM processors available in the market for different application
.These are grouped into different families based on the core .These families are based on the
ARM7, ARM9, ARM10, and ARM11 cores. The numbers 7, 9, 10, and 11 indicate different
core designs. The ascending number indicates an increase in performance and sophistication.
Though ARM 8 was introduced during 1996, it is no more available in the market. The
following table gives a brief comparison of their performance and available resources.

The ARM7 core has a Von Neumannstyle architecture, where both data and instructions
use the same bus. The core has a three-stage pipeline and executes the architecture ARMv4T
instruction set. The ARM7TDMI was introduced in 1995 by ARM. It is currently a very popular
core and is used in many 32-bit embedded processors.

The ARM9 family was released in 1997. It has five stage pipeline architecture .Hence ,
the ARM9 processor can run at higher clock frequencies than the ARM7 family. The extra
stages improve the overall performance of the processor. The memory system has been
redesigned to follow the Harvard architecture, with separate data and instruction .buses. The first
processor in the ARM9 family was the ARM920T, which includes a separate D + I cache and an

51
MMU. This processor can be used by operating systems requiring virtual memory support.
ARM922T is a variation on the ARM920T but with half the D +I cache size.
The latest core in the ARM9 product line is the ARM926EJ-S synthesizable processor
core, announced in 2000. It is designed for use in small portable Java-enabled devices such as
3G phones and personal digital assistants (PDAs).

The ARM10 was released in 1999 . It extends the ARM9 pipeline to six stages. It also
supports an optional vector floating-point (VFP) unit, which adds a seventh stage to the ARM10
pipeline. The VFP significantly increases floating-point performance and is compliant with the
IEEE 754.1985 floating-point standard.
The ARM1136J-S is the ARM11 processor released in the year 2003 and it is designed
for high performance and power efficient applications. ARM1136J-S was the first processor
implementation to execute architecture ARMv6 instructions. It incorporates an eight-stage
pipeline with separate load store and arithmetic pipelines.
A brief comparison of different ARM families is presented below.

ARM Year of Architecture Pipeline Operational Multiplier MIPS


Family Release Frequency
ARM7 1995 Von Neumann 3 stage 80 M.Hz 8x32 0.97
ARM9 1997 Harvard 5 stage 150M.Hz 8x32 1.1
ARM10 1999 Harvard 6 stage 260M.Hz 16x32 1.3
ARM11 2003 Harvard 8 stage 335M.Hz 16x32 1.2

ARM INSTRUCTION SET


ARM instructions process data held in registers and only access memory with load and
store instructions. ARM instructions commonly take two or three operands.
For example ,the ADD instruction adds the two values stored in registers r1 and r2 (the source
registers). It stores the result to register r3 (the destination register). ADD r3, r1, r2

52
ARM instructions are classified into data processing instructions, branch instructions, load-store
instructions, software interrupt instruction, and program status register instructions.

Data Processing Instructions :


The data processing instructions manipulate data within registers. They are move
instructions, Arithmetic instructions, logical instructions, comparison instructions, and multiply
instructions. Most data processing instructions can process one of their operands using the barrel
shifter.

Data processing instructions are processed within the arithmetic logic unit (ALU). A
unique and powerful feature of the ARM processor is the ability to shift the 32-bit binary pattern
in one of the source registers left or right by a specific number of positions before it enters the
ALU. This shift increases the power and flexibility of many data processing operations.

There are data processing instructions that do not use the barrel shift, for example, the
MUL (multiply), CLZ (count leading zeros), and QADD (signed saturated 32-bit add)
instructions.

i. Move Instructions :
Move instruction copies R into a destination register Rd, where R is a register or
immediate value. This instruction is useful for setting initial values and transferring data between
registers.

Example1 : PRE r5 = 5
r7 = 8
MOV r7, r5 ;
POST r5 = 5
r7 = 5

The MOV instruction takes the contents of register r5 and copies them into register r7.
Example 2: MOVS r0, r1, LSL #1

MOVS instruction shifts register r1 left by one bit

53
Arithmetic Instructions :
The arithmetic instructions implement addition and subtraction of 32-bit signed and
unsigned values. the various addition and subtraction instructions are given in table below.

SUB r0, r1, r2 ; This subtract instruction subtracts a value stored in register r2 from a value
stored in register r1. The result is stored in register r0.

RSB r0, r1, #0 ; This reverse subtract instruction (RSB) subtracts r1 from the constant value #0,
writing. the result to r0. You can use this instruction to negate numbers.

SUBS r1, r1, #1 ; The SUBS instruction is useful for decrementing loop counters. In this
example we subtract the immediate value one from the value one stored in
register r1. The result value zero is written to register r1.

Logical Instructions :
These Logical instructions perform bitwise logical operations on the two source registers.

BIC r0, r1, r2 ; BIC, carries out a logical bit clear. register r2 contains a binary pattern where
every binary 1 in r2 clears a corresponding bit location in register r1. This instruction is
particularly useful when clearing status bits and is frequently used to change interrupt masks in
the cpsr.

54
Comparison Instructions :
The comparison instructions are used to compare or test a register with a 32-bit value.
This instruction affects only CPSR register flags.

Branch Instructions: A branch instruction changes the normal flow of execution of a main
program or is used to call a subroutine routine. This type of instruction allows programs to have
subroutines, if-then-else structures, and loops. The change of execution flow forces the program
counter pc to point to a new address.
Example 1: B forward ; (unconditional branch to forward)

ADD r1, r2, #4 ;

ADD r0, r6, #2 ;

ADD r3, r7, #4 ;

forward SUB r1, r2, #4 ;

Similarly Backward branch :

backward : ADD r1, r2, #4 ;

SUB r1, r2, #4 ;

ADD r4, r6, r7 ;

B backward ; branch to the target backward.

The branch with link, or BL, instruction is similar to the B instruction but overwrites the

link register lr with a return address. It performs a subroutine call.

BL subroutine ; branch to subroutine

CMP r1, #5 ; compare r1 with 5

55
MOVEQ r1, #0 ; if (r1==5) then r1 = 0 :

Subroutine

MOV pc, lr ; return by moving pc = lr

The Branch Exchange (BX) and Branch Exchange with Link (BLX) are the third type of branch instruction.
The BX instruction uses an absolute address stored in register Rm. It is primarily used to branch to and
from Thumb code. The T bit in the cpsr is updated by the least significant bit of the branch register.
Similarly the BLX instruction updates the T bit of the cpsr with the least significant bit and additionally
sets the link register with the return address.

The details of the branch instructions are given in the table above.

Load-Store Instructions : Load-store instructions transfer data between memory and processor
registers. There are three types of load-store instructions:

Single-register transfer
Multiple-register transfer, and
Swap.
Single-Register Transfer : These instructions are used for moving a single data item in and out of a
register. The data types supported are signed and unsigned words (32-bit), half-words (16-bit), and
bytes. Ex1: STR r0, [r1] ; = STR r0, [r1, #0] ; store the contents of register r0 to the
memory address pointed to by register r1.

56
Ex2 : LDR r0, [r1] ; = LDR r0, [r1, #0] ; load register r0 with the contents of the

memory address pointed to by register r1.

Multiple-Register Transfer :

Load-store multiple instructions can transfer multiple registers between memory and the
processor in a single instruction. The transfer occurs from a base address register Rn pointing
into memory. Multiple-register transfer instructions are more efficient than single-register
transfers for moving blocks of data around memory and saving and restoring context and stacks.

Load-store multiple instructions can increase interrupt latency. ARM implementations do


not usually interrupt instructions while they are executing. For example, on an ARM7 a load
multiple instruction takes 2 + N.t cycles, where N is the number of registers to load and t is the
number of cycles required for each sequential access to memory. If an interrupt has been raised,
then it has no effect until the load-store multiple instruction is complete.

Example 1: LDMIA r0!, {r1-r3} ; In this example, register r0 is the base register Rn and is
followed by !, indicating that the register is updated after the instruction is executed. In this case
the range is from register r1 to r3.

Example 2 : LDMIB : load multiple and increment before

Ex 3: LDMIB r0!, {r1-r3} ;

Ex 4 : LDMDA r0!, {r1-r3}

Stack Operations :

The ARM architecture uses the load-store multiple instructions to carry out stack
operations. The pop operation (removing data from a stack) uses a load multiple instruction;
similarly, the push operation (placing data onto the stack) uses a store multiple instruction.

A stack is either ascending (A) or descending (D). Ascending stacks grow towards higher
memory addresses; in contrast, descending stacks which grow towards lower memory addresses.
When a full stack (F)is used , the stack pointer sp points to an address that is the last used or full
location (i.e., sp points to the last item on the stack). In contrast, if an empty stack (E) is used ,
the sp points to an address that is the first unused or empty location (i.e., it points after the last
item on the stack).

57
Example1 : The STMFD instruction pushes registers onto the stack, updating the sp.

STMFD sp! , {r1,r4}; Store Multiple Full Descending Stack

PRE r1 = 0x00000002

r4 = 0x00000003

sp = 0x00080014

POST r1 = 0x00000002

r4 = 0x00000003

sp = 0x0008000c.

The stack operation is shown by the following diagram.

Example2: The STMED instruction pushes the registers onto the stack but updates register sp to
point to the next empty location as shown in the below diagram..

PRE r1 = 0x00000002

r4 = 0x00000003

sp = 0x00080010

STMED sp! , {r1,r4} ; Store Multiple Empty Descending Stack

POST r1 = 0x00000002

r4 = 0x00000003

sp = 0x00080008

This operation is explained in the following figure.

58
Swap Instruction :

The Swap instruction is a special case of a load-store instruction. It swaps (Similar to exchange)
the contents of memory with the contents of a register. This instruction is an atomic operation
it reads and writes a location in the same bus operation, preventing any other instruction from
reading or writing to that location until it completes.Swap cannot be interrupted by any other
instruction or any other bus access. So, the system holds the bus until the transaction is
complete.
Ex 1: SWP : Swap a word between memory and a register tmp = mem32[Rn]
mem32[Rn] =Rm
Rd = tmp

Ex2 : SWPB Swap a byte between memory and a register tmp = mem8[Rn]
mem8[Rn] =Rm
Rd = tmp.

Ex 3: SWP r0, r1, [r2] ; The swap instruction loads a word from memory into register
r0 and overwrites the memory with register r1.

Software Interrupt Instruction : A software interrupt instruction (SWI) is used to generate a


software interrupt exception, which can be used to call operating system routines.When the
processor executes an SWI instruction, it sets the program counter pc to the offset 0x8 in the
vector table. The instruction also forces the processor mode to SVC, which allows an operating
system routine to be called in a privileged mode. Each SWI instruction has an associated SWI
number, which is used to represent a particular function call or feature.

59
Ex: 0x00008000 SWI 0x123456

Here 0x123456, is the SWI number used by ARM toolkits as a debugging SWI.
Typically the SWI instruction is executed in user mode.

Program Status Register Instructions : There are two instructions available to directly control
a program status register (PSR). The MRS instruction transfers the contents of either the CPSR
or SPSR into a register.Similarly the MSR instruction transfers the contents of a register into
the CPSR or SPSR .These instructions together are used to read and write the CPSR and
SPSR.
MRS : copy program status register to a general-purpose register , Rd= PSR
MSR : move a general-purpose register to a program status register, PSR[field]=Rm
MSR : move an immediate value to a program status register, PSR[field]=immediate

Ex : MRS r1, CPSR


BIC r1, r1, #0x80 ; 0b01000000
MSR CPSR_C, r1.
The MSR first copies the CPSR into register r1. The BIC instruction clears bit 7 of r1. Register
r1 is then copied back into the CPSR, which enables IRQ interrupts. Here the code preserves all
the other settings in the CPSR intact and only modifies the I bit in the control field.
Loading Constants : In ARM instruction set there are no instructions to move the 32-bit
constant into a register. Since ARM instructions are 32 bits in size, they obviously cannot
specify a general 32-bit constant. To overcome this problem .two pseudo instructions are
provided to move a 32-bit value into a register.
LDR : load constant pseudo instruction Rd= 32-bit constant.
ADR : load address pseudo instruction Rd=32-bit relative address.
The first pseudo instruction writes a 32-bit constant to a register using whatever instructions are
available.
The second pseudo instruction writes a relative address into a register, which will be encoded
using a PC -relative expression.
Example 2: LDR r0, [pc, #constant_number-8-{PC}]

constant _number DCD 0xff00ffff.

60
Here the LDR instruction loads a 32-bit constant 0xff00ffff into register r0.

Example 3: The same constant can be loaded into the register r0 using the MVN instruction also.
MVN r0, #0x00ff0000
After execution r0 = 0xff00ffff.

5.9.5 Introduction to Thumb instruction set :


Thumb encodes a subset of the 32-bit ARM instructions into a 16-bit instruction set
space. Since Thumb has higher performance than ARM on a processor with a 16-bit data bus,
but lower performance than ARM on a 32-bit data bus, use Thumb for memory-constrained
systems. Thumb has higher code densitythe space taken up in memory by an executable
programthan ARM. For memory-constrained embedded systems, for example, mobile phones
and PDAs, code density is very important. Cost pressures also limit memory size, width, and
speed.
Thumb execution is flagged by the T bit (bit [5] ) in the CPSR. A Thumb implementation of the
same code takes up around 30% less memory than the equivalent ARM implementation. Even
though the Thumb implementation uses more instructions ; the overall memory footprint is
reduced. Code density was the main driving force for the Thumb instruction set. Because it was
also designed as a compiler target, rather than for hand-written assembly code. Below example
explains the difference between ARM and Thumb code

61
From the above example it is clear that the Thumb code is more denser than the ARM code.
Exceptions generated during Thumb execution switch to ARM execution before executing the
exception handler . The state of the T bit is preserved in the SPSR, and the LR of the exception
mode is set so that the normal return instruction performs correctly, regardless of whether the
exception occurred during ARM or Thumb execution.
In Thumb state, all the registers can not be accessed . Only the low registers r0 to r7 can be
accessed. The higher registers r8 to r12 are only accessible with MOV, ADD, or CMP
instructions. CMP and all the data processing instructions that operate on low registers update
the condition flags in the CPSR
The list of registers and their accessibility in Thumb mode are shown in the following table..

S.No Registers Access


1 r0 r7 Fully accessible
2 r8 r12 Only accessible by MOV ,ADD &CMP
3 r13SP Limited accessibility
4 r14 lr Limited accessibility
5 r15 PC Limited accessibility
6 CPSR Only indirect access
7 SPSR No access

Form the above discussion, it is clear that there are no MSR and MRS equivalent Thumb
instructions. To alter the CPSR or SPSR , one must switch into ARM state to use MSR and
MRS. Similarly, there are no coprocessor instructions in Thumb state. You need to be in ARM
state to access the coprocessor for configuring cache and memory management.

ARM-Thumb interworking is the method of linking ARM and Thumb code together for both
assembly and C/C++. It handles the transition between the two states. To call a Thumb routine
from an ARM routine, the core has to change state. This is done with the T bit of CPSR . The
BX and BLX branch instructions cause a switch between ARM and Thumb state while
branching to a routine. The BX lr instruction returns from a routine, also with a state switch if
necessary.

62
The data processing instructions manipulate data within registers. They include move
instructions, arithmetic instructions, shifts, logical instructions, comparison instructions, and
multiply instructions. The Thumb data processing instructions are a subset of the ARM data
processing instructions.

Exs : ADC : add two 32-bit values and carry Rd = Rd + Rm + C flag


ADD : add two 32-bit values Rd = Rn + immediate
Rd = Rd + immediate
Rd = Rd + Rm

AND : logical bitwise AND of two 32-bit values Rd = Rd & Rm


ASR : arithmetic shift right Rd = Rm_immediate,
C flag= Rm[immediate 1]
Rd = Rd_Rs, C flag = Rd[Rs - 1]
BIC : logical bit clear (AND NOT) of two 32-bit Rd = Rd AND
NOT(Rm)values
CMN : compare negative two 32-bit values Rn + Rm sets flags
CMP : compare two 32-bit integers Rnimmediate sets flags RnRm sets flags
EOR : logical exclusive OR of two 32-bit values Rd = Rd EOR Rm

LSL : logical shift left Rd = Rm_ immediate,


C flag= Rm[32 immediate]
Rd = Rd_Rs, C flag = Rd[32 Rs]
LSR : logical shift right Rd = Rm_ immediate,
C flag = Rd [immediate 1]
Rd = Rd_ Rs, C flag = Rd[Rs 1]
MOV : move a 32-bit value into a register Rd = immediate
Rd = Rn
Rd = Rm
MUL : multiply two 32-bit values Rd = (Rm * Rd)[31:0]
MVN : move the logical NOT of a 32-bit value into a register Rd = NOT(Rm)

NEG : negate a 32-bit value Rd = 0 Rm


ORR : logical bitwise OR of two 32-bit values Rd = Rd OR Rm
ROR : rotate right a 32-bit value Rd = Rd RIGHT_ROTATE Rs,
C flag= Rd[Rs1]
SBC : subtract with carry a 32-bit value Rd = Rd Rm NOT(C flag)
SUB : subtract two 32-bit values Rd = Rn immediate
Rd = Rd immediate
Rd = Rn Rm
sp = sp (immediate_2)
TST : test bits of a 32-bit value Rn AND Rm sets flags

63
5.10 GSM TECHNOLOGY:

5.10.1 INTRODUCTION
GSM (Global System for Mobile Communications, originally Groupe Spcial
Mobile), is a standard developed by the European Telecommunications Standards
Institute (ETSI) to describe protocols for second-generation (2G) digital cellular
networks used by mobile phones. As of 2014 it has become the default global standard for
mobile communications - with over 90% market share, operating in over 219 countries and
territories.

GSM stands for Global System for Mobile Communication and is an open, digital cellular
technology used for transmitting mobile voice and data services.
The GSM emerged from the idea of cell-based mobile radio systems at Bell Laboratories in
the early 1970s.

The GSM is a circuit-switched system that divides each 200kHz channel into eight 25kHz
time-slots. GSM operates in the 900MHz and 1.8GHz bands in Europe and the 1.9GHz and
850MHz bands in the US.

The GSM is owning a market share of more than 70 percent of the world's digital cellular
subscribers.

The GSM makes use of narrowband Time Division Multiple Access (TDMA) technique for
transmitting signals.
The GSM was developed using digital technology. It has an ability to carry 64 kbps
to 120 Mbps of data rates.

Presently GSM supports more than one billion mobile subscribers in more than 210 countries
throughout the world.

The GSM provides basic to advanced voice and data services including Roaming service.
Roaming is the ability to use your GSM phone number in another GSM network.

64
A GSM digitizes and compresses data, then sends it down through a channel with two other
streams of user data, each in its own time slot. It operates at either the 900 MHz or 1,800 MHz
frequency band.

Fig : 5.14 Over view of GSM

A GSM network consists of several functional entities, whose functions and interfaces are
defined. The GSM network can be divided into following broad parts.

The Mobile Station (MS)


The Base Station Subsystem (BSS)
The Network Switching Subsystem (NSS)

The Operation Support Subsystem (OSS)

5.10.2_ARCHITECTURE_OF_GSM_NETWORK:

Fig 5.15: Architecture

65
The added components of the GSM architecture include the functions of the databases and
messaging systems:

Home Location Register (HLR)


Visitor Location Register (VLR)
Equipment Identity Register (EIR)
Authentication Center (AuC)
SMS Serving Center (SMS SC)
Gateway MSC (GMSC)
Chargeback Center (CBC)
Transcoder and Adaptation Unit (TRAU)

The MS and the BSS communicate across the Um interface, also known as the air interface or
radio link. The BSS communicates with the Network Service Switching center across the A
interface.

5.10.3 SMS SERVICE:


SHORT TEXT MESSAGES:

SMS (Short Messaging Service) service is a text messaging which allow you to send
and receive text messages on your GSM Mobile phone. Services available from many of the
world's GSM networks today - in addition to simple user generated text message services -
include news, sport, financial, language and location based services, as well as many early
examples of mobile commerce such as stocks and share prices, mobile banking facilities and
leisure booking services.

66
CHAPTER-6
SOFTWARES

6.1 KEIL SOFTWARE:


6.1.1 INSTALLING THE KEIL SOFTWARE ON A WINDOWS PC:

Insert the CD-ROM in your computers CD drive


On most computers, the CD will auto run, and you will see the Keil installation menu. If the
menu does not appear, manually double click on the Setup icon, in the root directory: you will
then see the Keil menu.
On the Keil menu, please select Install Evaluation Software. (You will not require a license
number to install this software).
Follow the installation instructions as they appear.

6.1.2 LOADING THE PROJECTS

The example projects for this book are NOT loaded automatically when you install
the Keil compiler. These files are stored on the CD in a directory /Pont. The files are
arranged by chapter: for example, the project discussed in Chapter 3 is in the directory
/Pont/Ch03_00-Hello.Rather than using the projects on the CD (where changes cannot be
saved), please copy the files from CD onto an appropriate directory on your hard disk.
Note: you will need to change the file properties after copying: file transferred from the CD
will be read only.

Configuring the Simulator

Open the Keil Vision2

Go to Project Open Project and browse for Hello in Ch03_00 in Pont and open it.

67
Go to Project Select Device for Target Target1

68
Select 8052(all variants) and click OK

Now we need to check the oscillator frequency:

Go to project Options for Target Target1

69
Make sure that the oscillator frequency is 12MHz.

Building the Target

Build the target as illustrated in the figure below

70
Running the Simulation

Having successfully built the target, we are now ready to start the debug session and run the
simulator.
First start a debug session

71
The flashing LED we will view will be connected to Port 1. We therefore want to observe the
activity on this port

To ensure that the port activity is visible, we need to start the periodic window update flag

72
Go to Debug - Go

While the simulation is running, view the performance analyzer to check the delay durations.
Go to Debug Performance Analyzer and click on it

73
Double click on DELAY_LOOP_Wait in Function Symbols: and click Define button

6.2 PROTEUS

74
6.2.1 INTRODUCTION TO PROTEUS:

Proteus professional is a software combination of ISIS schematic capture program and


ARES PCB layout program. This is a powerful and integrated development environment.
Tools in this suit are very easy to use and these tools are very useful in education and
professional PCB designing. As professional PCB designing software with integrated space
based auto router, it provides features such as fully featured schematic capture, highly
configurable design rules, interactive SPICE circuit simulator, extensive support for power
planes, industry standard CADCAM & ODB++ output and integrated 3Dviewer.

Next, a work space with interface buttons for designing circuit will appear as shown in
figure below. Note that there is a blue rectangular line in the workspace; make sure that whole
circuit is designed inside the rectangular space.

Next step is selecting the components to our required circuit. Let us take one example
is designing of 38 kHz frequency generator by using 555 timer IC. The circuit diagram is
shown in below image.

In the above circuit the required components are 555 timers IC, 470 and 22K
Resisters,10K. Variable resister, 0.001f capacitor and one IR LED. So select the components

75
from library. In menu bar library > pick device/ symbol. Then one window will open that
shown in below.

There is another way to select the components. In work space left side there is a tool bar. In
that tool bar click the component mode button or pick from library.

76
Select the all components from library, that components are added to devices list.
Click on the device and change the angle of the device by using rotate buttons. Then click in
the work space then the selected component is placed in work space. Place all the devices in
work space and put the curser at the component pin end then draw the connections with that
pen symbol. Connect all the components according to circuit then that designed circuit is
show in below image.

If any modifications want to do to the component place the mouse point and click on right
button then option window will open. That is shown in below figure.

77
After completion of designing save with some mane and debug it. This is virtual
simulation means without making circuit we can see the result in virtually through this
software and we can design the PCB layout to our required circuit with this software

78
CHAPTER-7
RESULT AND ANALYSIS
In this section the results obtained from the software and hardware developments
are discussed. In addition the alarm and testing procedures are presented

7.1 RESULTS ANALYSIS SOFTWARE

In the progression of the project through software developments, there were


positive results in these areas. Taking an input video into the system we are able to extract the
relevant information we desire through electronic means without ever having to look at the
image. In this instance the relevant information is centered around the eyes.

The main development of software has taken place in the MATLAB development
environment. Using this to create algorithms and a working structure for the driver fatigue
detection system, a modular function structure was developed with the code required to gain
maximum benefit of code reused.

The results of the software development are a method of finding the pupil in eye
and determining their position within a defined range.

7.2 Results Analysis Hardware

The hardware aspects of this project encompass the ALCOHOLIC,


TEMPARATURE Sensor Circuit, the ADC mcp3208, the PC and camera.. This caused
difficulties while developing the system as the data had to be stored in an intermediary
location to allow the device and program to send data from one to another.

Fortunately all the current hardware elements are interfacing through the
MATLAB environment. System is connected to the PC via the serial cable and transmitting
the two digit level pressure to the MATLAB workspace where it is used with the camera
data.

79
CHAPTER-8
CONCLUSION & FUTURE SCOPE

I have enjoyed greatly the challenges this project has had to offer. I have learned a
multitude of new techniques with image processing and have developed confidence in my
own ability to develop systems.

The development of a commercial unit based a similar strategy to this projects methods
of eye detection is inevitable as world culture dictates higher safety standards in all aspects of
life.

In todays world there are more vehicles on the roads than ever before at all hours of the
night and day. This increase in road usage is a factor in the rate of traffic accidents on roads.
In addition, especially in Ireland, hundreds of thousands commute over long distances to
work, day in, and day out. This long daily commute very early in the morning and late in the
evening can fatigue the driver thus inhibiting their ability to react to non-expectant events and
even worse, it can cause the driver to fall asleep at the wheel. This is why such a system,
outlined in this project would be of benefit to drivers and their communities.

FUTURE ENHANCEMENT:

1) We can implement GSM technology to inform the relatives or owners of the vehicle about

the alcohol consumption.

2) We can implement GPS technology to find out the location of the vehicle.

80
REFERENCES

1. Fitting the Task to the Human, Taylor & Francis, 1997


2. Reaction Time, Institute of Transportation Engineers Expert Witness Council Newsletter,
3. Driver Fatigue Road Safety Authority,
4. Road accidents caused by drivers falling asleep, Fridulv Sagberg ,Accident Analysis and
5 . Embedded Systems Design , Jim Tundy, http://www.embeddedsystems.com
6. "Use of the Hough Transformation to Detect Lines and Curves in Pictures" Duda, R.O. and
7. The Hough transform: http://planetmath.org/encyclopedia/HoughTransform.html
8. The Hough Transform: http://en.wikipedia.org/wiki/Hough_transform
9. GRJ Cooper & DR Cowan, The detection of circular features in irregular spaces data,
10. Circular Hough Image:
http://www.cis.rit.edu/class/simg782.old/talkHough/HoughLecCircles.html
11. Qiang Ji and Xiaojie Yang Real Time Visual Cues Extraction for Monitoring Driver
Vigilance, B. Schiele and G. Sagerer (Eds.): ICVS 2001, LNCS 2095,
12. Image if illuminated eyes by IR light
http://www.archimuse.com/mw2003/papera/milekic/milekic.html
13. The FSR Guide:
http://www.interlinkelectronics.com/library/media/papera/pdf/fsrguide.pdf
14. AduC831 Datasheet : http://www.analog.com/UploadedFiles/Data_Sheets/ADUC831.pdf
15. Analogue Devices Product Site:
http://www.analog.com/en/prod/0,2877,ADUC832,00.html
16. Mathworks website: http://www.mathworks.com

81
82

You might also like