Lao Yang's MS Project
-
Upload
vasea-varzari -
Category
Documents
-
view
9 -
download
0
Transcript of Lao Yang's MS Project
REMOTE CONTROL POWER GLOVE
____________
A Project
Presented
to the Faculty of
California State University, Chico
____________
In Partial Fulfillment
of the Requirements for the Degree
Master of Science
in
Electrical and Computer Engineering
Computer Engineering Option
____________
by
© Lao Yang 2010
Spring 2010
REMOTE CONTROL POWER GLOVE
A Project
by
Lao Yang
Spring 2010
APPROVED BY THE INTERIM DEAN OF THE SCHOOL OF GRADUATE, INTERNATIONAL, AND INTERDISCIPLINARY STUDIES:
______________________________ Mark J. Morlock, Ph.D.
APPROVED BY THE GRADUATE ADVISORY COMMITTEE:
_______________________________ ______________________________ Adel Ghandakly, Ph.D Hede Ma, Ph.D., Chair Graduate Coordinator
_____________________________ Adel A. Ghandakly, Ph.D.
iii
PUBLICATION RIGHTS
No portion of this project may be reprinted or reproduce in any manner
unacceptable to the usual copyright restrictions without the written permission of the
author.
iv
DEDICATION
This project is dedicated to my parents:
Kia Yang & Mai Lao Vang
~~~
Thank you for always believing in me and all the
support you have given me throughout my life.
v
ACKNOWLEDGMENTS
First of all, I want to thank Dr. Hede Ma. Without his guidance, this project
would have not been possible. I would also like to thank Dr. Adel Ghandakly along with
the faculties and staffs in the Electrical and Computer Engineering department at
California State University, Chico. I am thankful for the help of my friends Christopher
Peurifoy, Jowel Yusta, and Krishna Khandavilli as well as my colleagues and staff at
Student Computing. Finally, I want to thank all my friends and family for their support
in making this project possible.
vi
TABLE OF CONTENTS
PAGE
Publication Rights…………………………………………………………..…… iii
Dedication……………………………………………………………………….. iv
Acknowledgments……………………………………………………………….. v
List of Figures…………………………………………………………………… viii
List of Nomenclatures……………………………………….…………………... ix
Abstract………………………………………………………………………….. xiii
CHAPTER
I. Introduction………………………………………………………. .. 1
Purpose of Project…………………………………………..... 1 Scope of the Project…………………………………….......... 2 Significance of the Project………………………………….... 3 Limitations………………………………………………….... 4
II. Review of Related Literature ………………………………….…... 6
Introduction…………………………………………….……. 6 Microcontrollers……………………………………….…….. 7 Accelerometers………………………………………............ 7 Radio Frequency (RF) Wireless Devices..…………………… 9 Other Parts…………………………………………………… 10 Hypothesis…………………………………………………… 11
III. Methodology………………………………………………………. 13
Introduction………………………………………………….. 13 Assembling the Power Glove………………………………... 15 Assembling the RC Car…………………………………….... 25
vii
CHAPTER PAGE
IV. Results…………………………………………………………….. 31
Introduction…………………………………………………. 31 Findings and Errors…………………………………………. 31
V. Summary, Conclusions, and Recommendations………………….. 33
Summary……………………………………………………. 33 Conclusions…………………………………………………. 34 Recommendations…………………………………………... 34
References………………………………………………………………………. 35
Appendices
A. Schematics………………………………………………………... 38 B. Flowcharts………………………………………………………… 41 C. Source Codes……………………………………………………… 44 D. Final Project………………………………………………………. 59
viii
LIST OF FIGURES
FIGURE PAGE
1. Interrupt Control Register (INTCON)…………………………………..... 15
2. Interrupt Control Register 2 (INTCON2)..……………………………….. 16
3. Interrupt Control Register 3 (INTCON3)……………………………….... 17
4. Reset Control Register (RCON)…….……………………………………. 17
5. A/D Control Register 0 (ADCON0)…..………………………………….. 18
6. A/D Control Register 1 (ADCON1)………………………………............ 19
7. A/D Control Register 2 (ADCON2)…………………………………........ 20
8. Transmit Status and Control Register (TXSTA)…………………………. 23
9. Receive Status and Control Register (RCSTA)…………………………... 24
10. Baud Rate Control Register (BAUDCON).………………………………. 24
11. Peripheral Interrupt Enable Register 1 (PIE1).…………………………... . 29
12. Peripheral Interrupt Priority Register 1 (IPR1).…………………………... 29
ix
LIST OF NOMENCLATURES
A Amperes
A/D Analog-to-Digital
ADCON0 Analog-to-Digital Control Register 0
ADCON1 Analog-to-Digital Control Register 1
ADCON2 Analog-to-Digital Control Register 2
ADFM Analog-to-Digital Result Format
ADON Analog-to-Digital On bit
AN0 Analog Port 0
AN1 Analog Port 1
ASK Amplitude shift keying
BAUDCON Baud Rate Control Register
BRG16 16-Bit Baud Rage Register Enable bit
BRGH High Baud Rate Select bit
bps Bits per second
C/C++ C and C++ programming language
CPU Central Processing Unit
CREN Continuous Receive Enable bit
DC Direct Current
EUSART Enhanced USART
x
FOSC Microcontroller Oscillator
ft Feet (a unit of measurement)
g Gravitational constant
GIE/GIEH Global Interrupt Enable bit
h-bridge Motor driver chip
IC Integrated circuit
I/O Input/Output
INT0 Interrupt 0
INT1 Interrupt 1
INT2 Interrupt 2
INT0IE Interrupt 0 External Interrupt Enable bit
INT1IE Interrupt 1 External Interrupt Enable bit
INT2IE Interrupt 2 External Interrupt Enable bit
INTCON Interrupt Control Register
INTCON2 Interrupt Control Register 2
INTCON3 Interrupt Control Register 3
INTEDG0 External Interrupt 0 Edge Select bit
INTEDG1 External Interrupt 1 Edge Select bit
INTEDG2 External Interrupt 2 Edge Select bit
IPEN Interrupt Priority Enable
IPR1 Peripheral Interrupt Priority Register 1
ISR Interrupt Service Routine
xi
LED Light emitting diode
mA Milliamperes
MHz Megahertz
Microchip Manufacture of PIC® microcontrollers
mV Millivolts
PCFG3:PCFG0 Analog-to-Digital Port Configuration Control bits
PDA Personal digital assistant
PIE1 Peripheral Interrupt Enable Register 1
PEIE/GIEL Peripheral Interrupt Enable bit
PIC® Programmable Interface Controller
RB0 Port B0 of microcontroller
RC Remote control
RCIP Receiver Interrupt Priority bit
RCON Reset Control Register
RCPG Remote Control Power Glove
RCSTA Receive Stats and Control Register
SPBRG EUSART Baud Rate Generator Register Low Byte
SPEN Serial Port Enable bit
SYNC EUSART Mode Select Bit
TAD Time Analog-to-Digital
TX9 9-Bit Transmit Enable bit
TXCKP Clock and Data Polarity Select bit
xii
TXSTA Transmit Status and Control Register
TXEN Transmit Enable bit
USART Universal Synchronous/Asynchronous Receiver/Transmitter
V Volts
VCFG1 Voltage Reference Configuration bit (Vref- Source)
VCFG0 Voltage Reference Configuration bit (Vref+ Source)
x-axis Displacement in the left and right movement
y-axis Displacement in the back and forth movement
xiii
ABSTRACT
REMOTE CONTROL POWER GLOVE
by
© Lao Yang 2010
Master of Science in Electrical and Computer Engineering
Computer Engineering Option
California State University, Chico
Spring 2010
The idea of using hand gestures to control a remote control car motivated this
project. Instead of using a regular controller, the user can put on a glove and wirelessly
control the remote control car by just moving his/her hand.
Working on this project takes a lot of time and research. Even though the
technologies being used to implement this project are available, researching on how they
work and putting it all together takes a lot of time. Each part has to be individually
analyzed and carefully tested.
There are two main parts to this project. The first part is the transmitter,
which is the power glove. It contains sensors that will calculate the motion of the user’s
hand gestures, encode data, and transmits it to the receiver. The receiver, on the other
hand, is the remote control car. It waits for data from the transmitter. Once data is
received, it will decode it and execute the proper functions.
xiv
After months of research and testing, the project was successfully
implemented. While the project was being developed, like every other project, problems
occur which cause delays. Some of these problems include: bad parts, damaged sensors,
budget limits, etc. But, in the end, the project was successfully implemented.
1
CHAPTER I
INTRODUCTION
Remote control (RC) cars are those kinds of toys that everyone wants
regardless of how old they are. The size of these cars can range from very small to very
huge. Most people use them as entertainment while others just like to collect them. The
idea is to wirelessly control it using a controller.
In 1989, Nintendo® released their Power Glove [1]. The purpose of the power
glove is to be used with their video games. Basically, the user can control the character
in a video game with certain hand gestures. With this idea, it started to change the way
of gaming as we saw it.
Even though there are these kinds of technologies, no one has attempted to
combine these two devices and use the power glove to control the RC car. The idea of
controlling an RC car with only hand gestures is the main purpose behind this project.
Purpose of the Project
The purpose of this project is to combine both the power glove and the RC
car. So, instead of using a regular RC car controller, the user will control the RC car
using only his/her hand gestures. The idea of using hand gestures to physically interact
with an RC car motivated this project. It will eliminate the use of RC car controllers.
2
Scope of the Project
This project allows the user to use a glove to remotely control an RC car. The
way the user controls the RC car is by using hand gestures. So, if the user tilts his/her
hand forward, the RC car will move forward. Tilting back will move it backwards.
Similarly, tilting left/right will move it left/right. If the user’s hand is level parallel to the
ground surface, the RC car will stop and do nothing. There are additional controls to it as
well. For instance, pressing on the forefinger will start the RC car and power glove
initialization. Pressing on the middle finder will turn the headlights on and off. Finally,
pressing the pinky will turn off the initialization.
The user of this project can range from children ages three all the way to
seniors in their seventies. Because it doesn’t require any special skills, it can be use by
pretty much anyone. Another group of users who will be interested in using this project
are those who have lost an arm or a hand. Because most RC cars require the user to use
two hands to operate, it is difficult for them. Being disabled doesn’t mean that they can’t
have fun. Because this project only requires the use of one hand, anyone can use it
regardless of who they are.
Since this project will be categorized as a toy, it can be used for entertainment
as well as collectables. There are many people out there that just love to collect toys like
these, especially if it is something new and has advanced technologies built in. For those
who enjoy RC cars, they will surely love this project. This project will take RC cars to
the next level. It will give the user the opportunity to physically interact with it.
3
Significance of the Project
When designing this project, research and time are big issues. Even though
the technologies being used to implement this project are available, it requires a lot of
research on getting them to work together. Because this project requires two separate
devices, the RC car and the power glove, two separate designs were created. The power
glove contains an accelerometer, which detects the user’s hand gesture, push buttons, a
transmitter which transmits commands and data to the receiver, and a microcontroller,
which is use to do all the data processing. The RC car, on the other hand, contains a
receiver, an h-bridge, two direct current (DC) motors, some light emitting diodes (LED),
and a microcontroller. Once data is received from the power glove, the microcontroller
on the receiver end will decode the data and execute the functions accordingly.
When both the power glove and RC car are turned on, nothing will happen
regardless of the hand gestures. The RC car will wait until it receives an initialization
command from the power glove. When the user presses on his/her forefinger, the
microcontroller on the power glove will instantly be notified that the initialization process
has started. The microcontroller then sends a command to the RC car indicating that it is
ready to start transmitting data and for the RC car to get ready. At the same time, it
activates the accelerometer, calculates its movement, and starts to compare values. For
example, if the hand is tilted forward, the microcontroller will calculate the values and
transmit a command to the RC car to execute the forward function. The back, left, right
and stop hand gestures have the same effects. The power glove will keep on calculating
and sending commands according to the user’s hand gesture. When the user presses
his/her middle finger, the calculations will be interrupted transmitting a command to turn
4
on or off the headlights of the RC car. In addition, when the user presses his/her pinky, it
will stop all the data calculations as well as the transmission. This will stop the
initialization between the two devices.
On the RC car, when first turned on, nothing will happen. It will wait until
the initialization command from the transmitter is received. Once received, its
microcontroller will initialize all the necessary ports and wait for proper commands to be
executed. For example, if the RC car receives the command to move forward, the
microcontroller will call the function which will activate the h-bridge. This h-bridge will
activate the drive motor, which will make it go forward. The same process applies to
moving back, left, right, and stop. When the RC car receives the command to turn on/off
its headlights, it will call the proper function to turn it on/off. While everything is being
processed, if the RC car receives the command to turn off everything, it will interrupt all
the running processes and turn off the RC car. This will help save battery power.
The project itself looks simple, but the idea of using hand gestures to remotely
control an RC car is difficult. It requires the understanding of how microcontrollers,
accelerometers, radio frequency (RF) wireless devices, h-bridges, and motors work.
Limitations of the Project
There are not a lot of limitations when working on this project. Everything
worked out as it was planned. One of the limitations during the implementation of this
project was time. Because a lot of research has to be done, a lot of time was required.
With only twelve weeks, every minute counts. Resource was also another thing that was
limited to this project as well. Every part and device used in this project had to be
5
carefully used because if a part or device goes bad, it’ll take a lot of time just to get a
replacement. But, overall, everything was managed and the project was completed in the
given time frame.
6
CHAPTER II
REVIEW OF RELATED LITERATURE
Introduction
This project requires the use of microcontrollers, an accelerometer, RF
wireless devices, push buttons, an h-bridge, DC motors, 9V batteries, and other electrical
components. The major devices used in this project are the microcontrollers, the
accelerometer, and the RF wireless devices. The main idea behind this project is to
design a power glove that will be use to control an RC car. The RC car, on the other
hand, will also be design from scratch as well. This is something that hasn’t yet been
done. RC cars have been around for decades. But, none of them are controlled by the
user’s hand gestures. They all use controllers.
The Power Glove, on the other hand, was released by Nintendo® back in 1989
[1]. The purpose of the Nintendo® Power Glove was to be used with its games.
Basically, the user can control the character in a video game with certain hand gestures
and the use of the Nintendo® controller embedded into the glove. Because the games that
were made specifically for the Power Glove sold poorly, it became useless and Nintendo®
stopped marketing it [2].
Before implementing this project, a lot of research had to be done regarding
all the necessary parts and devices. This includes researching on how each individual
device works and how it will benefit the project. This process took a lot of time.
7
Microcontrollers
Microcontrollers are basically small computers on integrated circuit (IC)
chips. Unlike ordinary personal computers, it only requires small amounts of power
ranging from 3.3V to 5V. So, that means that it can be powered by a 9V battery with the
right voltage regulation. Microcontrollers also have internal memories, CPU, clocks, I/O
ports, Analog-to-Digital (A/D) converter, USART module [3], and many more advanced
features depending on the device. They are mostly used in small embedded devices such
as cell phones, PDAs, remote controls, etc. These microcontrollers are programmable.
So, with the right tools and knowledge, a designer can program it to control pretty much
anything he/she wants. It can be as simple as controlling a television remote control to a
control system in an automobile.
The microcontrollers used in this project are the PIC18F2580 microcontrollers
from Microchip [4]. It has everything that is needed for this project. It also has a built in
10-bit A/D converter module. So, analog data read from any external devices, such as the
accelerometer, can be converted into digital data without the use of an external A/D
converter. This digital data can then be used in calculations where needed. The
microcontrollers are the main unit that does all the data processing.
Accelerometers
Accelerometers are electromechanical devices that are used for measuring
acceleration forces [5]. It measure static forces, such as the gravitational pull, and
dynamic forces, such as movements. In addition, it can also be used as tilt sensors.
Accelerometers can be created in many different ways. One of them is by using the
8
piezoelectric effect. Accelerative force stresses microscopic crystals inside these
accelerometers causing it to generate voltages [5]. When being used as a tilt sensor, it
measures static forces or gravitational pulls. So, if it is tilted one way or the other, the
gravitational pull on the device will change resulting in voltage changes within the
device. There are different models of accelerometers available. Some of these are:
single-axis, dual-axis, and tri-axis accelerometers.
Single-axis accelerometers only measure the movement of the device in one
direction. This will most likely be in the x-axis. So if this device is moved or tilted left
or right, it will generate voltages accordingly. Dual-axis accelerometers measure both
directions. This includes the x-axis and y-axis. Basically, dual-axis accelerometers can
measure acceleration or tilt when it is moved or tilted from left to right and/or forward
and backward. Voltages will be generated independently of each other. If there’s a
gravitational pull or movement on only the x-axis and not the y-axis, voltages will only
change on the x-axis output. This will not affect the y-axis. The third model is the tri-
axis accelerometer. This measures the acceleration or tilt and all three directions. It can
measure left-to-right, forward-and-backward, up-and-down, and vice versa. Similar to
the dual-axis accelerometer, the measurements are independent of each other.
The accelerometer used in this project is the Dual Axis Accelerometer
ADXL322 +/- 2g from Analog Devices [6], [7]. This accelerometer can be used to
measure both dynamic and static accelerations [7]. It will be placed on the power glove to
measure hand gestures. So, it will be used as a tilt sensor measuring static acceleration.
This device can measure accelerations with a scale of +/- 2g [7]. This means that if the
9
device is tilted forward and/or right, it can measure a maximum force of +2g with respect
to the earth’s gravitational pull and if it is tilted backwards and/or left, it can measure a
force of -2g with respect to the earth’s gravitational pull.
According to [7], 0g will generate a voltage of about half the input voltage,
which in this case is about 2.5V because the input voltage is 5V. In addition, the
sensitivity of the tilt is about 320 mV/g [7], this means that at every +/-1g, the
accelerometer will add +/-320mV to the initial voltage at 0g. This voltage will then be
read by the microcontroller for further data processing.
Radio Frequency (RF) Wireless Devices
Radio frequency wireless devices have been available for decades. It is used
to transmit signals wirelessly. There are two parts to these RF wireless devices. There
is the transmitter and the receiver. The transmitter takes whatever data it gets from a
microcontroller, encode it, and transmits it to the receiver. The receiver, on the other
hand, will then decode the data received and send it out to its microcontroller for further
data processing. Because wireless devices are so common these days, in order for the
transmitter to properly communicate with the receiver, both devices have operate at the
same frequency.
For this project, the RF Link 4800bps 315MHz Receiver and Transmitter
modules were used [8], [9]. Both the receiver and transmitter operate at the same
frequency of 315MHz. They both use amplitude-shift keying (ASK) modulation [8],
[9]. ASK is a type of modulation that is use to represent digital data with the change in
the amplitude of a carrier wave [10]. The carrier wave is a modified waveform that
10
carries an input signal and transmits it through space. It is usually at a much higher
frequency than the input signal [10]. This way, the data being transmitted won’t get lost
at the receiver end.
The receiver operates at 5V. Since it is a receiver, it only needs 5V to fully
operate itself. It just waits for data. Once data is received, it will then decode it and
output it to the microcontroller. The transmitter, on the other hand, can operate at
voltages ranging from 1.5V to 12V. It operates at a wide range of voltages because with
higher voltages, data can be transmitted further. This transmitter has the capability to
transmit up to 500 ft [9]. To fully transmit data up to 500 ft, the transmitter power supply
has to be 12V.
Other Parts
There are other parts and components used in this project as well. These are:
capacitors, resistors, 8MHz oscillators, voltage regulators, push buttons, LEDs, an h-
bridge, and DC motors. They are the smaller parts in this project. Capacitors, resistors
and voltage regulators were used to reduce and get proper voltages and currents to fully
operate the circuits. In addition, the oscillators were used to fully operate the
microcontrollers.
The headlights and backlights for this project were made from light emitting
diodes (LED). Because the LEDs used for the headlights can only operate a 3.3V at
22mA, voltage division off of the 5V source had to be done to get the proper voltage and
current.
11
There are three main push buttons used in this project. The first one is to start
the initialization process. The second one is to turn the headlights on and off. Finally,
the third one is to turn off the power glove and RC car initialization. The RC car will act
according to the buttons pushed.
H-bridges are electronic circuits that allow voltages to pass through a load in
either direction [11]. In this case, the DC motors are the load. With DC motors, if
voltage is applied in one direction, it will turn in one direction and vice versa if the
voltage is reversed. With an h-bridge, it is easier to reverse the voltage directions on the
motors making it possible for it to move in both directions.
Hypothesis
With all of these devices and small parts, the design and implementation of
this project is possible. Microcontrollers are going to be use as the main data processing
unit for both the power glove and the RC car. On the power glove, the accelerometer is
the main unit that detects the user’s hand gesture. Push buttons are going to start and stop
the initialization and turn on and off the headlights. Finally, the transmitter will transmit
commands from the power glove to the receiver. The receiver, on the other hand, will be
on the RC car as the main receiving unit. Once data is received, it will send it to the
microcontroller for further data processing. The h-bridge will be use on the RC car to
control the DC motors. With proper commands from the microcontroller, the h-bridge
can move the DC motors in one direction or the other. In addition, the h-bridge chip can
control two DC motors at a time. One is to drive the RC car and the other to maneuver it.
12
The Remote Control Power Glove (RCPG) will make it possible for anyone to
control an RC car using only hand gestures. There are people who have only one hand,
which makes it impossible for them using regular RC car controllers. But, with the
RCPG, it will be possible for them to once again enjoy the entertainment of RC cars.
13
CHAPTER III
METHODOLOGY
Introduction
Before working on this project and digging into the hardware, a design for
each device, the power glove and the RC car, is required (refer to Appendix A). Every
part and electrical components are laid out on the circuit design to make sure that all the
connections are correct. For the RC car, the microcontroller is connected to the
headlights (LEDs), h-bridge, and receiver. The h-bridge is connected to two DC motors.
For the power glove, the microcontroller is connected to the three push buttons, the
accelerometer and the transmitter. The purpose of the design is to ensure that when the
physical connections are being made, it is correct. This makes it easier to find the proper
pins to connect to.
After designing the two devices, flowcharts (refer to Appendix B) were also
created for each one as well. Flowcharts help guide the project. It contains information
on how the project should work. For the power glove, when first turned on, nothing will
happen. When the start initialization button is pushed, it will interrupt the
microcontroller and send a command to the RC car indicating that it is ready. This will
then start reading data from the accelerometer. Depending on the input data from the
accelerometer, the microcontroller will send commands to the RC car accordingly. For
example, if the data read into the microcontroller is a forward tilt, it will send the forward
14
command to the RC car letting it know that the hand gesture is forward. When the off
button is pressed, it will interrupt the microcontroller from its current process and send a
command to the RC car letting it know to turn off everything. The same process is used
for turning the headlights on and off.
On the RC car, it does nothing when it is first turned on. It waits for
commands from the transmitter. When the start initialization command is received, the
receiver breaks into a loop which activates all the needed ports to operate the RC car.
When a command is received from the power glove, it will interrupt the RC car from its
current process, compare it to a table of commands, and execute the proper function. For
example, if the RC car receives a command to start moving forward, it will compare it
with the existing table of commands, and execute the function which will drive the RC
car forward.
When working on this project, everything had to be carefully analyzed. Each
device used in this project had to be properly tested before putting it together with the
others. This way, if that device is faulty, it won’t affect the others. This will help save
time and resources.
The microcontrollers were the first to be tested. For this project, the
PIC18F2580 microcontrollers from Microchip Technology Incorporated are used. Since
it is programmable, test programs can be written to test some of the features that it has.
Two of the main features used are the built in A/D converter and the USART module.
Before any testing can be done, proper software and hardware needed to program the
microcontrollers must be acquired. The software and hardware used for all the
programming, compiling, and debugging are both from Microchip Technology
15
Incorporated [12], [13]. After the program was written and compiled, it is then
transferred to the microcontroller using the programmer. In addition, all the
programming is done in C/C++. Test programs such as blinking LEDs were used to test
and make sure that the microcontrollers are working properly with the connected
oscillator, which is 8MHz, and other electrical components. After verifying that the
microcontrollers are working properly, the next step is to start implementing the designs
one at a time.
Assembling the Power Glove
The first thing on the power glove that was implemented was the three push
buttons. The first one is to start the initialization. The second one is to turn the
headlights on and off. Finally, the third one is to turn off the RC car and stop all the data
calculations. Because these buttons have higher priorities than the accelerometer and the
transmitter, they are being used as interrupts. To activate the microcontroller interrupts,
the interrupt control (INTCON) register (Figure 1) must be properly set. So, the first
thing that needs to be done is to set the port (RB0) as input ports.
INTCON: INTERRUPT CONTROL REGISTER
Fig. 1. Interrupt Control Register (INTCON). Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February
2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
16
INTCON contains 8-bits. Each bit corresponding to a different interrupt source. To
properly set the push button interrupts, the following bits must be set: Global Interrupt
Enable bit (GIE/GIEH), Peripheral Interrupt Enable (PEIE/GIEL) bit, and the INT0
External Interrupt Enable bit (INT0IE).
After setting these bits, the next thing is to set the bits on the second interrupt
control (INTCON2) register (Figure 2).The INTCON2 register is used for setting the
buttons interrupt edge. This means that when the buttons are pushed, it either interrupts
on the rising or falling edge of the clock. These external interrupts will be interrupting on
the rising edge of the clock. This means that the following bits are set high: External
Interrupt 0 Edge Select bit (INTEDG0), External Interrupt 1 Edge Select bit (INTEDG1),
and External Interrupt 2 Edge Select bit (INTEDG2). This ensures that when the push
buttons are pressed, it will only interrupt on the next rising edge of the clock.
INTCON2: INTERRUPT CONTROL REGISTER 2
Fig. 2. Interrupt Control Register 2 (INTCON2). Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February
2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
The next register that that needs to be set is the third interrupt control
(INTCON3) register (Figure 3). This register contains bits to make sure that INT1 and
INT2 are treated as external interrupts. There are only two bits in this register that
17
needed to be set. These are the Interrupt 1 External Interrupt Enable bit (INT1E) and the
Interrupt 2 External Interrupt Enable (INT2E) bit.
INTCON3: INTERRUPT CONTROL REGISTER 3
Fig. 3. Interrupt Control Register 3 (INTCON3). Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February
2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
The final register that needs to be set is the Reset Control Register (RCON)
(Figure 4). This register contains the bit to set the interrupt priority. To give priorities to
the interrupts, the Interrupt Priority Enable (IPEN) bit must be set. After these registers
RCON: RESET CONTROL REGISTER
Fig. 4. Reset Control Register (RCON).
Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February 2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
are configured, the external interrupt will work properly. An interrupt service routine
(ISR) will be used to control the interrupt. Whenever the program is interrupted by one
18
of the external interrupts, it will halt the program, jump to the ISR, execute that function,
and return back to resume the program.
After getting the external interrupt to work, the next step is getting the
accelerometer to work. Since the data from the accelerometer are analog values, it
requires the use of the microcontroller’s internal A/D converter. This A/D converter is a
10-bit converter [14]. Configuring the A/D converter is similar to configuring the
external interrupts. Internal registers of the microcontroller must be set in order to
activate the A/D converter module. The A/D converter module requires the configuration
of three registers: A/D Control Register 0 (ADCON0), A/D Control Register 1
(ADCON1), and A/D Control Register 2 (ADCON2).
ADCON0 (Figure 5) is used to configure the analog channel select bits as well
as turning on the A/D converter module. To turn on the A/D converter, bit zero of
ADCON0 needs to be set high which is the A/D On bit (ADON).
ADCON0: A/D CONTROL REGISTER 0
Fig. 5. A/D Control Register 0 (ADCON0). Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February
2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
The next register that is required to be set is the A/D Control Register 1
(ADCON1) (Figure 6). In this register, the only required bits that need to be set are the
19
ADCON1: A/D CONTROL REGISTER 1
Fig. 6. A/D Control Register 1 (ADCON1). Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February
2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
Voltage Reference Configuration bit (VCFG1), Voltage Reference Configuration bit
(VCFG0), and the A/D Port Configuration Control bits (PCFG3:PCFG0). If both the
VCFG1 and VCFG0 are set, that means that the A/D converter will be using external
voltage and ground as reference points instead of the internal power and ground source of
the microcontroller. For this project, external reference points are needed. So, VCFG1
and VCFG0 are set high. Since the accelerometer being used is dual-axis, only two ports
are needed. For this case, only Analog Port 0 (AN0) and Analog Port 1 (AN1) are
needed. To make these ports analog input ports, bits PCFG3, PCFG1, and PCFG0 must
be set.
The last A/D register that needs to be configured is the ADCON2 register
(Figure 7). This register has control bits such as determining the A/D Acquisition Time,
A/D Conversion Clock, and the A/D Result Format. These bits must be set according to
the oscillator used. For the A/D Result Format (ADFM) bit, set it high to right justify the
results. Because the oscillator is 8MHz, the acquisition time is set to 12 TAD (Time
Analog-to-Digital) for this microcontroller. The next part is to set the A/D Conversion
Clock bits. Again, since the oscillator is only 8MHz, the A/D Conversion Clock will be
20
ADCON2: A/D CONTROL REGISTER 2
Fig. 7. A/D Control Register 2 (ADCON2). Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February
2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
set to FOSC/8. FOSC is the oscillator being used by the microcontroller.
After setting these three registers, the next step is to connect up the
accelerometer to the microcontroller. The only pins that are needed are the outputs from
the X and Y axis. For this particular accelerometer (ADXL322), it has measuring range
of +/- 2g [7]. When tilted, it can measure up to +2g with respect to the earth’s gravitation
pull. With 5V as the input source, the tilt sensitivity is about 320mV/g. So, if the device
is tilted forward with a force of +1g, 320mV will be added to the original voltage at 0g.
In addition, at 0g, when the accelerometer is not moving, the voltage measured is about
2.5V. This is about half of the input voltage. So, if it is tilted 1g forward, 320mV will be
added to the 2.5V which will be approximately about 2.82V. If it is tilted backwards,
320mV will be subtracted from the 2.5V resulting in an output voltage of 2.18V. These
values can be used to determine the tilt motion of the sensor. The same method is also
used when tilting left or right.
Once these values are gathered, it is being read by microcontroller’s A/D
input ports (AN0 and AN1). These values are taken in as analog signals and then
converted into digital signals. Because the microcontroller cannot automatically
21
determine if the tilt is forward, backward, left, or right, functions are written to determine
all of this.
Since the A/D converter is 10-bit, it means that the digital data converted from
the analog input is 2 which is 1024. If the reference voltage is 5V and the input analog
voltage is 5V as well, the resulted digital value is going to be 1024. But for the
accelerometer, when it is sitting at 0g, meaning that nothing is happening, the output
voltage is 2.5V. At 0g, this 2.5V analog signal will be converted by the A/D converter
and spit out a digital value of 512. Since 5V analog input gives a digital value of 1024
and 2.5V is half of that, the digital output of 2.5V is 512. The most important part is
finding the digital value for 320mV. With this digital value, it will be much easier to
determine the tilt at +/- 1g and/or +/- 2g.
There are many different ways to determine the digital value for 320mV.
Below is one way of finding the digital value for 320mV.
5 2 1024
5 ∗ 1024 (1)
1024
5 204.8
0.320 ∗ 204.8 (2)
65.536 2 64
From the above calculations, the digital value for 320mV is approximately around 64.
So, if we have a +1g tilt in the forward direction, the analog voltage will be around
2.5 0.320 2.820 . When converted into digital value, it will be 512 64
22
576. If it is tilted in the negative direction, 64 will be subtracted from 512 instead. This
method works the same for both the left and right tilt as well. If the tilt sensitivity is
different, finding the digital value can be done using (2).
To create the window frame that will be used to determine the amount of tilt
from the accelerometer, six reference points are created. Two points are used to
determine the positive tilt, two points are used to determine the negative tilt, and two
other points are used to determine the no tilt motion. The first part is creating the
reference point for the no tilt motion. Obviously, the no tilt motion is when the
accelerometer is at 0g. At 0g, the digital value will be 512. The values will change only
when the accelerometer is tilted. So, the minimum and maximum values must be
determined to create this frame. At +1g, the digital value will be around 576. At -1g, it
will be 448. A +/- 1g tilt should be enough to determine that the hand is either moving
forward or backward. So for the first frame, the minimum value will be approximate 449
and the maximum at 575. This way, if the accelerometer is accidently tilted within the 0g
to +1g; it won’t accidentally move the RC car. The next two frames are pretty simple to
create.
One of them is for values that are from 576 to 1024 and other is from 448 to 0.
For the 576 to 1024 frame, it means that when the accelerometer is tilted forward beyond
+1g, it will have a digital value of 576 or more. This will be treated as a forward tilt. On
the other hand, if it is tilted at -1g or lower, the values will be ranging from 448 down to
0. This will indicate the backward tilt. This same method applies to the left and right tilt
as well. So, two functions must be created for this. One is for the forward and backward
tilt and the other is for the left and right tilt. When data is received from the
23
accelerometer, the microcontroller converts it using the internal 10-bit A/D converter
module, compares the digital values with the corresponding frame, and transmits the
proper command.
The final device used in the power glove is the RF transmitter module. It uses
the serial port (USART) on the microcontroller. Commands sent from the
microcontroller though the USART port will be encoded and transmitted by the RF
transmitter. Since the USART port is being used, it is required that the proper registers
are set. The first register that needs to be set is the Transmit Status and Control Register
(TXSTA) (Figure 8). This register contains bits to control the transmitter port of the
microcontroller.
TXSTA: TRANSMIT STATUS AND CONTROL REGISTER
Fig. 8. Transmit Status and Control Register (TXSTA). Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February
2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
In the TXSTA register, the Transmit Enable bit (TXEN) must be set high in
order to enable the transmitter port. Set the EUSART Mode Select bit (SYNC) and the 9-
Bit Transmit Enable bit (TX9) to low for asynchronous mode with only 8-bit
transmission. Then finally, set the High Baud Rate Select (BRGH) bit low. Since the
24
transmitter will transmit only with baud rates from 2400bps to 4800bps, having a low
speed is better.
In order for the microcontroller to set the correct ports as serial, the Serial Port
Enable bit (SPEN) from the Receive Stats and Control Register (RCSTA) (Figure 9) set.
Once that is set, the rest of the RCSTA control register bits can be ignore.
RCSTA: RECEIVE STATUS AND CONTROL REGISTER
Fig. 9. Receive Status and Control Register (RCSTA). Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February
2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
The final register that needs to be set up is the Baud Rate Control Register
(BAUDCON) (Figure 10). This register is use to control the baud rates of the transmitter.
BAUDCON: BAUD RATE CONTROL REGISTER
Fig. 10. Baud Rate Control Register (BAUDCON). Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February
2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
25
The only bits that need to be set are the Clock and Data Polarity Select bit (TXCKP) and
the 16-Bit Baud Rate Register Enable bit (BRG16). Set both of these bits low.
After configuring these registers, the next thing to do is set the SPBRG
register. This register takes in a decimal value. This value is used by the USART
module to determine the baud rate. The SPBRG can be calculated from the following
formula:
∗
1 (3)
Oscillator refers to the oscillator used, which is 8MHz. The 2400 is the baud rate and the
number 64 refers to the 8-bit low speed transmission.
Once the USART port of the microcontroller is configured, it can then be used
to get data from the microcontroller to the RF transmitter. When data is received, the RF
transmitter encodes it and transmits it to the RC car. Data from the accelerometer are
converted to digital values. These data are then compared to the frames created to
determine which way the accelerometer is being tilted. Once determined, the
microcontroller sends the appropriate commands to the USART port to be transmitted.
Assembling the RC Car
A microcontroller is also used as the main processing unit for the RC car. The
first thing that was done was getting the headlights to work. The headlights are made out
of two bright white LEDs. These LEDs are connected to two ports of the
microcontroller. Similar to the power glove, this microcontroller needs to configure as
well. For the headlights, the configuration is pretty simple. All that needs to be done is
26
to configure the ports that it is connected to as output ports. When signal is received
from the power glove, the microcontroller will switch those ports turning them on or off.
The next part in the RC car is connecting the h-bridge and the DC motors.
The motors are not connected to the microcontroller. Because they required voltages to
change direction, both the drive and turn motors are connected to the h-bridge. The h-
bridge is then connected to the microcontroller. Since the h-bridge that is being used has
two motor drivers built in [15], it is possible to control two motors with only one h-bridge
chip. There are four pins that are used to connect the h-bridge to the microcontroller.
Two of the pins are used to control one driver while the other two pins are used to control
the other driver. There are two DC motors that are used for this project. One of them is
to drive the RC car, while the other is to maneuver it.
The h-bridge takes in two different voltages. One to power the chip and the
other is to power the motors. The pins connecting the h-bridge to the microcontroller
must first be initialized as output pins. After initializing the ports, simple commands can
be sent to the h-bridge to activate the motors. Let’s take the drive motor as an example.
There are two pins that are connected to the microcontroller which will be used to control
the drive motor. If the microcontroller set both of these pins high or low, the motor will
stop. If one pin is high while the other one is low, then the motor will start to move in
one direction. If it is reversed, the motor will start to move in the opposite direction.
This makes it possible to drive the RC car back and forth as well as maneuvering left and
right. The direction of the motor does not matter. It depends on how it is laid out.
The other major device that is used in the RC car is the RF receiver. With the
receiver, the RC car is able to receive transmitted data from the power glove, decode it,
27
and send it to the microcontroller for further data processing. Similar to the transmitter
on the power glove, the receiver will be communicating with the microcontroller through
its serial (USART) port. In order for this to work properly, the microcontroller’s USART
port must be configured. This requires the configuration of the receiver register controls.
The first one is the Receive Status and Control Register (RCSTA) (Figure 9). Set the
Serial Port Enable bit (SPEN) high to have the microcontroller properly configure the
serial communication port. Set the 9-Bit Receive Enable (TX9) bit low. Because the
transmitter from the power glove is only transmitting 8-bit data, the receiver has to be set
to receive only 8-bit data as well. Since the receiver will be operating in asynchronous
mode, set the Continuous Receive Enable bit (CREN) to high. This ensures that the
receiver is continuously receiving.
The next register that needs to be set is the Transmit Status and Control
Register (TXSTA) (Figure 8). In this register, the only bits that need to be set for the
receiver to work properly are the EUSART Mode Select bit (SYNC) and the High Baud
Rate Select bit (BRGH). These two bits must be set low. SYNC being low means that
the USART is operating in asynchronous mode. BRGH being low means that it is
receiving at a low speed.
The final register that needs to be set is the Baud Rate Control Register
(BAUDCON) (Figure 10). The settings for this control register must be the same for the
transmitter. After setting this register, the next step is to calculate the SPBRG value.
This value can be calculated using (3). The baud rate used for calculating the SPBRG
value must be the same as the one used for the transmitter, which is 2400bps.
28
After these control registers are set, the receiver will start receiving data from
the transmitter. So, if the receiver receives commands from the transmitter, it will decode
it, and send it to the microcontroller for further data processing. This method will work,
but there is one problem. If the receive is set to constantly receive, it will try to get data
from the transmitter regardless of whether the transmitter is on or off. If this happens, it
will start to drain battery power. So, one solution is to use interrupts. This means that
when the receiver is not receiving anything, it doesn’t do anything. When a command is
received, it will interrupt the microcontroller, jump to the ISR, compare the commands,
executes the required functions, jumps back out of the ISR, and then back to its current
process. But, before the interrupt will work, some control registers must be set.
The first control register is the Interrupt Control Register (INTCON) (Figure
1). There are only two bits that need to be set in this register. These are the Global
Interrupt Enable bit (GIE/GIEH) and the Peripheral Interrupt Enable bit (PEIE/GIEL).
The GIE/GIEH bit will enable the global interrupts while the PEIE/GIEL bit will enable
all peripheral interrupts, which includes the USART receiver interrupt.
The next register that needs to be configured is the Peripheral Interrupt Enable
Register 1 (PIE1) (Figure 11). This register is used to enable the receiver interrupt bit.
The only bit that needs to be set in this register is the EUSART Receive Interrupt Enable
bit (RCIE). With this bit set, the microcontroller will interrupt every time there is data
received from the receiver. Without the interrupt, the program will always loop causing
it to drain battery.
29
PIE1: PERIPHERAL INTERRUPT ENABLE REGISTER 1
Fig. 11. Peripheral Interrupt Enable Register 1 (PIE1). Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February
2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
Finally, the last register that needs to be set is the Peripheral Interrupt Priority
Register 1 (IPR1) (Figure 12). The only bit that needs to be set is the Receive Interrupt
Priority bit (RCIP). When this bit is set high, the microcontroller will indicate that the
receive interrupt is a high priority and will be executed first.
IPR1: PERIPHERAL INTERRUPT PRIORITY REGISTER 1
Fig. 12. Peripheral Interrupt Priority Register 1 (IPR1). Source: Microchip Technology Inc. “PIC18F2580 Datasheet”. 2009. Retrieved: February
2, 2010. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf. ©2009 Microchip Technology Inc. Reprinted with permission of Microchip Technology Incorporated.
When first turned on, if the start initialization command has not been received,
nothing will happen. Once the command has been received, the RC car will initialize all
the ports needed and wait for commands from the power glove. For example, if the
power glove transmits a command to move forward, it will first be received by the RF
30
receiver. The receiver decodes that command, sends it to the microcontroller interrupting
it from its current process, jumps to the ISR, compare the command, and call the function
to move the RC car forward. In that function, the microcontroller will send a signal to
the h-bridge telling it to start moving the drive motor in the forward direction. This will
then start moving the RC car forward. The microcontroller then jumps out of the ISR and
back to its current process. The same process applies to all commands that are received
from the power glove. Finally, when the receiver receives the off command, it turns
everything off and waits for the start initialization command again.
31
CHAPTER IV
RESULTS
Introduction
This project introduces a new way to control an RC car. Instead of using two
hands, it is now possible to do it with only one hand. With some research and time, the
idea of controlling an RC car with only hand gesture became a project. This project
introduces the idea of using accelerometers to detect a person’s hand movement. This is
not limited to only controlling RC cars. With the data collected from the hand gestures,
designers can use it to control pretty much anything.
Findings and Errors
One of the things found when working on this project is the h-bridge conflict
with the first sets of motors. The original motors being used were 3.3V DC motors.
When first tested, the motors weren’t responding as it should. After a few hours of
testing and researching, it turned out that the h-bridge that was being used is made for
high voltage devices. Because the h-bridge outputs a current of 1 Amp to the motors,
when it is connected to the 3.3V power source, and running, the 3.3V power source gets
really hot. The motors were when replaced with 5V motors, which works a lot better.
Now with higher voltage motors, it only needs one voltage regular instead of two. After
the change, the RC car moved as it should without any problems.
32
The other thing that was found during the implementation of this project was
the distance that the transmitter can transmit. With some testing, at slower baud rates, the
transmitter tends to transmit further than at higher baud rates. When transmitted at higher
baud rates, some data received at the receiver end are lost. But, at lower baud rates,
everything got transmitted as it should.
33
CHAPTER V
SUMMARY, CONCLUSIONS,
AND RECOMMENDATIONS
Summary
This project was created with the idea of using only hand gestures to control
an RC car. Before, it was not possible. But now, with the technologies available, such as
accelerometers, microcontrollers, and RF wireless devices, this project can now put that
idea into use. There are two parts to this project, the power glove and the RC car.
The power glove contains a microcontroller, an accelerometer, an RF
transmitter and some push buttons. The microcontroller is used to do all the data
processing. The accelerometer is used to detect the user’s hand gestures. Once the hand
gestures has been detected, it sends a signal to the microcontroller, which compares it to
the existing data, and then puts the proper command out to the RF transmitter. The RF
transmitter then encodes the data and transmits it to the RC car.
The RC car contains a microcontroller, an RF receiver, an h-bridge, two DC
motors, and some LEDs. Similar to the power glove, the microcontroller is being used as
the main processing unit. Once data is received, the RF receiver decodes the data and
sends it to the microcontroller. The microcontroller then compares the data and executes
the proper functions. When the motor is needed, the microcontroller sends a signal to the
h-bridge to activate it. When the RC car receives the off command, it will turn off.
34
Conclusions
Remote control cars have been around for decades. They range from small
ones to humongous ones. But, all of these require that the user uses a remote control.
More advanced RC cars require the user to use both hands to control and maneuver it.
What if the user doesn’t have the capability to do that? Does that mean that he/she will no
longer be able to enjoy RC cars anymore? The idea behind this project is to design a
power glove that can be use to control an RC car. There are technologies that are capable
of doing all of this, but are used for other things.
With this project, users incapable of controlling an RC car with two hands can
now do it with one hand. All he/she needs to do is put on the power glove, turn it on,
start the initialization, and start making hand gestures. With this power glove, the user
can drive the RC car forward and backward as well as maneuvering left and right. This
project also introduces the idea of physically interacting with an RC car.
Recommendations
When working on a project like this, it is always a good idea to plan ahead.
Have a design ready. Create flowcharts. Make sure that the parts needed are available
and within budget. The most important thing is to make sure that a lot of research is done
before hand. This will make the implementation of the project easier. Make sure to test
each part individually before putting it all together. Reserve a lot of time and use it
wisely. Every minute counts.
REFERENCES
36
REFERENCES
[1] Abraham Gentile Entertainment . Power Glove. [Online]. Available: http://www.ageinc.com/tech/index.html
[2] Wikipedia The Free Encyclopedia. (2010, March). Power Glove. [Online]. Available: http://en.wikipedia.org/wiki/Power_Glove
[3] Wikipedia The Free Encyclopedia.(2009). Microcontrollers. [Online]. Available: http://en.wikipedia.org/wiki/Microcontroller
[4] Microchip Technology Incorporated. (2009). PIC18F2580. [Online]. Available: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en020613
[5] Dimension Engineering. A Beginner’s Guide to Accelerometers. [Online]. Available: http://www.dimensionengineering.com/accelerometers.htm
[6] SparkFun. (2009). Dual Axis Accelerometer Breakout Board – ADXL322 +/-2g. [Online]. Available: http://www.sparkfun.com/commerce/product_info.php?products_id=849
[7] Analog Devices. Small and Thin +/- 5g Accelerometer ADXL320. [Online]. Available: http://www.sparkfun.com/datasheets/Accelerometers/ADXL320_0.pdf
[8] SparkFun. (2009). RF Link 4800bps Receiver – 315MHz. [Online]. Available: http://www.sparkfun.com/commerce/product_info.php?products_id=8947
[9] SparkFun. (2009). RF Link Transmitter – 315MHz. [Online]. Available: http://www.sparkfun.com/commerce/product_info.php?products_id=8945
[10] Global Onceness. (2004, June). Amplitude-shift keying. [Online]. Available: http://www.experiencefestival.com/amplitude-shift_keying
[11] Andras Tantos. (2004). H-bridge secrets part 1. The H-Storm Web. [Online]. Available: http://www.modularcircuits.com/h-bridge_secrets1.htm
[12] Microchip Technology Incorporated. (2009). MPLAB® Integrated Development Environment. [Online]. Available: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002
37
[13] Mouser Electronics. (1996). Microchip Technology MPLAB® PICkit 3 Debug Express. [Online]. Available: http://www.mouser.com/PICkit3debugexpress/
[14] Microchip Technology Incorporated. (2009). PIC18F2480/2580/4480/4580 Datasheet. [Online]. Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39637d.pdf
APPENDIX A
39
SCHEMATICS
Power Glove Circuit
40
Remote Control Car Circuit
APPENDIX B
42
FLOWCHARTS
Power Glove Flow Chart
43
Remote Control Car Flowchart
APPENDIX C
45
SOURCE CODES
Power Glove Source Code
helpertx.h /***************************************************************** * Name: helpertx.h * Author: Lao Yang * Date: April 9, 2010 * Description: Helper file for the transmitter. It contains * port definitions, function calls, and commands for the * transmitter. ******************************************************************/ #ifndef HELPERTX_H #define HELPERTX_H /************* Command Definitions **************/ #define start 's' #define off 'x' #define stop 'd' #define forward 'f' #define reverse 'b' #define left 'l' #define no_turn 'z' #define right 'r' #define hlight_on 'o' #define hlight_off 'c'
/************** Initialization Functions ********/
void InterruptHandlerHigh(void); void InterruptHandlerLow(void); void btn_int_init(); void accel_init(); int accel_read(); int accel_conv(char chan); int accel_busy(); void drive_movement(int value); void drive_turn(int value); void tx(char value); void wait();
#endif
46
helpertx.c
/***************************************************************** * Name: helpertx.c * Author: Lao Yang * Date: April 9, 2010 * Description: Helper file for the transmitter. It contains * initialization functions as well as other functions ******************************************************************/ #include <p18f2580.h> #include <usart.h> #include "helpertx.h" /******************************************************************************* * Function: drive_movement(int value) * Purpose: This function will be used to transmit commands for the * drive motors. * Paramater: int value * Functions called: tx() ********************************************************************************/ void drive_movement(int value){ if(value >= 0 && value < 390){ // Forward Movement (f) tx(forward); wait(); }else if(value > 391 && value < 590){ // Stop (d) tx(stop); wait(); }else if(value >= 591 && value < 1024){ // Reverse Movement (b) tx(reverse); wait(); } } /******************************************************************************* * Function: drive_turn(int value) * Purpose: This function will be used to trasmit commands for the * turn motors. It will either turn left or right. * Paramater: int value * Functions called: tx() ********************************************************************************/ void drive_turn(int value){ if(value >= 0 && value < 400){ // Turn Right (r) tx(right); wait(); }else if(value > 401 && value < 600){ // No Turn (z) tx(no_turn); wait(); }else if(value >= 601 && value < 1024){
47
// Turn Left (l) tx(left); wait(); } } /******************************************************************************* * Function: btn_int_init() * Purpose: This function will be called to initialized the push buttons * as well as the interrupt levels of those push buttons. This function * also sets up the interrupts as well. * Paramater: None * Functions called: None ********************************************************************************/ void btn_int_init(){ /***** Setting Interrupt Bits ******/ /* RCON Bits */ /* IPEN = 1 Interrupt Priority Bit Enabled */ RCON = 0x80; /* INTCON Bits */ /* GIE = 1 * PEIE/GIEL = 1 * INT0IE = 1 INT0 enable (RB0) */ INTCON = 0b11010000; /* INTCON2 Bits */ /* INTEDG0 = 1 Interrupt on rising edge INT0 * INTEDG1 = 1 Interrupt on rising edge INT1 * INTEDG2 = 1 Interrupt on rising edge INT2 */ INTCON2 = 0b01110000; /* INTCON3 Bits */ /* INT1IE = 1 INT1 enable (RB1) * INT2IE = 1 INT2 enable (RB2) */ INTCON3 = 0b00011000; } /******************************************************************************* * Function: accel_init() * Purpose: This function will initialize the AD conversion registers * of the PIC18F2580. This will also set-up the corresponding * AD conversion values for the Accelerometer being used. * Paramater: None * Functions called: None
48
********************************************************************************/ void accel_init(){ /*********** AD Configuration Bits ******************/ /* ADCON0 Bits * * ADON = 1 AD Conversion Module is on */ ADCON0 = 0b00000001; /* ADCON1 Bits * * VCFG1 = 1 VREF- = AN2 * VCFG0 = 1 VREF+ = AN3 * PCFG3:PCFG0 = 1011 AD Port Configuration (RA0 - RA3 = Analog input) */ ADCON1 = 0b00111011; /* ADCON2 Bits * * ADFM = 1 Right Justified * ACQT2:ACQT0 = 101 12 TAD * ADCS2:ADCS0 = 001 FOSC/8 */ ADCON2 = 0b10101101; } /******************************************************************************* * Function: accel_read() * Purpose: This function will return the values read from the AD Conversion. * The returned value will be an integer. * Paramater: None * Functions called: None ********************************************************************************/ int accel_read(){ return(((unsigned int)ADRESH)<<8)|(ADRESL); // Reading input } /******************************************************************************* * Function: accel_conv(char chan) * Purpose: This function will choose which AD port to convert. The AD port will
be * passed in as a parameter. * Paramater: char chan * Functions called: None ********************************************************************************/ int accel_conv(char chan){ if(chan == 'x'){ ADCON0 = 0b0000001; // Channel AN0 Select }else if(chan == 'y'){ ADCON0 = 0b0000101; // Channel AN1 Select } ADCON0bits.GO = 1; // Start Conversion } /*******************************************************************************
49
* Function: accel_busy() * Purpose: This function will return the ADCON0bits.GO bits. If it returns a * 1, that means that AD is still converting. If it returns a 0, then * that meas that the conversion is done. * Paramater: None * Functions called: tx() ********************************************************************************/ int accel_busy(){ return (ADCON0bits.GO); // Returns GO bit if it's still converting } /******************************************************************************* * Function: tx(char value) * Purpose: This function will start transmitting the commands out from * the transmitter to the receiver. * Paramater: char value * Functions called: putcUSART(), BusyUSART() ********************************************************************************/ void tx(char value){ while(BusyUSART()); putcUSART(value); Delay10KTCYx(20); } /******************************************************************************* * Function: wait() * Purpose: This function will cause a 0.5 second delay for for an * 8 MHz clock. * Paramater: None * Functions called: None ********************************************************************************/ void wait(){ return; }
main.c
/***************************************************************** * Name: main.c * Author: Lao Yang * Date: April 9, 2010 * Description: Main File Remote Control Power Glove (RCPG) * for the transmitter. ******************************************************************/ #include <p18f2580.h> #include <usart.h> #include <adc.h>
50
#include <delays.h> #include "helpertx.h" #pragma config OSC=HS,WDT=OFF,LVP=OFF /********* Global Variable Declarations ***********/ int start_on_off = 0; int lights_on_off = 0; /******************************************************************************* * Function: main(); * Purpose: This is the main function in this project. This function * is first exectued and within it, it calls the other functions * such as: initializations and turning on and off LEDs * Paramater: None * Sample Call: main() * Functions called: OpenUSART(), btn_int_init(), accel_conv(),drive_turn(), * drive_motor(), accel_read() ********************************************************************************/ void main(void){ // Local Variable Declarations int accel_val_x, accel_val_y; ADCON1 = 0xFF; // Led Initialization //TRISAbits.TRISA3 = 0; //PORTAbits.RA3 = 0; // Fucntion Initializations btn_int_init(); // Configure USART OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51); // Configure Accelerometer accel_init(); while(1){ // PORTAbits.RA3 = 1; if(start_on_off == 1){ accel_conv('x'); while(accel_busy()); accel_val_x = accel_read(); drive_turn(accel_val_x); accel_conv('y');
while(accel_busy()); accel_val_y = accel_read(); drive_movement(accel_val_y); } }} /******** HIGH Interrupt Control ********/
51
#pragma code InterruptVectorHigh = 0x08 void InterruptVectorHigh(void){ _asm goto InterruptHandlerHigh _endasm } #pragma code #pragma interrupt InterruptHandlerHigh /******** END HIGH Interrupt Control ********/ /******** LOW Interrupt Control ********/ #pragma code InterruptVectorLow = 0x18 void InterruptVectorLow(void){ _asm goto InterruptHandlerLow _endasm } #pragma code #pragma interrupt InterruptHandlerLow /******** END LOW Interrupt Control ********/ /******** Interrupt Functions ********/ /******************************************************************************* * Function: InterruptHandlerHigh() * Purpose: This function will be extecuted whenever a High Interrupt is * encountered. * Paramater: None * Functions called: tx() ********************************************************************************/ void InterruptHandlerHigh(void){ /* START/STOP Button */ if(INTCONbits.INT0IF){ int i; if(start_on_off == 0){ for(i=0;i<5;i++){ tx(start); } start_on_off = 1; } INTCONbits.INT0IF = 0; } // Re-enable global interrupt INTCONbits.GIE = 1; return; } /******************************************************************************* * Function: InterruptHandlerLow() * Purpose: This function will be extecuted whenever a Low Interrupt is * encountered. * Paramater: None
52
* Functions called: tx() ********************************************************************************/ void InterruptHandlerLow(void){ /* HeadLight Button */ if(INTCON3bits.INT2IF){ int i; if(lights_on_off == 0){ for(i=0;i<5;i++){ tx(hlight_on); } lights_on_off = 1; }else if(lights_on_off == 1){ for(i=0;i<5;i++){ tx(hlight_off); } lights_on_off = 0; } INTCON3bits.INT2IF = 0; }else /* Others */ if(INTCON3bits.INT1IF){ int j; if(start_on_off == 1){ for(j=0;j<5;j++){ tx(off); } start_on_off = 0; } INTCON3bits.INT1IF = 0; } // Re-enable global interrupt INTCONbits.GIE = 1; return;}
53
Remote Control Car Source Codes helperrx.h /***************************************************************** * Name: helpertx.h * Author: Lao Yang * Date: April 9, 2010 * Description: Helper file for the receiver. It contains * port definitions, function calls, and commands for the * receiver. ******************************************************************/ #ifndef HELPERRX_H #define HELPERRX_H /*********** Port Definition *************/ #define head_light_r PORTCbits.RC4 #define head_light_l PORTAbits.RA1 #define stop_light PORTAbits.RA2 #define back_light PORTAbits.RA3 #define drive1a PORTCbits.RC0 #define drive2a PORTCbits.RC1 #define turn3a PORTCbits.RC2 #define turn4a PORTCbits.RC3 /************ Commands ******************/ #define start 's' #define off 'x' #define stop 'd' #define forward 'f' #define reverse 'b' #define left 'l' #define no_turn 'z' #define right 'r' #define hlight_on 'o' #define hlight_off 'c' /************* Functions ****************/ void InterruptHandlerHigh(void); void InterruptHandlerLow(void); void device_init(); void rx_init(); void lights(int a); void drive(int a, int b); void turn(int a, int b); void brake(); #endif
54
helperrx.c /***************************************************************** * Name: helpertx.c * Author: Lao Yang * Date: April 9, 2010 * Description: Helper file for the receiver. It contains * initialization functions as well as other functions * that is used by the receiver. ******************************************************************/ #include <p18f2580.h> #include <delays.h> #include <usart.h> #include "helperrx.h" /****************************************************************************** * Function: device_init() * Purpose: This function will be used to initialize the device ports. * All the port macros are defined in "helperrx.h". * Paramater: None * Functions called: None ********************************************************************************/ void device_init(){ ADCON1 = 0xFF; TRISA = 0x00; TRISC = 0x80; head_light_r = 0; head_light_l = 0; back_light = 0; stop_light = 0; drive1a = 0; drive2a = 0; turn3a = 0; turn4a = 0; rx_init(); } /******************************************************************************* * Function: rx_init(void) * Purpose: This function will initialize the Peripheral Interrupts. * It will set all the bits needed to setup the UART RX Interrupt. * Paramater: None * Functions called: None ********************************************************************************/ void rx_init(){ RCON = 0x00; INTCON = 0b11000000; PIE1 = 0b00100000; IPR1 = 0b00100000; PIR1 = 0b00000000;
55
OpenUSART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51); } /******************************************************************************* * Function: lights(int value) * Purpose: This function will be used to turn on the headlights on the * RC car. * Paramater: int value * Functions called: None ********************************************************************************/ void lights(int a){ if(a == 0){ head_light_r = 0; head_light_l = 0; stop_light = 0; }else if(a == 1){ head_light_r = 1; head_light_l = 1; stop_light = 1; } } /******************************************************************************* * Function: drive(int a, int b) * Purpose: This function will be used to control the drive motor on the * RC car depending on the values passed in. * Paramater: int a, int b * Functions called: None ********************************************************************************/ void drive(int a, int b){ drive1a = a; drive2a = b; } /******************************************************************************* * Function: turn(int a, int b) * Purpose: This function will be used to intialize the turn motor on the * RC car. * Paramater: int a, int b * Functions called: None ********************************************************************************/ void turn(int a, int b){ turn3a = a; turn4a = b; } void brake(){ stop_light = 1;}
56
main.c /***************************************************************** * Name: main.c * Author: Lao Yang * Date: April 9, 2010 * Description: This is the Main file for the Remote Control * Power Glove (RCPG). This is the main file for the * receiver. ******************************************************************/ #include <p18f2580.h> #include <delays.h> #include <usart.h> #include "helperrx.h" #pragma config OSC=HS, LVP=OFF, WDT=OFF int activate = 0; int hlight_active = 0; /******************************************************************************* * Function: main(); * Purpose: This is the main function for the receiver. This function will * contain all the functions to intialize and process all the data * needed for this program to run correctly. * Paramater: None * Functions called: device_init(); ********************************************************************************/ void main(void){ int i; device_init(); while(1){ brake(); if(!hlight_active){ lights(0); }else if(hlight_active){ lights(1); } } } /******** HIGH Interrupt Control ********/ #pragma code InterruptVectorHigh = 0x08 void InterruptVectorHigh(void){ _asm goto InterruptHandlerHigh _endasm } #pragma code
57
#pragma interrupt InterruptHandlerHigh
/******** END HIGH Interrupt Control ********/ /******** Interrupt Functions ********/ /******************************************************************************* * Function: InterruptHandlerHigh() * Purpose: This function will be extecuted whenever a High Interrupt is * encountered. * Paramater: None * Functions called: DataRdUSART(), ReadUSART(), lights(int a), drive(int a, int b), * turn(int a, int b) ********************************************************************************/ void InterruptHandlerHigh(void){ if(PIR1bits.RCIF){ while(!DataRdyUSART()); while(BusyUSART()); putcUSART(ReadUSART()); switch(ReadUSART()){ case start: activate = 1; break; case forward: drive(1,0); break; case reverse: drive(0,1); break; case stop: drive(1,1); break; case right: turn(1,0); break; case left: turn(0,1); break; case no_turn: turn(1,1); break; case off: drive(1,1); turn(1,1); activate = 0; break; case hlight_on: hlight_active = 1; break; case hlight_off: hlight_active = 0; default: break; } PIR1bits.RCIF = 0;
58
} // Re-enable global interrupt INTCONbits.GIE = 1; return; }
APPENDIX D
60
FINAL PROJECT
Final Project Figure D-1 shows what the final project looks like.
Fig. D-1. Power Glove and Remote Control Car
61
Power Glove
Figure D-2 shows the electronic circuits inside of the Power Glove.
Fig. D-2. Power Glove Circuit Remote Control (RC) Car Figure D-3 shows the electronic circuits inside of the remote control (RC) car.
Fig. D-3. Remote Control (RC) Car Circuit