Professional Documents
Culture Documents
CONTENTS PAGE NO
1.1. Introduction 1
1.2 Characteristics 2
2.1Project_Specification 5
2.2 Problems 6
3.2 Introduction 9
4.1 Introduction 21
4.1.1 Eyes 21
4.4.1circuit Explanation 21
4.5 Buzzer 29
4.6.1 Introduction 30
4.7 Switches 33
5.1.1.transformer 27
5.1.2 rectifier 28
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
6.2 Proteus 74
REFERENCES 81
FIGURES
EMBEDDED SYSTEMS
1.1 INTRODUCTION
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.
2
Peripherals:
Embedded Systems talk with the outside world via peripherals, such as
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
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.
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.
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
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
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.
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.
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.
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
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
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.
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.
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:
The following hardware and software is used in this system. Detailed explanations of
these components follow in the later sections.
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.
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.
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.
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.
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.
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
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.
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
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.
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:
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 half-wave rectifier is the simplest type of rectifier since it only uses one diode, as
shown in figure
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.
The circuit in figure 3 addresses the second of these problems since at no time is
the output voltage 0V.
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.
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.
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.
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:
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.
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:
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:
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.1 FEATURES
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
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.
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
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.
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.
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).
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 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
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.
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.
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 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
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)
The branch with link, or BL, instruction is similar to the B instruction but overwrites the
55
MOVEQ r1, #0 ; if (r1==5) then r1 = 0 :
Subroutine
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
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.
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.
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.
PRE r1 = 0x00000002
r4 = 0x00000003
sp = 0x00080014
POST r1 = 0x00000002
r4 = 0x00000003
sp = 0x0008000c.
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
POST r1 = 0x00000002
r4 = 0x00000003
sp = 0x00080008
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.
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
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.
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..
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.
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.
A GSM network consists of several functional entities, whose functions and interfaces are
defined. The GSM network can be divided into following broad parts.
5.10.2_ARCHITECTURE_OF_GSM_NETWORK:
65
The added components of the GSM architecture include the functions of the databases and
messaging systems:
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.
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
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.
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
69
Make sure that the oscillator frequency is 12MHz.
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:
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
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.
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
2) We can implement GPS technology to find out the location of the vehicle.
80
REFERENCES
81
82