Docstoc

Final Paper

Document Sample
Final Paper Powered By Docstoc
					  Bus Locator System

                   By


             Ruchir Patel
            Ankit Gandhi
            Kashyap Patel


ECE 345 - Senior Design Project Laboratory

                Fall 2004




          TA: Richard Cantzler




               May 4, 2004




            Project Number 34
                                     ABSTRACT

Bus Locator System (BLS) was build to track the location of the bus and informed the
waiting commuter about the current status of the bus at appropriate bus stop. This
document will present the thorough information about our Bus Locator System. BLS
utilized the HP II series transmitters and receivers, PIC 16F877 as a Microcontroller and
Allesis (16x2) and Shelly (40x2) LCDs in order to relay accurate bus status at particular
bus stop. The functionality of each used component, overall system deign and software
module will be discussed. In addition to that, design decisions, challenges and obstacles
that occurred during the phase of the project work will be explained.
                                              TABLE OF CONTENTS

1.   INTRODUCTION ................................................................................................................................... 1
     1.1   Motivation ................................................................................................................................. 1
     1.2   Objectives .................................................................................................................................. 1
     1.3   System Overview ....................................................................................................................... 2
           1.3.1 Demo Setup .................................................................................................................. 2
           1.3.2 Behind the Scene (High Level) .................................................................................... 3

2.   DESIGN PROCEDURE.......................................................................................................................... 4
     2.1   Design Decision ......................................................................................................................... 4
           2.1.1 Transmitters and Receivers .......................................................................................... 4
           2.1.2 Antennas ...................................................................................................................... 4
           2.1.3 Microcontroller ............................................................................................................ 5
           2.1.4 LCD.............................................................................................................................. 5
     2.2   Software Aspects ....................................................................................................................... 5

3.   DESIGN DETAILS ................................................................................................................................. 6
     3.1   Hardware Components .............................................................................................................. 6
           3.1.1 Bus Hardware............................................................................................................... 6
           3.1.2 Station Hardware.......................................................................................................... 7
     3.2   Software Component ................................................................................................................. 9
           3.2.1 Format of Data Packet.................................................................................................. 9
           3.2.2 Software Flowchart .................................................................................................... 10

4.   DESIGN VERIFICATION ................................................................................................................... 12
     4.1   Hardware Testing..................................................................................................................... 12
           4.1.1 Transmitter and Receiver Testing .............................................................................. 12
           4.1.2 Distance Testing ......................................................................................................... 12
           4.1.3 Frequency Selection ................................................................................................... 13
     4.2   Software Testing ...................................................................................................................... 13

5.   COST ANALYSIS ................................................................................................................................ 15
     5.1   Parts ......................................................................................................................................... 15
      5.2 Labor .................................................................................................................................... 15

6.   CONCLUSION ..................................................................................................................................... 16
     6.1  Accomplishments .................................................................................................................... 16
     6.2  Challenges ............................................................................................................................... 16
     6.3  Future Development Considerations ....................................................................................... 17

7.   APPENDIX ........................................................................................................................................... 18

8.   REFERENCE ........................................................................................................................................ 37
                                                            Project No 34 - Final Paper

                               1. INTRODUCTION

   1.1 Motivation

       Due to the uncertainty about the arrival of bus at bus stop waiting passengers
       especially students on UIUC campus have no straightforward way to find out the
       accurate status of the bus. Additionally, they don’t have real time information
       about the arrival of bus other than printed MTD bus schedule which could be
       different because of construction, accident or awful weather condition.
       Therefore, the development of system which could track the location of bus and
       display its current status accurately at appropriate bus stop will be really
       beneficial. Also, system can make impact on community by helping students to
       save their valuable time and can make bus transportation more efficient and
       useful. In addition to that, system will replace the old fashion confusing clock
       method employed at certain campus location like PAR, FAR, Illini Orange etc.



   1.2 Objectives
       The main goal of this project was to provide students with the most accurate and
       efficient bus status. Moreover, almost as important goal was to develop a
       functioning model which could provide a base for more complex system in
       future. Since this system could be employed and utilized in numbers of buses and
       stations, to construct the low cost system was also our primary goal. The
       programming and installation of the device should be fairly easy and should not
       require any special knowledge from the technician. Operating device should also
       be as easy so that bus drivers don’t have to go through special training.




May 4, 2004                                                                        -1-
                                                               Project No 34 - Final Paper


   1.3 System Overview

   1.3.1    Demo Setup


                              na
                        ten                                        An
                                                                      te
                   An                                                      nn
                                                                              a



     Transmitter                                                                  Receiver




     PIC16F877                                                                PIC16F877




                                                          LCD Display                 Transmitter




           Terminate                        Decrement                             Decrement
            Display                         Counter &                             Counter &
           Bus Stop 4                        Display                               Display
                                            Bus Stop 3                            Bus Stop 2



                                   Figure 1: System Overview


May 4, 2004                                                                                    -2-
                                                           Project No 34 - Final Paper

1.3.2 Behind the Scene (High Level)


                                      RXM 900 HP II
                                       Waiting State




                                         Is Signal
                                          Valid?




                                        Microprocessor


                                         Is it from
           Bus                             Bus or                        Station
                                          Station?



                                                                    Map the signal to
      Change the Bus                                                the specific bus
         status to
        “Just Left”
                                                                    Change the Bus
                                                                       status to
                                                                    “Arriving Soon”




                                      Display on the
                                          LCD




                                      TXM 900 HP II




                                      Send Signal to the
                                         next station



                   Figure 2: System Overview (Behind the Scene)


May 4, 2004                                                                        -3-
                                                               Project No 34 - Final Paper


                             2. DESIGN PROCEDURE

   2.1 Design Decision

       During the course of this project we had to make some of the crucial decisions
       regarding our hardware components. Following are the implemented hardware
       and the reasons for their selections.


   2.1.1   Transmitter and Receiver

           Initially, we had a lot of options choosing the transmitter and receiver for our
           system. After considering various factors such as availability, cost and size we
           narrowed it down to the Linx LC Series and HP-II Series. First we decided to
           go with the LC Series as it was smaller in size and occupied less space on the
           protoboard. Although it was compact, it only had the following three available
           frequencies: 315 MHz, 418 MHz and 433.92 MHz. For our project purposes
           we needed more than three frequencies and thus we decided against the LC
           series.

            On the other hand the HP-II series was bigger in size, but had eight different
           frequencies in a range of 902-928 MHz, all these frequencies were available
           on the same module through channel selects. The higher frequencies would be
           beneficial in allowing for a smaller antenna length and the variable channel
           selects. As size was not a significant issue as compared to the frequencies, we
           decided to go with the HP-II series. Another good thing about the HP-II series
           was that it worked at a higher frequency as compared to the LC series, which
           made the transmission easier without the use of actual antennas.


   2.1.2   Antennas

           Antennas were not a very important issue for us as most of our testing was
           initially done inside the lab within a short range. But to test our system at a
           greater distance it was very important to decide on the type of antenna we
           would use. There were several choices we had, the top three choices were the
           helical, splatch and whip style antennas. The helical and the splatch were
           unidirectional and the helical was also big in size. In case of implementation
           we decided to use the whip style antenna as it was omni directional, which
           was very important for our project purpose as the hardware at the station level
           would transmit and receive data at the same time. The splatch antennas being
           easily available and fitting all our requirements were the best choice for our
           design purposes.



May 4, 2004                                                                            -4-
                                                               Project No 34 - Final Paper

   2.1.3   Microcontroller

           We had several options for microcontroller which were HC-12 (Motorola),
           Basic Stamp 2 and PIC 16F877. We eliminated HC-12 due to its bigger size
           compare to Basic Stamp 2 and PIC 16F877. Also, HC-12 was really complex
           to program. Although, Basic Stamp 2 was smaller in size but because of its
           availability at the ECE part shop Basic Stamp 2 wasn’t good choice either.
           Also, after researching we found out that Basic Stamp 2 wasn’t cost effective.

           On the other hand, PIC 16F877 was smaller in size as compare to HC-12,
           easily programmable, and easily available. Considering that this PIC would be
           installed on lot of bus stations, size and cost is a very important concern. PIC
           is just a regular basic 40 pin chip. Additionally, it was recommended by our
           TA Mr. Cantzler as he had previous experienced with programming the PIC
           16F877. Even though HC 12 is faster and you can expand to additional
           memory. Since speed is not as important concern as size and cost so we went
           with PIC.


   2.1.4   LCD

           We didn’t have much of an option to pick for LCD even though we would
           have liked to have an LCD with larger display size. Part shop had two types of
           LCD Shelly (40x2) and Allessis (16x2).




  2.2 Software Aspects
      The software was written using C and was compiled using PIC C. As mentioned
      before, the software language for the PIC is C, a rather simple language, which is
      compiled to assembly using PIC C compiler. The simplicity of the language was a
      key factor in the decision on which microcontroller was to be used. The software
      embedded in the PIC modules at each station performs the processing of data
      received from the bus receiver, after being decoded with our Startup Sequence,
      the station receiver as well as providing the data to be sent to other stations
      through the station transmitter.




May 4, 2004                                                                            -5-
                                                                    Project No 34 - Final Paper

                               3. DESIGN DETAILS

3.1   Hardware Components
      The hardware components exist in two different levels, bus hardware and station
      hardware. All Linx transmitters and receivers have been supplied with a clean
      power source by including the suggested supply filter in the HP Series-II
      Transmitter Module Design Guide.

  3.1.1 Bus Hardware

      The bus hardware consists of a Push Button switch, Linx transmitter (TXM-900-
      HP-II at 902 MHz) and a Simple Antenna, as shown in Figure 2.



                     Switch

                                        Microcontroller
                                         PIC 16F877



                                     TXM – HP-II 900

                                       (Transmitter)
                                 Sends signal to nearby Bus
                                          Terminal



                                                          Antenna




                        Figure 3. Bus Hardware Block Diagram

      The identification number for each individual bus is encoded as a 5-bit number by
      the PIC which is hard coded in each PIC based on unique bus. With a 5-bit binary
      encoder, 25 buses with unique identification numbers are possible. The 5-bit
      binary string is then sent serially to the Linx transmitter to be transmitted to the
      station for processing. We had a push button switch installed on each bus which
      is connected to one of the input pin on the PIC. You just push this button, when
      you want to send this information via transmitter. The Linx transmitter was set at
      a frequency of 902 MHz by setting the channel select pins, CS2-CS0, to 000 on
      the transmitter. Alternative frequencies may be set by setting the channel select




May 4, 2004                                                                               -6-
                                                                               Project No 34 - Final Paper

        pins according to Figure 17 in the HP Series-II Transmitter Module Design Guide
        [1]. The signal is then sent via the simple antenna connected to the antenna pin
        (PIN 1) of the transmitter.

        To maintained the reliability of the transmission of each data we gave reliability
        more priority than speed of transmission. The baud rate was selected after
        research had shown that 9600 baud was one of the industry standards and allowed
        for fast transmission of data. Exceeding a baud rate of 9600 baud could possibly
        result in errors during transmission due to information being lost or misinterpreted
        because the information is already being sent at a relatively fast rate compared to
        other industry standards. Speed 9600 baud rate corresponded to 104 milliseconds.


  3.1.2 Station Hardware

                                                                  Antenna




                                             RXM – 900 HP-II
                                                 (Receiver)
                                               Only Receives
                                              signal from other
                                                  Stations



                                                  PIC16F877
                                                                                                    Antenna
                                        1. Decode the received signal.
                                        2. Classify the signal
                                        3. Display appropriate output on the
                                           display.
                                        4. Based on classification decide
                                           whether to forward the signal or
                                           not.


       TXM – 900 HP-II                                                                 RXM – 900 HP-II
          (Transmitter)                                                                    (Receiver)
  - Transmits signal to other                                                       Only Receives signal from
  status to update their status.                LCD Display                                   Bus




                      Antenna




                                   Figure 4: Station Hardware Block Diagram


May 4, 2004                                                                                              -7-
                                                              Project No 34 - Final Paper

      The station hardware consists of a PIC microcontroller (16F877), a Linx bus
      receiver (RXM-900-HP-II at 902 MHz), a Linx station receiver (RXM-900-HP-II
      at 919.87 MHz), a Linx transmitter (TXM-900-HP-II at 919.87 MHz), two simple
      antennas and a 16 X 2 (or 40 X 2) serial input LCD, as shown in Figure 3.

      The bus receiver obtains data sent from the transmitter located on the bus. This
      data is then sent to microcontroller which decodes the information from the BUS
      or from station. Once the Microprocessor classifies the information, it will
      generate 2 Bytes of Data which contains Bus ID, Station ID, Counter and
      Frequency. After processing has concluded which is shown in detail in software
      flow chart, the appropriate data is sent to the LCD for display.

                            L (ft) = 468/Frequency (MHz)                               (1)

      To achieve a reliable wireless link, the length of the antenna leads needed to be a
      ½ - wavelength of the frequency. Using Equation (1) with the frequency equal to
      919.87 MHz, the length of the antenna lead was 6.105 inches and with the
      frequency equal to 921.37 MHz, the length of the antenna lead was 6.095 inches.
      Due to the differences in antenna leads being one hundredth of an inch, all leads
      were cut at slightly over 6 inches because the only accessible tool was a
      conventional ruler.

      In order for the receiver (RXM HP II ) to receive the correct serial data, the baud
      rate it receives should be at least eight time faster than transmitter. After
      sampling, eight times for the same input, we added those numbers up. If the
      number is greater than of equal to six we considered that as digital ONE. If the
      sum is less than of equal to two we considered that as digital Zero. must match the
      baud rate the data is sent from the encoder.




May 4, 2004                                                                          -8-
                                                             Project No 34 - Final Paper

3.2   Software Component

3.2.1 Format of Data Packet

      The information is transmitted in form of data packet which is two bytes long and
      consist the information in following manner. This data packet is preceded by a
      start sequence which is one byte long and followed by a end sequence which is
      also one byte long.



       15 1 4 13 12 1 1 10 9                                               8

       7         6        5         4         3        2         1         0
        FREQ
                          FREQ = 000  900 MHz
                          BUS ID = 10010  22 ILLINI
       BUSID

      STATION             STATION ID = 101010  UNION
         ID
                          Counter  11 or 10 or 01 or 00
      COUNTER



                                Figure 5: Data Packet Format


      As shown in the above figure the first two bits are used as COUNTER for bus
      stop. The next six bits are the STATION ID which is unique to every station. As
      we used six bits we can have up to 64 different stations. The next five bits are
      used as BUS ID which is also unique to every BUS and gives us an option to use
      32 different buses in our database. The last three bits are for FREQ select which
      will help us in distinguishing between different data packets coming from buses
      or different bus stops. The database for the bus and bus stop can be easily be
      increased by just increasing the size of this data packet.




May 4, 2004                                                                         -9-
                                                                        Project No 34 - Final Paper

3.2.2 Software Flowchart

                                             Read Data
                                               From
                                              Receiver




                                               Bus or
                     Bus                                                Bus Stop
                                               another
                                              Bus Stop


                                                                                     Decode Data
                                                                                      From Bus
  Set counter to 3




                                                                                   Read Bus Stop No
  Encode Bus No.




                                                                                     Read Bus No
   Encode Station
        No.




                                                                                       Calculate
                                                                                    Estimated Time
    Send data to                                                                       Of arrival
    Transmitter




                                                                                   Send Display Info
   Send Display                                                                        to LED
    Info to LED




                                                                                     YES
                                             NO

                                                          Counter ==0
                                                                                               Terminate
                           Decrement Count                                                    Transmission




                                        Figure 6: Software Flowchart



May 4, 2004                                                                                            - 10 -
                                                              Project No 34 - Final Paper

      The above flowchart explains the functionality of the software module in our Bus
      Locator System. As we can see, encoded data packet is first received at bus
      station with the help of RXM 900 HP-II. The receiver sends this data packet to the
      Microcontroller – PIC 16F877 where the data packet is decoded and read. The
      Microcontroller first decides depending upon the data packet, whether the
      information is coming from a bus or another bus stop.

      If the information is coming from the bus that has just arrive at the bus stop the
      PIC will modify the data packet and encode the correct BUS ID, STATION ID,
      FREQ and COUNTER value. Counter bits will be set to “11” (3) indicating that
      the information has to be sent to the next three bus stops. The PIC will also send
      this information to the LCD on the station to display the current status of the bus.
      This information will then be send by the PIC to the Transmitter so that the
      modified information can be transmitted to the next bus stop on an appropriate
      frequency.

      If the information is coming form another bus stop the PIC at the receiving bus
      stop will decode the data packet, read the BUS ID, the STATION ID and also the
      COUNTER. Depending upon whether the counter is zero or not, the PIC will
      decrement the counter accordingly, if the counter is already zero the PIC will
      know that the transmission has to be terminated. Otherwise it will just encode the
      new counter value, the new frequency and send this information to the next bus
      stop. The PIC will also depending upon the COUNTER value calculate the
      approximate time of arrival and display the current status of the bus on the LCD
      at the station.




May 4, 2004                                                                            - 11 -
                                                              Project No 34 - Final Paper


                           4. DESIGN VERIFICATION

   4.1 Hardware Testing

   4.1.1 Transmitter and Receiver Testing

      The main components used for the wireless aspect of the project were the Linx
      transmitter and receiver. To test the functionality of the transmitter and receiver,
      a function generator, LEDs and oscilloscope were used. As shown in Figure 7,
      the function generator was set to output a 1 kHz, 1.2 V peak-to-peak square wave.
      The output of the function generator was then connected to the Data In Pin of the
      transmitter. The Data Out Pin of the receiver was then connected to an
      oscilloscope. The results can be seen in Figure 8. As demonstrated, the
      frequencies remained the same, but the peak to peak voltage was amplified to 5 V.
      This change in amplitude is acceptable because binary strings are being sent, all
      high values are equal to VCC and all low values are equal to 0 V can still easily be
      detected by the hardware.




   Figure 7. Transmitter Input                           Figure 8. Receiver Output


  4.1.2 Distance Testing

      The distance testing was done in the Everitt Lab on the second floor. In order to
      test distance, a transmitter, receiver, microcontroller, LCD and LED were used.
      The Data In Pin of the transmitter was connected to the Data Out Pin of
      microcontroller, and the Data Out Pin of the receiver was attached to the Data In
      Pin of the other microcontroller. Connection to the valid Transmission Pin of the
      microcontroller, transmitter and receiver were connected by LED. The LED
      would turn on when a valid transmission was being sent. The transmitted signal
      was sent from one end of the lab to the other end of the lab over an approximate
      distance of 50 ft. We then moved our receiver to a ECE 386 lab but the signal
      extremely corrupted. After talking to our TA, we discover that there is huge



May 4, 2004                                                                          - 12 -
                                                               Project No 34 - Final Paper

      impedance in the walls of the Everitt and it significantly affects our data
      transmission.

   4.1.3 Frequency Selection

      To test the functionality of the frequency select capabilities of the transmitters and
      receivers, a transmitter, receiver, function generator, oscilloscope and LED were
      used. The function generator was connected to the Data In pin of the transmitter.
      The oscilloscope was connected to the Data Out pin of the receiver. An LED was
      connected to the Valid Transmission pin of the receiver and transmitter. When
      the LED was turned on, proper communication between the transmitter and
      receiver was established. The LED remained on when frequency select channels
      were matched on both the transmitter and receiver. However, when the frequency
      select channels on the transmitter and receiver were set differently, the LED
      turned off.

      To make sure that there is no noise generated in successive transmission of data
      between two pair of transmitter and receiver, we connected another pair of
      transmitter and receiver with the above mention connection but this pair has
      different value for channel select. We discover that there was no noise detected on
      the respective receiver and they were both received correct data. Thus, the
      operation of the transmitter and receiver set at one frequency would not affect
      another pair of modules set at another frequency.


4.2 Software Testing
      Testing of the software was done by creating lot of test file. As long as the
      software could be loaded into the PIC microcontroller module, further testing on
      the accuracy of the software would be done in the overall function test. The test
      file was created to determine if valid data would be sent serially from PIC to
      receiver via transmitter. PIC was hard coded with certain sequence of data and
      receiver should output the same result with very little delay.

      Another test was design to determine if a bus identification number could be
      correctly read serially from receiver by PIC. The output of the test file was
      displayed over LCD as well as bit pattern was also seen on Oscilloscope as well
      as LEDs for verification. The values displayed on the LCD and on oscilloscope
      initially did not match the corresponding input. After several tests, and changing
      our RS 232 communication method we finally got our PIC and transmitter
      synchronize for data communication.

      For the error detection, receivers will poll for information eight time faster than
      the transmission rate (104 ms). All the polling information for a particular bit will
      be stored in an array and after polling for eight time it will compute the sum of


May 4, 2004                                                                            - 13 -
                                                                 Project No 34 - Final Paper

      data stored in the array. If the sum is greater or equal to six, then that bit is read as
      “Digital 1”. On the other hand, if the sum is less than or equal to two it will be
      read as “Digital 0”.




May 4, 2004                                                                               - 14 -
                                                      Project No 34 - Final Paper


                                   5. COST ANALYSIS

5.1. Parts
Parts Costs
Transmitter (4 transmitter)                                                      $800.00
Receiver ( 6 Receiver)                                                         $1200.00
Microcontroller PIC 16F877 (4 PIC)                                                 $24.00
LCD Screen (4 LCDs)                                                              $300.00
LED for testing purpose                                                            $10.00
Miscellaneous Components**                                                         $50.00
                                                                          ------------------
Total Parts Cost                                                               $2,384.00




5.2. Labor

Labor Costs
Hourly salary                                                                      $30.00
Hours per week*                                                                          30
# of weeks                                                                               10
Overhead Multiplier                                                                     2.5
                                                                          ------------------
Total Labor Cost                                                             $22,500.00



Total Development Cost (1 Demo Setup)                                        $24,884.00
* average total work for 3 people
** gates, diodes, resistors, wires and protoboard




May 4, 2004                                                                 - 15 -
                                                               Project No 34 - Final Paper


                                  6. CONCLUSION

   6.1 Accomplishments

      The final working of our project was very satisfactory, as we accomplished all our
      goals. Our primary task was to make sure all our modules work independently.
      The first module we worked on was the TXM 900 HP-II transmitter and RXM
      900 HP II receiver system. As this was the basic module for our project we had to
      make sure that this module was working efficiently. We tested this by
      transmitting different data packet and receiving the same data on our receiver.
      Our second module was the PIC 16F877 microcontroller. We tested and learned
      about the PIC 16F877 with the test code provided. After acquiring the knowledge
      of the PIC C programming language, we started programming the control module
      required for our project. We uploaded several versions of our code on the PIC
      16F877 and checked its functionality. The last module we had to work on was
      LCD. The provided LCD sample code was very useful in helping us writing our
      own LCD module. Once all the modules were working independently our final
      task was to integrate them. After integrating we tested and debugged to make sure
      the system was performing all the function required.


   6.2 Challenges

       We came across a lot of challenges during the course of our project. The first
       problem we dealt with was to get rid of the noise between our transmitter-
       receiver system. The reason for the noise was the usage of different grounds for
       our PIC 16F877 and RXM 900 HP II receiver. While testing our PIC we realized
       that we were not getting the right data byte display on our LEDs. After looking
       into the problem we realized that our PIC was calling LCD initialize subroutine
       in the beginning of our code. As there was no LCD wired to the test board the
       code on the PIC did not function as intended. Initially it was hard for the receiver
       to distinguish between different data packets. This issue was finally resolved by
       using the START and END sequence before and after transmitting the data
       packet. As all the team members were unfamiliar to the PIC C language we made
       lots of syntax errors in our code, which was later debugged with the manual
       available in laboratory. The other challenge we had to face was that we could
       only test one PIC at a time because of the lack of availability of the test boards.
       With the help provided by our TA we were able to design and build our own test
       boards.


       RS232




May 4, 2004                                                                            - 16 -
                                                             Project No 34 - Final Paper


   6.3 Future Development Considerations
      In the future, more advanced microcontrollers would enable the BLS system to be
      easily implemented on larger bus routes with lot of database. The PIC 16F877 has
      a small amount of allocated memory which can not handle a large amount of
      information. If the PIC microcontroller was used on a large bus route, multiple
      microcontrollers would be present at each station significantly increasing the
      amount of hardware necessary for optimal operation. The use of more advanced
      microcontrollers would have the capabilities to incorporate additional hardware
      components into the software reducing the amount of hardware in the design. In
      order to assure consistent data transmission, reliable communication hardware
      should be utilized in the production of the BLS system. This would eliminate
      some of the errors encountered with the use of less reliable hardware. Linx
      module had certain uncertainty when they were powered up. We would like to
      investigate other transmitter and receivers that are manufactured.

      We would also like to use LCD with multiple lines so we can constantly display
      lot of bus information instead of overwriting the information every time a new
      bus data is received.

      System could be further modify the system by relaying the bus information to a
      web-hosting server where travelers can check the real time status of the bus using
      Internet. We would also like to develop an algorithm which also calculates
      estimated arrival time instead of just displaying the location.




May 4, 2004                                                                         - 17 -
                                                  Project No 34 - Final Paper


                             7. APPENDIX


===================== Trans.c ==========================
//Trans.c
//
// VERSION: 1.2
//

// Revision History, Updated after every code load
//
//    Developer         Date           Revision
//
//    Richard Cantzler 02/27/2004      Initial Creation
//    Richard Cantzler 03/04/2004      Added NODEBUG to allow
programming.
//                                     Modified main loop and
interrupts to display correctly.
//    Richard Cantzler 04/05/2004      Created version 1.1.
//                                     Needs to output LED's and use
ADC.
//    Richard Cantzler 04/10/2004
//
//    Modified by:            Ruchir Patel
//                      Ankit Gandhi
//                      Kashyap Patel
//
//    Modified Date:    26th April, 2004


/**********************************************************************
********\
*
*
*                P R E P R O C E S S O R   D I R E C T I V E S
*
*
*
\**********************************************************************
********/
//#include <18F452.h>

#include <16F877.h>      // <-- This is the type of PIC you're using.
                         //     Other supported PICs are in:
                         //     C:\Program Files\PICC\Devices

//#device ICD=TRUE
#device *=16 ADC=10      // Use 16-bit pointers, use 10-bit ADC

#fuses HS                // You may or may not want some of these ....
#fuses NOWDT



May 4, 2004                                                             - 18 -
                                                     Project No 34 - Final Paper
#fuses   NOPROTECT
#fuses   NOLVP
#fuses   NODEBUG
#fuses   NOPUT
#fuses   NOBROWNOUT

#use delay(clock=20000000)                    // What speed clock do you
want today?

// These require use of Set_Tris_x()
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
// End Preprocessor Directives


// Always a good idea to write clean code, makes changes easy

#include   <stddef.h>
#include   <string.h>
#include   <math.h>
#include   "Include\TransCompiler.h"
#include   "Include\TransGlobals.h"
#include   <LCD.c>
#include   "Include\TransMisc.c"



/**********************************************************************
********\
*
*
*                    F U N C T I O N   P R O T O T Y P E S
*
*
*
\**********************************************************************
********/

void initTimers( void);
int16 MakeInt(void);
int8 MakeBUSID(void);
void initADC( void);
void timer1ISR( void);
void timer2ISR( void);       // ISR does not stand for Illinois Street
Residence


/**********************************************************************
********\
*
*
*                            M A I N   R O U T I N E
*




May 4, 2004                                                                - 19 -
                                                            Project No 34 - Final Paper
*
*
\**********************************************************************
********/
#pragma zero_ram                     // Interesting command ....
void main( void)
{


   int1 GotData = 0;                           // Standard C, so define variables
up front
   int8 prev_error = 0;

      ID = 0;
      prev_ID = 0x80;

      Backlight_Enabled = 0;
      tempVar = 0;

      disable_interrupts(GLOBAL);              // We don't want to be interrupted
yet

      delay_ms(500);          // wait for voltages to stablize

      Set_Tris_A(MY_TRISA);       //   Port   A's I/O
      Set_Tris_B(MY_TRISB);       //   Port   B's I/O
      Set_Tris_C(MY_TRISC);       //   Port   C's I/O
      Set_Tris_D(MY_TRISD);       //   Port   D's I/O
                                  //   this   might need to be changed if you put
the LCD on port D ....

   output_low(BACKLIGHT);          // You can turn on and off the Backlight
on the LCD if you
                                   // properly use a transister to sinc some
heavy current
   delay_ms(50);
   //lcd_init();
   delay_ms(50);



      initADC();

//Initialization for Start up sequence

           for(i = 0; i < 4; i++)
                 Start_Seq[i] = 0;

           for(i = 4; i < 8; i++)
                 Start_Seq[i] = 1;

//Initialization for End up sequence

           for(i = 0; i < 4; i++)
                 End_Seq[i] = 1;




May 4, 2004                                                                       - 20 -
                                                  Project No 34 - Final Paper
        for(i = 4; i < 8; i++)
              End_Seq[i] = 0;

      //Display_Name = 0;

//Initialization arrays and Send data

        for(i = 0; i < 5; i++)
              BusID[i] = 1;
        // Print Data on LCD

// 01010 --> UNION, 01100 --> ISR, 01001 --> PAR
/*
        if((STATIONID0 == STATIONID2 == STATIONID4 == 0)&& (STATIONID1
== STATIONID3 == 1))
              Display_Name = 20;

        if((STATIONID0 == STATIONID3 == STATIONID4 == 0)&& (STATIONID1
== STATIONID2 == 1))
              Display_Name = 21;

        if((STATIONID0 == STATIONID2 == STATIONID3 == 0)&& (STATIONID1
== STATIONID4 == 1))
              Display_Name = 22;

*/

/*
        for(i = 0; i < 6; i++)
              StationID[i] = 0;
*/
        for(i = 0; i < 2; i++)
              Counter[i] = 1;

        Freq[0] = 1;
        Freq[1] = 0;
        Freq[2] = 0;


        for(i = 0; i < 2; i++)
              Send_Data[i] = Counter[i];

        //for(i = 2; i < 8; i++)
              //Send_Data[i] = StationID[i-2];

        Send_Data[2]   =   STATIONID0;
        Send_Data[3]   =   STATIONID1;
        Send_Data[4]   =   STATIONID2;
        Send_Data[5]   =   STATIONID3;
        Send_Data[6]   =   STATIONID4;
        Send_Data[7]   =   STATIONID5;


        for(i = 8; i < 13; i++)
              Send_Data[i] = BusID[i-8];




May 4, 2004                                                             - 21 -
                                                    Project No 34 - Final Paper
          for(i = 13; i < 16; i++)
                Send_Data[i] = Freq[i-13];


        BUSIDFlag = 1;
        BUSIDCounter = 12;


        Data = MakeInt();
        Display_State = 10; // Done Loading SEND_DATA on LCD
        Display();
        delay_us(50);

      initTimers();               // This is where the interrupts are
enabled again
      delay_ms(50);

     while(FOREVER)
     {


   }
}
// End Main Routine


/**********************************************************************
********\
*
*
*               S U B - R O U T I N E   I M P L E N T A T I O N S
*
*
*
\**********************************************************************
********/

// Purpose:          Initializes timer interrupts
// Precondition:     None
// Postcondition:    Timers and interrupts are enabled
void initTimers(void)
{
   setup_timer_1( T1_INTERNAL | T1_DIV_BY_8 );                  //
confusing?
   setup_timer_2( T2_DIV_BY_4, 0x20, 2);                        // even
more so!
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);
   timer1Count = 0;
   timer2Count = 0;
   timer3Count = 0;
   tempCount = 0;
}

//    Purpose:         Initializes ADC


May 4, 2004                                                               - 22 -
                                                   Project No 34 - Final Paper
// Precondition:     None
// Postcondition:    ADC is configured
void initADC(void)
{
   setup_adc_ports(RA0_ANALOG_RA3_RA2_REF);   // A0 Ref=A2,A3
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel( 0 );
   delay_us(10);
}

int16 MakeInt(void)
{
      int16 temp = 0;
for(i = 0; i < 16; i++)
{
      if(Send_Data[i] == 1)
      {
            bit_set(temp, i);
      }
      else
      {
            bit_clear(temp, i);
      }

}
return temp;
}

int8 MakeBUSID(void)
{
      int8 temp = 0;
for(i = 8; i < 13; i++)
{
      if(Send_Data[i] == 1)
      {
            bit_set(temp, i);
      }
      else
      {
            bit_clear(temp, i);
      }

}
return temp;
}


//End Sub-Routine Implementions



/**********************************************************************
********\
*
*




May 4, 2004                                                              - 23 -
                                                    Project No 34 - Final Paper
*              I N T E R R U P T   S E R V I C E   R O U T I N E S
*
*
*
\**********************************************************************
********/

// Purpose:          Timer1 ISR
// Precondition:     initTimers called
// Postcondition:    Timer1 counter updated
#INT_TIMER1
void Timer1ISR(void)
{
//   disable_interrupts(GLOBAL);
//   set_timer1(Timer1Refresh);

   timer1Count++;
   timer2Count++;
   timer3Count++;
   tempCount++;
//   enable_interrupts(GLOBAL);
}

#INT_TIMER2
void Timer2ISR(void)
{

if(timer1Count > 9)
      {

      if(((!(Input(INPUTPIN))) && BUSIDFlag == 1)||(BUSIDCounter !=
12))// got rid of -ve RP
      {
            // 8 - 12
              Send_Data[BUSIDCounter] = ((Input(INPUTPIN)));
              BUSIDCounter = BUSIDCounter - 1;

                    Display_State = 1; // BusID receiving
                    Display();
                    delay_us(50);

                    Data = MakeInt();
                    Display_State = 10; // Done Loading SEND_DATA on LCD
                    Display();
                    delay_us(50);


                    Send_Data[12] = 1;
                    Send_Data[8] = 0;

              if(BUSIDCounter == 7)
              {
                    BUSIDFlag = 2;
                    BUSIDCounter = 12;




May 4, 2004                                                               - 24 -
                                                       Project No 34 - Final Paper

                    //Display_Name = MakeBUSID();
                    //Display_State = 53; // Done Loading SEND_DATA on
LCD
                    //Display();
                    //delay_us(50);

                    Display_State = 0; // Done Loading SEND_DATA on LCD
                    Display();
                    delay_us(50);


                    Send_Data[12] = 1;
                    Send_Data[8] = 0;

                    for(i = 8; i < 13; i++)
                    {
                          if(Send_Data[i] == 1)
                          {

                                   tempVar = tempVar+(pow(2,(i-8)));
                          }

                    }


              }


              Send_Data[12] = 1;
              Send_Data[8] = 0;

              SendCount = 15;
              StartupCount = 7;
              timer1Count = 0;
      }




// STARTUP SEQN CODE
            else if((!(StartupCount == -1)) && (BUSIDFlag == 2))
            {
                  if(Start_Seq[StartupCount] == 1)
                        {
                              output_high(STARTSEQ);
                              output_high(DATAPIN);
                              Display_State = 40; // 0x20 for High
                              Display();
                              delay_us(50);
                        }

                    else if(Start_Seq[StartupCount] == 0)
                    {


May 4, 2004                                                                  - 25 -
                                                    Project No 34 - Final Paper

                          output_low(STARTSEQ);
                          output_low(DATAPIN);


                          if(StartupCount == 2 || StartupCount == 0)
                          {
                                output_high(STARTSEQ);
                                output_high(DATAPIN);
                          }

                          Display_State = 41; // 0x21 for LOW
                                Display();
                                delay_us(50);
                          }
                  else
                          {
                                output_high(GARBLE);
                                Display_State = 30; // 0x30 for Garble
                                Display();
                                delay_us(50);
                                output_low(GARBLE);
                          }
                          StartupCount = StartupCount - 1;
                          timer1Count = 0;
              }


      // MAIN DATA CODE

                  //output_bit(DATAPIN, Send_Data[SendCount]);

                  else if( !(SendCount == -1)&& (BUSIDFlag      == 2))
                  {
                        if(Send_Data[SendCount] == 1)
                        {
                              output_high(DATAPIN);
                              if(tempVar == 22)
                              {
                                    Display_State = 50; //      ILLINI
                                    Display();
                                    delay_us(50);
                              }
                              else if(tempVar == 20)
                              {
                                    Display_State = 51; //      SILVER
                                    Display();
                                    delay_us(50);
                              }
                              else if(tempVar == 36)
                              {
                                    Display_State = 52; //      AIRBUS
                                    Display();
                                    delay_us(50);
                              }
                              else


May 4, 2004                                                               - 26 -
                                               Project No 34 - Final Paper
                         {
                               Display_State = 56; // 0x20 for
High
                               Display();
                               delay_us(50);
                         }


                  }

                  else if(Send_Data[SendCount] == 0)
                  {
                        output_low(DATAPIN);

                         if(tempVar == 22)
                         {
                               Display_State = 50;    // ILLINI
                               Display();
                               delay_us(50);
                         }
                         else if(tempVar == 20)
                         {
                               Display_State = 51;    // SILVER
                               Display();
                               delay_us(50);
                         }
                         else if(tempVar == 36)
                         {
                               Display_State = 52;    // AIRBUS
                               Display();
                               delay_us(50);
                         }
                         else
                         {
                               Display_State = 56;    // 0x20 for
High
                               Display();
                               delay_us(50);
                         }

                  }
                  else
                  {
                         output_high(GARBLE);
                         Display_State = 30; // 0x30 for Garble
                         Display();
                         delay_us(50);
                         output_low(GARBLE);
                  }

                  SendCount = SendCount - 1;
                  timer1Count = 0;
              }
       }




May 4, 2004                                                          - 27 -
                                                 Project No 34 - Final Paper

    if (timer2Count > 39)
    {
       Backlight_Enabled = !Backlight_Enabled;
       timer2Count = 0;
       if (Backlight_Enabled == 0)
       {
          output_low(BACKLIGHT);
       } else {
          output_high(BACKLIGHT);
       }
    }

}




May 4, 2004                                                            - 28 -
                                                  Project No 34 - Final Paper


================================ Recv.c ===============================


//Recv.c
//
// VERSION: 1.2
//

// Revision History, Updated after every code load
//
//    Developer         Date           Revision
//
//    Richard Cantzler 02/27/2004      Initial Creation
//    Richard Cantzler 03/04/2004      Added NODEBUG to allow
programming.
//                                     Modified main loop and
interrupts to display correctly.
//    Richard Cantzler 04/05/2004      Created version 1.1.
//                                     Needs to output LED's and use
ADC.
//    Richard Cantzler 04/10/2004
//
//    Modified by:            Ruchir Patel
//                      Ankit Gandhi
//                      Kashyap Patel
//
//    Modified Date:    26th April, 2004

/**********************************************************************
********\
*
*
*                P R E P R O C E S S O R   D I R E C T I V E S
*
*
*
\**********************************************************************
********/
//#include <18F452.h>
#include <16F877.h>      // <-- This is the type of PIC you're using.
                         //     Other supported PICs are in:
                         //     C:\Program Files\PICC\Devices

//#device ICD=TRUE
#device *=16 ADC=10      // Use 16-bit pointers, use 10-bit ADC

#fuses   HS              // You may or may not want some of these ....
#fuses   NOWDT
#fuses   NOPROTECT
#fuses   NOLVP
#fuses   NODEBUG
#fuses   NOPUT
#fuses   NOBROWNOUT




May 4, 2004                                                             - 29 -
                                                     Project No 34 - Final Paper
#use delay(clock=20000000)                    // What speed clock do you
want today?

// These require use of Set_Tris_x()
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
// End Preprocessor Directives


// Always a good idea to write clean code, makes changes easy

#include <stddef.h>
#include <string.h>

#include   "Include\RecvCompiler.h"
#include   "Include\RecvGlobals.h"
#include   <LCD.c>
#include   "Include\RecvMisc.c"



/**********************************************************************
********\
*
*
*                    F U N C T I O N   P R O T O T Y P E S
*
*
*
\**********************************************************************
********/

void initTimers( void);
void initADC( void);
void timer1ISR( void);
void timer2ISR( void);       // ISR does not stand for Illinois Street
Residence


/**********************************************************************
********\
*
*
*                            M A I N   R O U T I N E
*
*
*
\**********************************************************************
********/
#pragma zero_ram                     // Interesting command ....
void main( void)
{
   int1 GotData = 0;                 // Standard C, so define variables
up front


May 4, 2004                                                                - 30 -
                                                            Project No 34 - Final Paper
      int8 prev_error = 0;

      ID = 0;
      prev_ID = 0x80;

      // Code Initialization
      RStartCount = 7;
      RecvCount = 15;
      triggerFlag = 0;

      Backlight_Enabled = 0;

      disable_interrupts(GLOBAL);              // We don't want to be interrupted
yet

      delay_ms(500);          // wait for voltages to stablize

      Set_Tris_A(MY_TRISA);       //   Port   A's I/O
      Set_Tris_B(MY_TRISB);       //   Port   B's I/O
      Set_Tris_C(MY_TRISC);       //   Port   C's I/O
      Set_Tris_D(MY_TRISD);       //   Port   D's I/O
                                  //   this   might need to be changed if you put
the LCD on port D ....

   output_low(BACKLIGHT);          // You can turn on and off the Backlight
on the LCD if you
                                   // properly use a transister to sinc some
heavy current
   delay_ms(50);
   lcd_init();
   delay_ms(50);

   initTimers();                   // This is where the interrupts are
enabled again
   delay_ms(50);

      initADC();

      while(FOREVER)
      {
         readID();                 // Read in the ID
         readADC();                // Read in the value of the ADC

         if (ID != prev_ID)     // If the ID has changed
         {
            if (bit_test(ID, 1) == 1)      // Set Display based on ID
            {
               if (OldDisplay_State != 0x21)
               {
                  OldDisplay_State = 0x20;
                  //Display();
                  delay_us(50);
                  OldDisplay_State = 0x21;
               }
            } else if (bit_test(ID, 0) == 1) {
               if (OldDisplay_State != 0x11)


May 4, 2004                                                                       - 31 -
                                                  Project No 34 - Final Paper
               {
                   OldDisplay_State = 0x10;
                   //Display();
                   delay_us(50);
                   OldDisplay_State = 0x11;
               }
            } else {
               OldDisplay_State = 0x00;
            }

            //Display();

            prev_ID = ID;
         } else {
            if (0x21 == OldDisplay_State)
            {
               //Display();
            }
         }

         delay_us(50);
//         delay_ms(1);
     }

}
// End Main Routine


/**********************************************************************
********\
*
*
*               S U B - R O U T I N E   I M P L E N T A T I O N S
*
*
*
\**********************************************************************
********/

// Purpose:          Initializes timer interrupts
// Precondition:     None
// Postcondition:    Timers and interrupts are enabled
void initTimers(void)
{
   setup_timer_1( T1_INTERNAL | T1_DIV_BY_8 );                //
confusing?
   setup_timer_2( T2_DIV_BY_4, 0x20, 2);                      // even
more so!
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);
   timer1Count = 0;
   timer2Count = 0;
   timer3Count = 0;
   j = 0;
}


May 4, 2004                                                             - 32 -
                                                    Project No 34 - Final Paper

// Purpose:          Initializes ADC
// Precondition:     None
// Postcondition:    ADC is configured
void initADC(void)
{
   setup_adc_ports(RA0_ANALOG_RA3_RA2_REF);    // A0 Ref=A2,A3
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel( 0 );
   delay_us(10);
}

//End Sub-Routine Implementions



/**********************************************************************
********\
*
*
*              I N T E R R U P T   S E R V I C E   R O U T I N E S
*
*
*
\**********************************************************************
********/

// Purpose:          Timer1 ISR
// Precondition:     initTimers called
// Postcondition:    Timer1 counter updated
#INT_TIMER1
void Timer1ISR(void)
{
//   disable_interrupts(GLOBAL);
//   set_timer1(Timer1Refresh);

     timer1Count++;
     timer2Count++;
     timer3Count++;

//     enable_interrupts(GLOBAL);
}

#INT_TIMER2
void Timer2ISR(void)
{

// MY CODE STARTS

        if(input(LR7)) // PIN LR7 is high
        {
              triggerFlag = 1;
        }
        if (timer1Count > 9 && triggerFlag == 1)
        {
        // Analyzing Start up seqn


May 4, 2004                                                               - 33 -
                                                    Project No 34 - Final Paper
              if(!(RStartCount == -1))
              {
                    if(input(LR7))
                          {
                                output_high(L3);
                                Display_State = 0x40; // 0x20 for High
                                Display();
                                delay_us(50);
                                RStartCount = RStartCount - 1;
                          }

                    else if( !input(LR7) )
                          {
                                output_low(L3);
                                Display_State = 0x41; // 0x21 for LOW
                                Display();
                                delay_us(50);
                                RStartCount = RStartCount - 1;
                          }
                    else
                          {
                                output_high(L2);
                                Display_State = 0x30; // 0x30 for Garble
                                Display();
                                delay_us(50);
                                output_low(L2);
                          }

                          timer1Count = 0;
              }


              else if( !(RecvCount == -1))
                    {

                          Recv_Data[RecvCount] = input(LR7);
                          output_bit(L3, input(LR7));

                          if(Recv_Data[RecvCount] == 1)
                          {
                                output_high(L1);
                                Display_State = 0x20; // 0x20 for High
                                Display();
                                delay_us(50);
                          }

                          else if(Recv_Data[RecvCount] == 0)
                          {
                                output_low(L1);
                                Display_State = 0x21; // 0x21 for LOW
                                Display();
                                delay_us(50);
                          }
                          else
                          {
                                output_high(L2);


May 4, 2004                                                               - 34 -
                                                          Project No 34 - Final Paper
                                   Display_State = 0x30; // 0x30 for Garble
                                   Display();
                                   delay_us(50);
                                   output_low(L2);
                             }

                             RecvCount = RecvCount - 1;
                             timer1Count = 0;
                     }


/*
tempVar = 0;

        for(i = 2; i < 8; i++)
        {
              if(Send_Data[i] == 1)
              {
              tempVar = tempVar+(2^(i-2));
              }

        }

        if(tempVar == 16)
       Display_State = 0x16;
        else if (tempVar == 18)
        Display_State = 0x18;
        else if (tempVar == 31)
         Display_State = 0x31;
        else if (tempVar == 29)
          Display_State = 0x29;
        else
          Display_State = 0x02;
      Display();



*/
        }
        //    MY CODE ENDS



/*
     if (timer1Count > 30)
     {
        if (timer1Count > 39)
        {
           timer1Count = 0;
        }
        output_low(LED4);
        output_high(LED3);
        output_high(LED2);
        output_high(LED1);
     } else if (timer1Count > 20) {
        output_high(LED4);


May 4, 2004                                                                     - 35 -
                                                  Project No 34 - Final Paper

         output_low(LED3);
        output_high(LED2);
        output_high(LED1);
     } else if (timer1Count > 10) {
        output_high(LED4);
        output_high(LED3);
        output_low(LED2);
        output_high(LED1);
     } else {
        output_high(LED4);
        output_high(LED3);
        output_high(LED2);
        output_low(LED1);
     }
*/
     if (timer2Count > 39)
     {
        Backlight_Enabled = !Backlight_Enabled;
        timer2Count = 0;
        if (Backlight_Enabled == 0)
        {
           output_low(BACKLIGHT);
        } else {
           output_high(BACKLIGHT);
        }
     }

//     enable_interrupts(GLOBAL);
}




May 4, 2004                                                             - 36 -
                                                          Project No 34 - Final Paper

                                 8. REFERENCE

[1] Linx Technologies, “HP Series-II Transmitter Module Design Guide,” March 2004,
http://www.linxtechnologies.com/ldocs/pdfs/hptransman.pdf.

[2] Linx Technologies, “HP Series-II Receiver Module Design Guide,” March 2004,
http://www.linxtechnologies.com/ldocs/pdfs/hpreceivman.pdf.

[3] Microchip, “ PIC16F87x Data Sheet”, March 2004,
www.microchip.com/download/lit/pline/ picmicro/families/16f87x/30292c.pdf




May 4, 2004                                                                       - 37 -

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:3
posted:12/17/2012
language:Latin
pages:40