Untitled - Universiti Teknologi Malaysia

Transcription

Untitled - Universiti Teknologi Malaysia
i
RACE TIMING SYSTEM USING PIC MICROCONTROLLER
MUHAMMAD HAZIQ BIN RAMLI
A thesis submitted in fulfilment of the
requirements for the award of the degree of
Bachelor of Engineering (Electrical-Electronics)
Faculty of Electrical Engineering
Universiti Teknologi Malaysia
JANUARY 2014
iii
Specially dedicated to my beloved parents, my family members, lecturers and friends
who have given me support throughout my four years of study in Universiti Teknologi
Malaysia
iv
ACKNOWLEDGEMENT
“In the name of Allah, the Most Gracious and the Most Merciful”
Alhamdulillah, I am grateful to Allah s.w.t for his blessing and guidance that
helped me in finishing my thesis completely. First and foremost, I would like to express
my deepest and highest appreciation to my supervisor, Dr. Usman Ullah Sheikh for his
guidance, advices, motivation and support to help me throughout my research project.
His kindness for accepting me as his final year project student will always be
remembered.
My sincere appreciation also to my family especially my beloved parents Ramli
Bin Laha and Rabi’aton Bt Othman for their love and support to complete this thesis.
Thanks so much to them for the faith that they put in me. I also would like to thank all of
my friends whom had helped me during my project.
Once again, thank you.
v
ABSTRACT
Cycling competition has become one of the major sporting events in the world.
The objective of this project is to design a timing system for cycling competition. The
main challenge in conducting this project is to create an accurate timing system that can
trigger the timing for the riders whenever they pass through the starting line and stop the
timing when they reach the finishing line. After that, the system must be able to collect
data from various bikes and record the timing. Basically, there will be a truss or gate that
is located at the starting and finishing line in the cycling event. This work consists of
two hardware circuits, one placed at the start or finish line, while the other circuit is
mounted on the bicycle. The circuit uses a PIC microcontroller and an LCD display to
show the current time. This project detects the gate at the starting line and finishing line
using IR sensor to start and stop the timing. Zigbee technology was used for the purpose
of transferring data through wireless communication. In conclusion, suitable hardware
and software design must be developed and more research needs to be done to get an
accurate and effective timing system.
vi
ABSTRAK
Pertandingan berbasikal telah menjadi salah satu permainan yang utama di dunia.
Objektif projek
ini adalah untuk merekabentuk sistem masa bagi pertandingan
berbasikal. Cabaran utama semasa mengendalikan projek ini adalah untuk mewujudkan
suatu sistem masa yang tepat iaitu, kiraan masa akan dimulakan sebaik sahaja basikal
melepasi garisan permulaan dan kiraan masa dapat dihentikan apabila basikal tiba di
garisan penamat. Selepas itu, masa yang dicatat oleh setiap basikal mestilah dapat
direkod oleh sistem tersebut. Kebiasaannya di dalam pertandingan berbasikal, gerbang
atau palang akan diletakkan di garisan permulaan dan garisan penamat. Dua litar
diperlukan bagi memastikan sistem ini berfungsi, satu daripada litar tersebut akan
diletakkan di garisan permulaan atau garisan penamat, manakala litar yang lain pula
akan diletakkan di basikal. Litar tersebut menggunakan PIC microcontroller dan paparan
LCD untuk menunjukkan masa yang telah direkod. Projek ini mengesan gerbang yang
terdapat di garisan permulaan dan garisan penamat menggunakan IR sensor untuk
memulakan dan menghentikan masa. Teknologi Zigbee pula telah digunakan untuk
menghantar
data
melalui
komunikasi
tanpa
wayar.
Kesimpulannya,
komponen
elektronik dan perisian yang sesuai harus direka serta penyelidikan yang cukup harus
dilakukan bagi memperoleh sistem masa yang tepat dan berkesan.
vii
TABLE OF CONTENTS
TITLE
PAGE
DECLARATION
ii
DEDICATION
iii
ACKNOWLEDGEMENT
iv
ABSTRACT
v
ABSTRAK
vi
TABLE OF CONTENTS
vii
LIST OF TABLES
x
LIST OF FIGURES
xi
LIST OF APPENDICES
xii
LIST OF ABBREVIATIONS
xiii
1
INTRODUCTION
1
1.1
Problem Statement
2
1.2
Research Objectives
3
1.3
Scope
3
1.4
Outline of Thesis
4
viii
2
LITERATURE REVIEW
5
2.1
Wireless Sensor Networks
5
2.2
Wireless Telemetry
6
2.3
Radio Frequency Identification (RFID)
7
2.4
Related Research
8
2.4.1
8
Vehicle Speed Violation Detection Using
RF Communication
2.4.2
Wirelessly-Charged UHF Tags for Sensor
9
Data Collection
2.4.3
Distance-Sensitive High Frequency
10
RFID Systems
2.4.4
Cycling Timing System
10
2.4.5
A Low Cost RFID Tracking And Timing
11
System For Bike Races
2.5
3
Summary
12
METHODOLOGY
13
3.1
Introduction
13
3.2
Block Diagram of the Project
14
3.3
Flow Chart of the Project
15
3.4
Hardware Design
16
3.4.1
16
Peripheral Interface Controller (PIC)
Microcontroller
3.4.2
SK40C Development Board – Enhanced
18
40 Pins PIC Start-Up Kit
3.4.3
Interface SK40C with LCD Display
20
(16 x 2 characters)
3.4.4
Interface SK40C with Xbee.
23
3.4.5
Interface SK40C with Infrared (IR)
26
Distance Sensor
ix
3.4.6
USB ICSP PIC Programmer (UIC00B)
27
3.4.7
USB to UART Converter (UC00B)
29
3.4.8
Software Development
30
3.4.9
Software Flowchart
31
3.4.10 X-CTU Software
4
5
32
RESULTS AND DISCUSSION
34
4.1
Introduction
34
4.2
Complete circuits
35
4.3
Demonstration of the project
36
CONCLUSION AND RECOMMENDATION
38
5.1
Introduction
38
5.2
Conclusion
39
5.3
Recommendations
40
REFERENCES
41
APPENDICES
APPENDIX A
43
APPENDIX B
45
APPENDIX C
47
x
LIST OF TABLES
Table No
Title
Page
2.1
RFID Frequency Ranges and Its Applications
8
3.1
PIC16F877A Device Features
18
3.2
Specification of SK40C Development Board
19
3.3
LCD (16 x 2) Pins Function
21
3.4
Xbee Modules Series 2 Device Features
23
3.5
Pins Function of Xbee Module Series 2
24
3.6
Function of UIC00B Components
28
3.7
Function of UC00B Components
29
xi
LIST OF FIGURES
Figure No
Title
Page
3.1
Block Diagram of the Project
14
3.2
Flow Chart of the Program
15
3.3
Pins Description of PIC16F877A
17
3.4
SK40C Top View
19
3.5
LCD Display (16x2 Characters)
20
3.6
Complete Circuit of SK40C Interface With Xbee and
IR Distance Sensor
22
3.7
Xbee Module Series 2
23
3.8
System Data Flow Using UART
24
3.9
Diagram for IR Distance Sensor
26
3.10
Graph of Analog Voltage Output vs Distance to
Reflective Object
27
3.11
UIC00B Module
28
3.12
Connection UIC00B Module and SK40C
28
3.13
UC00B Module
29
3.14
Configuration Settings for Zigbee Coordinator
33
3.15
Configuration Settings for Zigbee Router
33
4.1
Hardware for Bike A
35
4.2
Hardware for Centralized Timing System
35
4.3
Bike A Pass Through Gate
36
4.4
Centralized Timing System
37
4.5
LCD on Bike A
38
4.6
LCD on Centralized Timing Circuit
38
xii
LIST OF APPENDICES
APPENDIX
TITLE
PAGE
APPENDIX A
Programming Code for Bike A
42
APPENDIX B
Programming Code for Centralized Timing
44
APPENDIX C
PIC16F877A Datasheet
46
xiii
LIST OF ABBREVIATION
AC
Alternating Current
CM
centimeter
DC
Direct current
FT
feet
Hz
Hertz
ICSP
In Circuit Serial Programming
ID
Identification
IR
Infrared
I/O
Input/Output
LCD
Liquid Crystal Display
M
meter
PIC
Peripheral Interface Controller
PCB
Printed Circuit Board
RFID
Radio Frequency Identification
RX
Received Data
TTL
Transistor-Transistor Logic
TX
Transmitted Data
UART
Universal Asynchronous Receiver Transmitter
UC00B
USB to UART Converter
UIC00B
USB ICSP PIC Programmer V2010
USB
Universal Serial Bus
WISP
Wireless Identification and Sensing Platform
WSN
Wireless sensor networks
1
CHAPTER 1
INTRODUCTION
Bicycle racing has become one of the major sporting events in the world; and has
been recognized as an Olympics sport. There are several types of bicycle racing
including road bicycle racing, time trialling, cyclo-cross, mountain bike racing, track
cycling, BMX, mountain bike trials and cycle speedway.
Nowadays, racing bicycles can easily be found due to the popularity of this sport.
The sport was first introduced in the year of 1868 and the first recorded bicycle race
being held at the Parc de Saint-Cloud, Paris with the distance of 1.2km. Since then,
many new systems were proposed to improve the current racing bicycles and provide
more advantages during the bike race events. For example, Mavic is one of the
manufacturers of road and mountain bike wheels and components have developed many
products that are specialized for bike racing such as wheel-tyre system, Wintech USB,
E-Skewer sensor, E-Bolt sensor, fork sensor, and other devices. The WIN technology
which is a wireless based system developed by Mavic‟s engineers to transfer data easily
between all the devices of the system. For the recent cycling timing systems, most
companies use wireless systems that require transponder chip to be attached on the
bicycle, while at the starting and finishing line, there have the photocells to start and
2
finish the timing of the bicycle. A decoder is used to decode the information that is sent
by the transponder wirelessly and also the result for each bicycle being recorded.
1.1
Problem Statement
Wireless communication is the transfer of digital information between two or
more devices which are not connected by any electrical conductor. To implement this
type of communication during bike racing events, the sensor must functionally
synchronized with the wireless system. The sensor that can work along properly with the
wireless communication will create a new system that can be used to design cycling
timing system.
Moreover, bike racing competition involves many participants. Each player will
have their own bicycle starting at the same starting line and will be finishing at the same
finishing line. It is important to design a system that can record the data of each bicycle,
so that each rider can get the result of their own timing during the racing. Current timing
system requires higher cost to develop the system and get perfect result. To hold the
competition, the organizers need to produce large capital and experienced people to
handle the timing system.
3
1.2
Research Objectives
For this work, there are two objectives that need to be achieved. Firstly, to design
a wireless sensor system that can trigger the timing for cycling event. The second
objective is to send the data via wireless communication.
1.3
Scope
The scope of this work is as follows. For the hardware design, the
microcontroller will be used is PIC16F877A, distance sensor and wireless module being
interfaced with the microcontroller. It will consist of transmitter subsystem that will be
placed on the bicycle and a receiving subsystem that will be placed at the start and finish
line.
For the software design, MPLAB IDE will be used as the interfacing software to
program the microcontroller and compile all the source codes of the project, while the
XCTU software will be used to configure the wireless module. The PICkit2 programmer
will connect between the hardware and the computer.
There are some limitations for conducting this project. The wireless data transfer
will be limited by the 100m distance, maximum speed that can be detected at the start
and finish line is 20km/h, maximum number of bicycles that can be handle by the
system is 3 bikes and the timing that will be recorded is “00:00:00:0” that represents
“HH:MM:SS:mS”.
4
1.4
Outline of Thesis
This thesis consists of five chapters altogether. Chapter two consists of the
theoretical concepts of the project including literature review and related research
regarding on the cycling timing system based on microcontroller. In chapter three, the
proposed methodology to design the hardware and software design is explained. Chapter
four will discuss on the results of this project. All information about the final product
and the testing will be shown here. Lastly, chapter five of the thesis will be the summary
of the thesis, thus concluding the project and discussion on some recommendations for
future works to improve this system. The problems that had been encountered during
conducting this project are clearly stated in this chapter.
5
CHAPTER 2
LITERATURE REVIEW
2.1
Wireless Sensor Networks
There are many applications of the wireless communication system. One of the
most important applications is wireless sensor networks that is important for industries
and developments. A wireless sensor network is a system consists of autonomous
sensors to sense noise, interference, physical or environmental activities in data
collection networks [1]. This allows the users to detect relevant changes, monitor and
collect data thus pass their data through the network to a main location [1].
Basically, wireless sensor networks use three basic networking concepts which
are cluster tree network, star (point to multipoint) topology or mesh networks. Cluster
tree network is the network that connects each node to a node higher or to the gateway,
and data is transmitted from the lowest node on the tree to the gateway [2]. Star topology
is the gathering of all nodes connected to a single hub [2]. If a communication link is
disturbed, it does not affect other node while the disadvantage of the star topology is the
failure of the hub will cause damage to the entire network. In a mesh network, each node
6
has multiple links to other nodes giving flexibility to the system and allow the data
transfer only to the nearest node [2]. A wireless sensor networks is built by combining
many nodes whereby each node is connected to one or several sensors. Each sensor will
have a radio transceiver with the connection to an antenna, a microcontroller, electronic
circuits and an energy source such as a battery.
2.2
Wireless Telemetry
Wireless telemetry has the same function as wireless sensor networks that
enables the user to monitor and collect data, thus controlling the device from a remote
location [3]. Telemetry plays an important role in aircrafts, spacecrafts, energy
monitoring, and industrial sectors. A telemetry system consists of two subsystems,
transmitter and receiver.
For the transmitting subsystem, the physical parameters being sensed by the
transducer will be converted to an electrical signal. After that, the transducer output will
be processed by the signal processing circuit to make it compatible for transmission and
reception of the signal with the subsequent circuits. The transmitter will convert the
signal to radio frequency signal which will be emitted from the antenna [4]. For the
receiving subsystem, the antenna converts the electromagnetic signal to an electrical
signal with lower frequency [4]. Next, the receiving signal will be processed by
demodulators, downconverters and diversity combiner before being stored and analyzed
by the system [4]. Hardware components will be functioning as signal acquisition, signal
conditioning, multiplexing, transmitting, pre-amplification and data processing [4].
7
2.3
Radio Frequency Identification (RFID)
Radio Frequency Identification (RFID) technology transfers and collects data
between a reader and movable item via radio-frequency waves [5]. This technology
operates by combining three parts, the transponder or tag, a reader and the middleware.
The transponder is an antenna that has microchip to carry the data, a reader will collect
the information from the chip within specified range and the middleware is software to
read and write the tag [5]. The RFID communication occurs when the reader and tag
communicate via RF signal. The reader will generate the carrier signal and sent through
the antenna. The tag will receive and send back the modulated signal after modifying it.
The modulated signal received by the antenna will be passed to the reader for decoding
of the data [5].
Usually, RFID can be categorized into three types of tags, passive, semi-passive
and active RFID tags. Passive RFID tags do not require power; the reader sends
electromagnetic waves to induce current in the tag‟s antenna and the transmitted RF
signal will be reflected and modulated by the tag to add information [6]. Semi-passive
RFID tags use battery to give power for the tag to modulate the reflected signal and
maintain the tag‟s memory [6]. Active RFID tags have an internal battery to run the
microchip‟s circuitry thus sends the signal to the reader [6]. The range of operational
frequencies can be divided into four types, which are low frequency (LF), high
frequency (HF), ultra-high frequency (UHF) and microwave. Table 2.1 shows the details
about the types of RFID frequency ranges and its applications in daily life.
8
Table 2.1 RFID Frequency Ranges and Its Applications [6]
Frequency
Range
LF (125kHz)
HF
(13.56MHz)
UHF
(868-915MHz)
Distance
Shortest
10 cm
Slower
Identifying
widgets
through
manufacturing
processes
Short
10 cm – 1 m
Moderate
Access
Control
Employee IDs
Medium
1 m – 100 m
Fast
Highway toll
Data Speed
Application
Microwave
(2.45GHz &
5.8GHz)
Medium
1m–2m
Faster
Identification of
private vehicle
going in/out of
some place
2.4
Related Research
2.4.1
Vehicle Speed Violation Detection Using RF Communication [7]
RFID tracking system has been used to detect the vehicle speed violation on
highway. In this system, vehicles are given unique identity tags. These tags contain
transmitters that emit messages along with its information of speed to the receivers that
are placed at a regular interval of distances. A reader receives information about the
vehicles from the database and hence the vehicle speed tracking and its violation can be
carried out. Besides that, RFID tags can store information that can be used for the
transmission of data to various RFID readers at different location. The advantages of the
RFID tracking system are two or more vehicles can be tracked simultaneously, it can be
traced anywhere and it does not require line of sight interference. The disadvantages are
the distance between data transfer is limited depending on the type of the RFID reader
that been used.
9
2.4.2
Wirelessly-Charged UHF Tags for Sensor Data Collection [8]
The wirelessly-charged power model for sensor-enabled RFID tags in the form
of a passive data logger (PDL) tag being introduced in this project. The purpose of using
a PDL is to combine the best features of passive (battery-free) and active (batterypowered) tags. PDLs use no battery but it can still collect data while away from an RFID
reader. PDLs stores energy harvested from RFID reader signals in a capacitor, that can
be recharged wirelessly and data can be uploaded whenever the PDL is near a reader.
WISP is a fully-passive UHF RFID tag that uses an ultra-low power, 16-bit,
general-purpose microcontroller for sensing, computation and RFID communication.
The prototype of WISP-PDL being designed and implemented on the study to monitor
the temperature and fullness of a milk carton as it is used over the course of a day.
10
2.4.3
Distance-Sensitive High Frequency RFID Systems [9]
The objective of this work is to implement RFID systems for measuring distance
by resolving a tag‟s distance from the reader. Compared to the current distance sensing
system that uses electromagnetic waves, the RFID system operates based on magnetic
coupling for data transmission. The system requires of a tag, a reader, and a data
processing unit that is connected to the reader. The RFID tag is built with discrete
components to enable it to function with the tilt sensor. Tilt sensor is used to measure the
tilting of the tag away from the parallel plane of the reader antenna. The reader antenna
will generate high frequency electro-magnetic field to power the RFID tag and become
the medium for data transmission. A tag transmits the sensor data along with the tag‟s
ID by switching a load resistor on and off thus affecting the transformed transponder
impedance. The analysis of signal strength for the data transmission be the concept to
measure distance between a tag and a reader. The distance for data transmission is
limited within the range of 33cm to 50cm with the accuracy of 1cm.
2.4.4
Cycling Timing System [10]
This system requires a radio frequency transmitter that will be placed on each
bike that will represent the bike‟s identification and two antennas that are connected to a
single receiver being setup at the finishing line to capture the timing for each of the bike
that goes through the finishing line. The data from the receiver is processed by a
computer to provide results in real time via a graphical user interface.
11
The analog receiver needs two antennas because it is necessary to detect the
radio frequency transmitter on each bike exactly when the bike passing the finishing
line. The digital control block has been designed using PIC microcontroller, Address
Incrementer (AI), Flag Array and MUX. Some of the conditions that being specified in
this project are the finishing speed is 60mph, the accuracy for processing time at
finishing speed is 0.02m and the necessary processing time is 700 µs. The advantage of
this system is it can record the timing of each bike if multiple bikes crossing the finish
line at the same time. The disadvantage is the interference of frequency waves from the
bikes that can affect the accuracy of timing processed by the system.
2.4.5
A Low Cost RFID Tracking and Timing System For Bike Races [11]
Bike race tracking system based on RFID is designed, built and tested to enhance
the capability of tracking of each rider and to reduce the system‟s complexity. Two
passive RFID components which are UHF reader and UHF item-level tags, including the
novel RFID reader antenna were developed to produce the system.
Passive UHF RFID is suitable to be used because it does not require battery to
operate. The RFID system that are composed of four components which are reader,
reader antenna, passive tag and computer system had been integrated with the minimal
impact on the race. Since many cycling competition have trusses at the starting and
finishing line, the RFID antennas being located at the truss to capture the information
from the UHF RFID tags on each rider. The UHF RFID tags are placed on the helmet of
each rider since it will ease the detection of the RFID signal.
12
For the system to operate, it requires the truss-mounted antenna and the helmet
deployed tag must meet the desired properties. Four novel antenna deployment are
needed to provide coverage for a 20 feet wide truss zone to accurately track each racer‟s
RFID tag. The advantage is the versatility of this system allows many RFID portals to be
set up during the race and coordinated via internet link. The disadvantage is the
requirement to produce least system complexity to minimize the cost of overall system.
2.5
Summary
Based on the related researches that have been done, to implement the RFID
system in the timing system for competition is difficult. It will require more complex
system to make sure that the system accurately detects and record the time for the bikes.
Besides that, the type of RFID reader and tag must be chosen carefully to ensure the
compatibility to the system. UHF RFID is the most suitable type to be used but it is
costly and the system is more complex.
13
CHAPTER 3
METHODOLOGY
3.1
Introduction
In this chapter, the design methodology that has been used to carry out this
project is explained. Both hardware and software designs are involved in this project.
This chapter will discuss in detail about the process flow of the project, flow chart,
method to interface between the hardware to the microcontroller and the techniques used
in the programming and debugging.
14
3.2
Block Diagram of the Project
Figure 3.1 shows the overview of the project that was developed. The block
diagram shows the description and implementation of the hardware that has been
designed to produce timing system for cycling event. Firstly, there are two main
subsystems were designed, the transmitter subsystem and receiver subsystem. The
transmitter subsystem which consists of PIC microcontroller, Xbee module and distance
sensor will be located on the bike, while the receiver subsystem that will be the
centralized timing consists of PIC microcontroller and Xbee module. The system will
initialize and operating when the bicycle start to cross the start line. The IR sensor will
sense the presence of gate or truss and start the real time counting. The wireless data
transmission will occurs between the Xbee transmitter and Xbee receiver, the timing of
the bicycle will be recorded after the bicycle reach the finish line and timing will be
displayed by the LCD display at the centralized timing circuit.
Figure 3.1 Block Diagram of the Project
15
3.3
Flow Chart of the Project
Figure 3.2 shows the flow chart of the software for this project. Firstly, it will
initialize the system at the beginning of the program. After that, it will go in to the
condition to check the distance sensor. If the distance sensor senses the object, it will
start the timing, and this will indicate that the bike has just went through the starting
line. At the finishing line, the sensor will sense the object to stop the timing and the data
being sent to the centralized timing. The object that will be sensed by the distance sensor
is the trusses at the starting and finishing line.
Figure 3.2 Flow Chart of the Program
16
3.4
Hardware Design
The circuit design and hardware development are important in designing the
system. The main component that will control the system is the microcontroller. The
other electronic components will be interfaced to the microcontroller.
3.4.1
Peripheral Interface Controller (PIC) Microcontroller
PIC microcontroller is one of the products developed by Microchip Technology
and it can be categorized into three types, 8-bit MCUs, 16-bit MCUs and 32-bit MCUs.
Microcontroller is an integrated chip that contains all the components such as CPU,
built-in ROM, RAM, I/O ports, Timers and others to function on their own compared to
microprocessor, a standalone microchip.
Every microcontroller has different number of I/O ports and other features. PIC
microcontroller with more pins will indicate that more functions can be used on the
microcontroller.
Besides that,
the number of bits also
will differ among the
microcontroller. PIC16F877A is the type that has been used in this project because of its
low cost and suitability since it is a 40-pin microcontroller having peripherals necessary
for this project.
PIC16F877A is the main component in the project, since it acts as the central
processing unit of the whole system. All the data that are received through the input pin
will be processed by the microcontroller and transmitted to the output pin. Input and
17
output pins play an important role in the transmission of data as it connects the
microcontroller to the input and output devices. PIC16F877A has 5 ports including 33
digital I/O ports.
It needs a range of 2.0V to 5.0V to operate and its supporting
frequency is 20MHz. Figure 3.3 shows the pins description on PIC16F877A and Table
3.1 shows the details and characteristics of PIC16F877A.
Figure 3.3 Pins Description of PIC16F877A
18
Table 3.1 PIC16F877A Device Features
Features
Operating Voltage
2.0V to 5.0V
Program Memory
14.3 kBytes
Data Memory
368 Bytes
EEPROM Data Memory
256 Bytes
I/O Ports
Port A, B, C, D, E
Operating Frequency
20MHz
Serial Communication
MSSP, USART
Timers
10-bit Analog-to-Digital Module
Pin Count
3.4.2
Characteristic/Values
3
8 Input Channels
40-pin PDIP
SK40C Development Board – Enhanced 40 Pins PIC Start-Up Kit
SK40C is one of the simplest development board designed for users to develop
PIC project easier and faster. It is suitable for 40 pins PIC microcontroller. The board
consists of the basic elements such as two Programmable switches, two LED indicators,
USART communication and USB on board. It offers user to program the PIC without
unplugging the microcontroller from the board. Figure 3.4 shows the top view of SK40C
with the labels and Table 3.2 shows the function of each label for SK40C.
19
Figure 3.4 SK40C Top View
Table 3.2 Specification of SK40C Development Board
Label
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
Function
Connector for UIC00b Programmer
JP10 for PICkit
UART Connector
LED Connector
40-pin IC Socket for PIC MCU
Programmable Push Button
Reset Button
LCD Contrast
JP9 for USB
JP8 for LCD Backlight
Turn Pin for Crystal
LCD display
Header Pin and Turn Pin
DC Power Adapter Circuit
USB Connector
Power Indication LED
Toggle Switch for Power Supply
20
3.4.3
Interface SK40C with LCD Display (16 x 2 characters)
The LCD display used in this project is JHD162A series (16 x 2 characters). The
purpose of using LCD is to display the output data from the microcontroller. The LCD is
connected to the SK40C board using port B and port D of the PIC microcontroller which
is the data bus pin are connected to the port D, pin RS and pin E are connected to the
port RB4 and port RB5 respectively. Figure 3.5 shows the connection of LCD display to
the PIC microcontroller. Table 3.3 describes the details description of each pin of the
LCD display.
Figure 3.5 LCD Connection to the PIC Microcontroller
21
Table 3.3 LCD (16 x 2) Pins Function
Pin
Name
Pin Function
Connection
1
VSS
Ground
GND
2
VCC
Positive supply for LCD
5V
3
VEE
Brightness adjust
Connected to a preset to
adjust brightness
4
Rs
Select register
RB4
5
GND
Ground
GND
6
E
Start data read or write
RB5
7
DB0
Data bus pin
RD0
8
DB1
Data bus pin
RD1
9
DB2
Data bus pin
RD2
10
DB3
Data bus pin
RD3
11
DB4
Data bus pin
RD4
12
DB5
Data bus pin
RD5
13
DB6
Data bus pin
RD6
14
DB7
Data bus pin
RD7
15
VCC
Backlight positive input
VCC
16
B/L
Backlight negative input
GND
22
Figure 3.6 Complete Circuit of SK40C Interface With Xbee and IR Distance Sensor
23
3.4.4
Interface SK40C with Xbee
The model of Zigbee that will be used in this project is Xbee Module 2mW PCB
Antenna - Series 2 (Zigbee Mesh). Xbee wireless RF modules have multiple protocol
and RF features that allow creating complex mesh networks. The Xbee modules enable
the
simple
connection
via
wireless
communication between microcontrollers or
computers or other systems. Figure 3.7 shows the top view of Xbee Series 2 and Figure
3.8 shows the system of data flow using UART. Table 3.4 shows some of the
characteristics of Xbee Series 2 while Table 3.5 describes the function for each pin on
the Xbee Module Series 2.
Figure 3.7 Xbee Module Series 2
Table 3.4 Xbee Module Series 2 Device Features
Features
Indoor/Urban Range
Outdoor RF line-of-sight Range
RF Data Rate
Supply Voltage
Operating Frequency Band
Supported Network Topologies
Number of Channels
Addressing Options
Serial Interface Data Rate
Data Packet Format
Characteristic/Values
Up to 133 ft. (40 m)
Up to 400 ft. (120 m)
250,000 bps
2.1 – 3.6 V
ISM 2.4 GHz
Point-to-point,
Point-to-multipoint,
Peer-to-peer, and Mesh
16 Direct Sequence Channels
PAN ID and Addresses, Cluster IDs
and Endpoints (optional)
9600 baud rate
8 Data Bits and 1 Stop Bit
24
Figure 3.8 System Data Flow Using UART
Table 3.5 Pins Function of Xbee Module Series 2
Pin #
1
2
3
4
5
Name
VCC
DOUT
DIN / CONFIG
D08*
RESET
Direction
Output
Input
Output
Input
6
PWM0 / RSS1
Output
7
8
9
PWM1
[reserved]
DTR / SLEEP_RQ
/ DI8
GND
AD4 / DIO4
CTS / DIO7
Output
Input
Output
Input
Either
16
ON / SLEEP
VREF
Associate / AD5 /
DIO5
RTS / AD6 / DIO6
17
18
19
20
AD3
AD2
AD1
AD0
Either
Either
Either
Either
10
11
12
13
14
15
/ DIO3
/ DIO2
/ DIO1
/ DIO0
Either
Either
Either
Description
Power supply
UART Data Out
UART Data In
Digital Output 8
Module Reset (reset pulse must be
at least 200ns)
PWM Output 0 / RX Signal
Strength Indicator
PWM Output 1
Do not connected
Pin Sleep Control Line or Digital
Input 8
Ground
Analog Input 4 or Digital I/O 4
Clear-to-Send Flow Control or
Digital I/O 7
Module Status Indicator
Voltage Reference for A/D Inputs
Associated
Indicator,
Analog
Input 5 or Digital I/O 5
Request-to-Send Flow Control,
Analog Input 6 or Digital I/O 6
Analog Input 3 or Digital I/O 3
Analog Input 2 or Digital I/O 2
Analog Input 1 or Digital I/O 1
Analog Input 0 or Digital I/O 0
25
After done with the configuration of Xbee, it can be used for the embedded
wireless development system. There are 4 pins of Xbee that being used to interface with
SK40C which are VCC, DOUT , DIN and GND. Based on the Figure 3.5 that shows the
complete circuit diagram, VCC will be represented by the purple wire, GND will be
represented the black wire, DOUT or TX will be represented by the green wire and DIN or
RX will be represented by brown wire. The function of DOUT or TX of Xbee is to
transmit the serial data to the pin UART_RX of SK40C and the function of DIN or RX is
to receive the serial data from SK40C through pin UART_TX.
RX pin of Xbee should be connected to TX on the pin SK40C Board, while TX
pin of Xbee should be connected to the RX pin of SK40C Board. A voltage divider
circuit was developed between the connection of RX (Xbee) and TX (SK40C Board)
because to ensure that power received by the Xbee is 3.3V since the range of operating
voltage for the Xbee is 3.3V to 3.5V.
26
3.4.5
Interface SK40C with Infrared (IR) Distance Sensor (SN-GP2Y0A21)
Infrared (IR) distance sensor made by Sharp comes with various types and
different range of detection. The sensor emits IR off objects to determine how far away
they are. It returns an analog voltage that can be used to determine the distance of the
nearest object. The IR distance sensor model been used is GP2Y0A21YK. The detecting
distance of this sensor is between 10cm to 80cm and the distance is adjustable within the
range of detection. Figure 3.9 shows the diagram and the pin description of IR distance
sensor. Based on Figure 3.6, Pin 1 or VOUT of IR distance sensor will be connected to the
Port RA0, whereas the VCC and GND of IR distance sensor will be connected to the VCC
and GND of SK40C board respectively. Figure 3.10 shows the example of graph for
analog output of IR distance sensor against the distance to reflective object. From the
graph, it can be seen that the less analog voltage output, the greater the distance from the
IR sensor to the reflective object.
Figure 3.9 Diagram for IR Distance Sensor
27
Figure 3.10 Graph of Analog Voltage Output vs Distance to Reflective Object
3.4.6
USB ICSP PIC Programmer (UIC00B)
UIC00B is the device to program Flash PIC MCU and includes most of the PIC
family. UIC00B can do on board programming, thus allows the user to program and
debug the source quickly while the PIC is on the development board. No external power
supply required. Figure 3.11 shows the components for UIC00B module and Figure 3.12
shows the connection UIC00B module and SK40C. Table 3.7 describes the details of
each component.
28
Figure 3.11 UIC00B Module
Table 3.6 Function of UIC00B Components
No
1
2
3
Function
UIC00B main board
Mini USB cable
Rainbow cable (programming cable)
Figure 3.12 Connection UIC00B Module and SK40C
29
3.4.7
USB to UART Converter (UC00B)
The main function of this component is to provide the converter for USB to
UART which enables the interface to most of microcontroller UART pin. Traditionally,
serial port (DB9) is used to do the serial interface from microcontroller to computer.
However, a level shifter is needed between the computer‟s serial port that uses RS232
protocol and the microcontroller that uses TTL (Transistor-transistor Logic) UART.
Recently, the serial port of computer has been replaced by USB. Figure 3.13 shows the
image of UC00B and Table 3.7 shows the function for each component of UC00B.
Figure 3.13 UC00B Module
Table 3.7 Function of UC00B Components
Label
A
B
C
Function
USB A type (male)
Voltage selector (3.3V or 5V)
6 ways header pin for interface to microcontroller
1)
3.3V / 5V Power output from UC00B
2)
UC00B UART Receive pin
3)
UC00B UART Transmit pin
4)
UC00B Data Terminal Ready pin
5)
UC00B Request To Send pin
6)
Ground or negative
30
UC00B UART Receive pin and UC00B UART Transmitter pin are connected to
TX pin and RX pin of Xbee Series 2 module respectively using female to female jumper
wires. The power output pin and the Ground of UC00B will be connected to VCC and
GND of Xbee Series 2 module. After that, the UC00B can be connected to the laptop or
computer to do the configuration of Xbee module.
3.4.8
Software Development
The software required for the development of this project are:
1. MPLAB IDE and HITECH C software to compile all the source code and turn it
into hex file.
2. PICkit2 software to burn the hex file into the PIC microcontroller
3. XCTU software to configure the Xbee module.
31
3.4.9
Software Flowchart
MPLAB IDE is an Integrated Development Environment that provides facility
for the development of embedded applications. MPLAB IDE contains source code
editor, linkers, debuggers, build automation tools and other. For this project, it is used to
simulate and write the program for PIC microcontroller.
Two systems are developed at the transmitter and the receiver. First, the system
is initialized before the system start to operate. Five sub header being included in the
main program which are to control the LCD display, Delay, Timer 0, Analog to Digital
Converter and Serial Communication. To make the PIC microcontroller as a stopwatch
device, Timer 0 is used to do the real time counting. Analog to Digital Converter feature
in the PIC microcontroller is used to control the IR sensor. Port RA0 is initialized to be
the Analog pin that is connected to the VOUT of the IR distance sensor. For the Xbee, the
serial communication feature of PIC microcontroller is used to set up the system either
to be a receiver subsystem or transmitter subsystem. Port RC6 and port RC7 of PIC
microcontroller are defined to be the UART_TX pin and UART_RX pin respectively.
The system will functioning when the transmitter subsystem which is represented
by „Bike A‟ crosses the start line. The IR distance sensor will detect the truss or gate at
the start line and automatically trigger the real time counting of the Timer 0. At the same
time, the data signal „A‟ is sent to the receiver subsystem through wireless
communication that represented as Centralized Timing to start the real time counting.
Both systems will display the same real time counting. After that, the timing will stop
when the „Bike A‟ reaches the finish line. The IR distance sensor will detect truss once
again, stop the time on „Bike A‟ and send the signal „B‟ via wireless communication to
stop the time at the „Centralized Timing‟. Finally the time will be recorded on both
systems.
32
3.4.10 X-CTU Software
X-CTU is a Windows-based application developed by Digi International. This
program was designed to enable the user to access the firmware files on Digi‟s RF
products. X-CTU is used in this project to configure the Xbee module to create the
wireless sensor network. Figure 3.14 and Figure 3.15 shows the setting for configuration
of the Xbee module in this project. Zigbee coordinator setting is for the „Centralized
Timing‟ and Zigbee router setting is for the circuit on the „Bike A‟.
Firstly, the type of Xbee model must be specified before doing the configuration
setting. In this project, the model of Xbee is XB24-ZB. After that , the function set that
being chosen will differentiate the behaviour of the Xbee module, either to transmit or to
receive data. The „Centralized Timing‟ is set as the ZIGBEE COORDINATOR AT, the
function is to receive data from multiple point. „Bike A‟ is set as the ZIGBEE ROUTER
AT, the function is to send the serial data. To enable the communication between two
Xbee modules, the addressing must be set carefully so that it matches each other Serial
Number. The Serial Number High and Serial Number Low are set according to the
registration number of each of the Xbee module. Different Xbee module will have
different registration number. After that, the Destination Address High and Destination
Address Low are set according to the target Xbee module‟s registration number. Similar
setting will be apply on the Xbee module. The relation of Serial Number and Destination
Address can be seen on the configuration setting for each Xbee module, thus make it
possible to do the data transmission via wireless between each other.
33
Figure 3.14 Configuration Settings for Zigbee Coordinator
Figure 3.15 Configuration Settings for Zigbee Router
34
CHAPTER 4
RESULTS AND DISCUSSION
4.1
Complete Circuits
There are two hardware circuits that have been designed in this project. First, the
hardware that will be the centralized timing system. The circuit was developed using
SK40C development board and Xbee module. Second, the circuit that will represent the
bicycle, in this project it will be named as „Bike A‟. The components included in this
hardware are SK40C development board, Xbee module and IR distance sensor.
35
Figure 4.1 Hardware for Bike A
Figure 4.2 Hardware for Centralized Timing System
Figure 4.1 and Figure 4.2 show the hardware that were developed in this project.
The images were taken before the timing started.
36
4.3
Demonstration of the Project
Figure 4.3 Bike A Pass Through Gate
37
Figure 4.4 Centralized Timing System
Figure 4.3 and Figure 4.4 are the images for the demonstration prototype. Figure
4.3 shows Bike A timing starts to count when passes through the gate. Then, the timing
is sent wirelessly to the centralized timing system as shown in Figure 4.4.
38
Figure 4.5 LCD on Bike A
Figure 4.6 LCD on Centralized Timing Circuit
Figure 4.5 shows the timing display by LCD on Bike A and Figure 4.6 shows the
timing display by the LCD on Centralized Timing Circuit. Based on the demonstration
that was done, there are a few aspects need to be considered to allow the system to
function. The maximum speed is limited to 10km/h to 15km/h because the IR distance
must take some time to detect the gate or truss at the start and finish line. When the bike
passes through the gate at the very fast speed, the detection of IR distance sensor is not
accurate. The maximum number of bicycles is three bikes because each of the bike will
use the Timer features in PIC microcontroller which are Timer 0, Timer 1 and Timer 2.
Each of the Timer will do the real time counting for different bikes. The distance of
operation for the Xbee module can be up to 100m.
39
CHAPTER 5
CONCLUSION AND RECOMMENDATIONS
5.1
Introduction
Chapter 5 will explain the conclusions and recommendations for this project. A
few recommendations are provided to improve this design as future research.
5.2
Conclusion
In conclusion, the timing system for cycling event can be designed using the PIC
microcontroller. The IR distance sensor was used to detect the gate and trigger the
timing, while Xbee module was used to send data via wireless communication. Some of
the hardware components are not suitable for this system, since it cannot produce
accurate timing system. Besides that, IR sensor that was used is a very sensitive sensor,
so the timing system cannot be fully controlled by the user. The riders that can be
40
detected by this system is limited to 3 riders. Many riders will cause the timing system
not functioning properly. While, maximum speed that is allowed for the system to
function is 10km/h, there should be no problem at the start line since the riders just
started to race, but at the finish line will be some inaccuracy for the timing to be
recorded when the riders speed are too fast.
5.3
Recommendations
Firstly, a more accurate sensor can be used to control the timing. A sensor that is
not sensitive to any of the disturbing factors from the surrounding should be used to
detect the gate more precisely.
Secondly, RFID technology can be used since it can do accurate detection at the
starting and finishing line. Besides that, RFID is more suitable to collect and send data
since it can give unique address representing the data which will be sent. For the timing
system for the cycling event, UHF RFID system can be used since it allows long range
of detection and transmission of data.
41
REFERENCES
1. Puccinelli, Daniele, and Martin Haenggi. "Wireless Sensor Networks:
Applications and Challenges of Ubiquitous Sensing." Circuits and Systems
Magazine, IEEE 5.3 (2005): 19-31.
2. Lewis, Franck L. "Wireless sensor networks." Smart Environments:
Technologies, Protocols, and Applications (2004): 11-46.
3. Allen Gale. Class Lecture, Topic: “An Introduction To Telemetry.” Department
of Electrical and Computer Engineering & Technology, Minnesota State
University, Mankato, MN.
4. Telemetry Application Handbook, 3rd ed., Telemetry Group (TG) of the Range
Commanders Council (RCC), White Sands, NM, 2006
5. SA, SA Weis. "RFID (Radio Frequency Identification): Principles and
Applications." Retrived from www. eecs. harvard. edu/rfid-article. pdf on 1
(2011).
6. Ilie-Zudor, Elisabeth, et al. "The RFID Technology and Its Current
Applications." Proceedings of the Modern Information Technology in the
Innovation Processes of the Industrial Enterprises (MITIP 2006), Budapest,
Hungary (2006): 29-36.
7. Shrivastava, Ashish, et al. "Vehicle Speed Violation Detection Using RF
Communication." Second National Conference in Intelligent Computing and
Communication, IEEE, 2013.
8. Yeager, Daniel J., et al. "Wirelessly-Charged UHF Tags For Sensor Data
Collection." RFID, 2008 IEEE International Conference on. IEEE, 2008.
9. Metzger, Christian, et al. "Distance-sensitive High Frequency RFID Systems."
Pervasive Computing and Applications, 2008. ICPCA 2008. Third International
Conference on. Vol. 2. IEEE, 2008.
42
10. Bell, Patrick. “Cycling Timing System: Mid-course Design Review.” Diss.
University of Massachusetts Amherst, 2004.
11. Tsai, Wei-Feng. “A Low Cost RFID Tracking and Timing System for Bike
Races.” Diss. Ohio State University, 2011.
12. Juan Antonio Infantes Diaz, “Wireless Sensor Networks Controlled With PIC
Microcontrollers and Zibee Protocol”, Bachelor‟s Thesis Information
Technology, May 2012.
13. R. Barnett, L‟O Cull, S. Fox, “Embedded C Programming and The Microchip
PIC”, Delmar Cengage Learning, 2004.
14. Microchip Technology Inc. “PIC16F87XA Data Sheet”, 2003.
15. Microchip Technology Inc. “MPLAB C Compiler For PIC32 MCUs User‟s
Guide”, 2009.
16. http://www.cytron.com.my
43
APPENDIX A
Programming Code for Bike A
#include
#include
#include
#include
#include
#include
#include
<pic.h>
"libDelay.h"
"libSerial.h"
"lcd.h"
"system.h"
"timer.h"
"adc.h"
// include PIC microcontroller library
// Delay (High Precision)
// Serial communication
__CONFIG(0x1E32);
// PIC microcontroller configuration
unsigned char data_tx;
unsigned int Count, msCount, secCount, minCount, hrCount;
void main(void)
{
TRISB = 0b00000011;
TRISC = 0b11000000;
TRISD = 0b00000000;
PORTB = 0;
PORTC = 0;
PORTD = 0;
//Configure PORTB I/O direction
//Configure PORTC I/O direction
//Configure PORTD I/O direction
ADCON1 = 7;
lcd_initialize();
lcd_clear();
adc_initialize();
InitTimer0();
Serial_Init();
// Initialize serial port (high speed)
lcd_goto(0x00);
lcd_putstr("BikeA-00:00:00:0");
DelayS(1);
Serial Port to finish initialize
//
Delay
while(1)
{
unsigned long adc_value = 0;
unsigned long range_an = 0;
unsigned long Vout = 0;
unsigned char j;
adc_on();
for(j = 0 ; j < 100 ; j++)
{
adc_value = adc_value + ui_adc_read();
}
adc_value = adc_value/100;
Vout = (adc_value*500000)/1024;
1
second,
for
44
if ((Vout > 43945)&&(Vout < 239785))
while ((Vout > 43945)&&(Vout < 239785))
{
range_an = (Vout - 19000)/2099;
Vout = 20.99*Distance + 0.19;
lcd_2ndline();
lcd_bcd(2,1000/range_an);
while(!T0IF);
{
T0IF=0;
Count++;
if(Count==2)
{
msCount++;
Count=0;
}
if(msCount==10)
{
secCount++;
msCount=0;
}
if(secCount==60)
{
minCount++;
secCount=0;
}
if(minCount==60)
{
hrCount++;
minCount=0;
}
if(hrCount==24)
{
hrCount=0;
}
}
data_tx=('A');
LED1=1;
Serial_Transmit(data_tx);
lcd_goto(0x0F);
lcd_bcd(1,msCount);
lcd_goto(0x0C);
lcd_bcd(2,secCount);
lcd_goto(0x09);
lcd_bcd(2,minCount);
lcd_goto(0x06);
lcd_bcd(2,hrCount);
}
}
} // End main()
45
APPENDIX B
Programming Code for Centralized Timing
#include
#include
#include
#include
#include
#include
<pic.h>
"libDelay.h"
"libSerial.h"
"lcd.h"
"system.h"
"timer.h"
// include PIC microcontroller library
// Delay (High Precision)
// Serial communication
__CONFIG(0x1E32);
// PIC microcontroller configuration
unsigned int Count, msCount, secCount, minCount, hrCount;
unsigned char data_rx;
void main(void)
{
TRISB = 0b00000011;
TRISC = 0b11000000;
TRISD = 0b00000000;
PORTB = 0;
PORTC = 0;
PORTD = 0;
//Configure PORTB I/O direction
//Configure PORTC I/O direction
//Configure PORTD I/O direction
ADCON1 = 7;
lcd_initialize();
lcd_clear();
Init1secTimer();
Serial_Init();
DelayS(1);
initialize
//
// Initialize serial port (high speed)
Delay 1 second, for Serial Port to
lcd_goto(0x00);
lcd_putstr("BikeA-00:00:00:0");
while(1)
{
data_rx=Serial_Receive();
if(data_rx=('A'))
{
while(!T0IF);
{
T0IF=0;
Count++;
if(Count==2)
{
msCount++;
Count=0;
}
if(msCount==10)
{
secCount++;
finish
46
msCount=0;
}
if(secCount==60)
{
minCount++;
secCount=0;
}
if(minCount==60)
{
hrCount++;
minCount=0;
}
if(hrCount==24)
{
hrCount=0;
}
lcd_goto(0x0F);
lcd_bcd(1,msCount);
lcd_goto(0x0C);
lcd_bcd(2,secCount);
lcd_goto(0x09);
lcd_bcd(2,minCount);
lcd_goto(0x06);
lcd_bcd(2,hrCount);
LED1=1;
}
}
}
} // End main()
47
APPENDIX C
PIC16F877A Datasheet
48
49
50
51