user guide ktgps1

Upload: saikripa121

Post on 03-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 User Guide Ktgps1

    1/14

    GPS Receiver

    Build and program your own GPS receiver.

    Contents

    OverviewChallenge 1: Understanding GPS Data

    Collecting Your ComponentsoConnecting the Receiver to Your ComputeroSetting up a Terminal Emulatoro

    Understanding GPS DataoChallenge 2: Controlling the Receiver

    Collecting Your Componentso

    Connecting the Receiver to the ChipoDisplaying Raw GPS Data on the LCDoParsing the Raw GPS DataoSelecting GPS Output StreamsoDisplaying Specific GPS Data ElementsoFormatting GPS Data on Two Lineso

    Overview

    In this project, you will build an interface to the GlobalSat EM-406A GPS Receiver. TheEM-406A is a 20-channel GPS receiver based on the SiRF StarIII chipset, and it features

    a built- in antenna. After building the interface circuit, you will learn how to customize it

    to display more than 30 standard GPS data types, including latitude, longitude, altitude,

    velocity, heading, time, and da te.

    Figure 1. GlobalSat EM-406A GPS Receiver.

    Like most GPS receivers, the EM-406A conforms to the standard NEMA SiRF interface

    protocol, so the code you write in this project will work with most other GPS receivers.

    Challenge 1: Understanding GPS Data

    In order to better understand the GPS data format, you will first connect your GPSreceiver directly to your computer through the Machine Science

    programming cable. GPS receivers are capable of transmitting a large

    volume of data, which can be difficult to see on a small LCD screen. By

    viewing the data on a computer monitor, you will be able to learn about thedifferent GPS data streams and data types.

    Collecting Your Com ponents

    In order to connect your GPS receiver to your computer, you will need the followingcomponents:

    Part Quantity Description

    A 1 GlobalSat EM-406A GPS Engine

    B 1 Connector harness (6-pin)

    C 1 Bent header (6-pin)

    D 1 Bent header (4-pin)

    Connecting the Receiver to Your Computer

    Using Figure 2 as a guide, connect the GPS receiver to the programming board, which

    will link it to your computer. To avoid intefering with the microcontroller, build this

    circuit in an area of the board away from the chip. Figure 3 shows one way to lay out this

    circuit. To orient the GPS unit properly, note the position of the grey wire in Figure 3.

  • 7/28/2019 User Guide Ktgps1

    2/14

    Figure 2. Connecting the GPS receiver to the computer (schematic).

    Figure 3. Connecting the GPS receiver to the computer (photo).

    Setting up a Terminal Em ulator

    Connected as shown in Figure 2, the GPS receiver will send satellite data to your

    computers COM port. To view the data, you will need to run a terminal emulator--a

    program that emulates an older-style text-only computer terminal. Depending on youroperating system, your computer may already have a terminal emulator, or you may need

    to download one from the Internet:

    Windows (Vista): TeraTerm Pro Web is available here:http://www.ayera.com/teraterm/Windows (pre-Vista): HyperTerminal is available in the Start menu underPrograms > Accessories > Communication.

  • 7/28/2019 User Guide Ktgps1

    3/14

    Macintosh: ZTerm comes pre-installed with OSX and above.Linux: CuteCom can be found at: http://cutecom.sourceforge.net/

    The instructions in this section are for installing TeraTerm Pro Web, but should give you

    enough information to help you set up any of the other programs listed above.

    1. Determine which COM port your Machine Science programming board is usingby viewing the Options menu in the Programming Window.

    2. Download TeraTerm Pro Web from http://www.ayera.com/teraterm/

    3. Unzip the .zip file to a convenient location on your hard drive.

    4. Open the folder and double click on the file ttermpro.exe. You will see a dialogbox like the one shown in Figure 4.

    Figure 4. New connection dialog box.

    5. Select Serial and the COM port being used by your Machine Science

    programming board. You should now see unintelligible characters scrolling acrossand down your screen as shown in Figure 5.

  • 7/28/2019 User Guide Ktgps1

    4/14

    Figure 5. TeraTerm Window.

    6. The reason you see a jumble of characters is that you need to set the baud rate inbaud rate in your terminal program to match the baud rate of the GPS receiver.

    Select Serial port... from the Setup menu. You should now see a dialog box like

    the one shown in Figure 6.

    Figure 6. Serial port setup.

    7. Select 4800 for the baud rate. You should now see lines of GPS data being

    updated every second on your screen, as shown in Figure 7.

  • 7/28/2019 User Guide Ktgps1

    5/14

    Figure 7. Term inal emulator.

    Understanding GPS Data

    GPS receivers are capable of transmitting eight types of GPS data streams, shown below:

    Option Description

    GGA Time and position data

    GLL Latitude, longitude, time and status

    GSA GPS receiver operating mode, satellites used in the position solution,

    and DOP values

    GSV The number of GPS satellites in view, satellite ID numbers, elevation,

    and azimuth

    MSS Signal-to-noise ratio, signal strength, frequency, and bit rate from a

    radio-beacon, receiver

    RMC Time, date, position, course and speed data

    VTG Course and speed information relative to the ground

    ZDA Pulse Per Second (PPS) timing message

    Referring to Figure 7 (or your terminal emulator, if it is still running on your computer),

    you should see four types of GPS data streams: GGA, RMC, GSV, and GSA. These are

    the four default data streams that are transmitted by the GPS receiver. Each stream is

    transmitted on a single line. An example of a GGA data stream is shown below.

    $GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M, , , ,0000*18

  • 7/28/2019 User Guide Ktgps1

    6/14

    Each GPS data stream can have up to sixteen GPS data fields. The data fields are

    separated by commas, as shown in the sample above. Table 3 below details the data fields

    contained in the GGA data stream.

    Nam e Example Description

    Message ID $GPGGA GGA protocol header

    UTC Time 161229.487 hhmmss.sss (h=hours,m=minutes, s=seconds)

    Latitude 3723.2474 ddm.mmmm (d=degrees,

    m=minutes)

    N/S Indicator N N=north or S=south

    Longitude 12158.3416 dddmm.mmmm (d=degrees,

    m=minutes)

    E/W Indicator W E=east or W=west

    Position Fix Indicator 1 0=fix not valid, 1,2, or 3= fixvalid

    Satellites Used 07 Range 0 to 12

    HDOP 1.0 Horizontal dilution of

    precision

    MSL Altitude 9.0 Meters above sea level

    Units M Meters

    Geoid Separation Meters

    Units Meters

    Age of Diff. Corr. Seconds

    Diff. Ref. Station ID 0000

    Checksum *18 Check for valid data

    Carriage return and line feed

    indicating end of message

    Don't worry about understanding all of the GPS data types shown in this table. The ones

    of greatest interest to you will probably be time, latitude, longitude, and altitude. In thenext challenge, you will learn how to display this information in a meaningful way on

    your LCD.

    Challenge 2: Controlling the Receiver

    In this challenge, you will construct a circuit connecting the EM-406A to

    the Atmega Board and program the chip to display readable GPS data onthe LCD.

  • 7/28/2019 User Guide Ktgps1

    7/14

    Collecting Your Com ponents

    In order to build the circuit, you will need the following components:

    Part Quantity Description

    A 1 GlobalSat EM-406A

    B 1 Connector harness (6-pin)

    C 1 Bent header (6-pin)

    D 1 Atmega Board

    Connecting the Receiver to the Chip

    Using the schematic in Figure 8 as a guide, add your components to the breadboard.

    Figure 9 shows an example of a completed board for this circuit. Since the leads on the

    GPS receiver are not labeled, you may need to examine the picture to make the correctconnections.

    Figure 8. Connecting GPS receiver to the Atmega168 (schem atic).

  • 7/28/2019 User Guide Ktgps1

    8/14

    Figure 9. Connecting GPS receiver to the Atmega168 (photo).

    Displaying Raw GPS Data on the LCD

    The following code will allow you to begin receiving data from your GPS receiver and

    displaying the information on your LCD. In this first step, you will not be parsing the

    data from your receiver. As you learned in the previous challenge, GPS receivers can

    produce a lot of data, so your tiny LCD will quickly fill up with a lot of numbers, letters,

    and symbols. While you will not be able to read the data, it will indicate that your circuitis working properly. (It also looks kind of cool!)

    IMPORTANT NOTE: The GPS receiver and the Machine Science programming board

    both use the same pin for transmitting data to the Atmega168. You must disconnect thewire linking the GPS pin 4 to the Port D0 of the Atmega168 before downloading your

    code. You can immediately reconnect this wire once the code has been downloaded.

    #include "mxapi.h"1.#include "usart.h"2.

    #include "lcd.h"3.4.

    int main ( void )5.{6.

    char gps_characters; //Declare a variable for7.storing GPS characters

  • 7/28/2019 User Guide Ktgps1

    9/14

    usart_init ( 4800 ) ; //Initialize the USART to8.4800 baud

    lcd_init () ; //Initialize your LCD9.while ( 1 == 1 ) //Start an infinite loop10.{11.

    gps_characters=usart_read () ; //Read each12. character from the GPS

    lcd_character ( gps_characters ) ; //Display13.each character on the LCD

    }14.}15.

    Parsing the Raw GPS Data

    In order to better view the data on your LCD, you will need to parse the raw data stream

    from the GPS receiver. In Figure 7, you can see that the terminal emulator on yourcomputer displays each data stream on a separate line. It does this by checking for a

    carriage return and line feed, the ASCII characters 13 and 10, at the end of each data

    stream (as shown in the last rows of Table 3). When the terminal emulator finds these

    two characters, it starts the next data set on a new line, making the data much easier to

    read than if it were simply a continuous stream.

    The microcontroller has no built-in ability to parse data. As you may have seen in the

    previous exercise, the carriage return and line feeds at the end of each data string are

    displayed on the LCD as more data. As a result, using the previous code, the GPS data

    was displayed on the LCD in long stream without easily discernible breaks.

    The next code sample introduces breaks after each line of data, just like the terminal

    emulator did. It checks continuously for a line feed character (ASCII 10), and when it

    gets one, it repositions LCD's cursor at the start of the first line before displaying the next

    character. The data on the display remains somewhat difficult to read, since all of thedifferent GPS data streams are displayed, but it is easier to pick out patterns in the data.

    #include "mxapi.h"1.#include "usart.h"2.#include "lcd.h"3.

    4.

    int main ( void )5.

    6. {char gps_characters; //Declare a variable to7.

    store GPS characters

    usart_init ( 4800 ) ; //Initialize the USART to8.4800 baud

    lcd_init () ; //Initialize the LCD9.while ( 1 == 1 ) //Start an infinite loop10.

  • 7/28/2019 User Guide Ktgps1

    10/14

    {11.gps_characters = usart_read () ; //Read12.each character from the GPS

    lcd_character ( gps_characters ) ; //Display13.each character on the LCD

    if ( gps_characters == 10 ) //Check for the14. line feed (ASCII 10) character

    {15.lcd_instruction ( FIRST_LINE ) ; //Move16.the cursor to the first line

    }17.}18.

    }19.

    Programming Challenge

    Modify your code so that each line new line scrolls up in the same way that it displays onyour computer monitor. This is difficult!

    Selecting GPS Output Streams

    The following code turns on and off specific GPS data streams. Remember that the

    receiver is capable of transmitting any or all of the eight different GPS streams listed in

    Table 2 at a rate of up to 100 Hertz each. In order to display the data on the LCD, it isbest to turn on only one stream and turn off the rest, using a function called gps_setdata.

    This function takes two arguments: the first argument selects the GPS stream that you

    want to turn on or off; the second argument determines how frequently (in Hertz) the

    GPS receiver transmits the stream. A value of 0 turns off the stream entirely, while avalue of 1 to 99 specifies a transmission frequency of 1 to 99 times a second.

    #include "mxapi.h"1.#include "usart.h"2.

    #include "lcd.h"3.#include "gps.h"4.

    5.

    int main ( void )6.7. {

    char gps_characters; //Declare a variable to8.

    store GPS characterusart_init ( 4800 ) ; //Initialize the USART to9.4800 baud

    lcd_init () ; //Initialize the LCD10.delay_ms ( 2000 ) ; //Delay while GPS receiver11.warms up

    12.

  • 7/28/2019 User Guide Ktgps1

    11/14

    /* Turn off all NMEA formats except the one13.you want to see. */

    gps_setdata (NMEA_GGA, 1 ) ; //Turn on GGA14.format at 1 Hertz

    gps_setdata (NMEA_GSA, 0 ) ; //Turn off GSA15.

    format (0 Hertz)gps_setdata (NMEA_GSV, 0 ) ; //Turn off GSV16.format (0 Hertz)

    gps_setdata (NMEA_RMC, 0 ) ; //Turn off RMC17.format (0 Hertz)

    while ( 1 == 1 ) //Run the following code in an18.infinite loop

    {19.gps_characters = usart_read () ; //Read20.each character from the GPS

    lcd_character ( gps_characters ) ; //Display21.each character on the LCD

    if ( gps_characters== 10 ) //Check for the22.line feed (ASCII 10) character

    {23.lcd_instruction ( FIRST_LINE ) ; //Move the24.cursor to the first line

    }25.}26.

    }27.

    You do not need to select a GPS data stream every time you program the device. Once a

    stream is selected, the receiver displays only that stream until the gps_setdata function iscalled again.

    Programming Challenge

    Try changing the GPS stream displayed by your GPS receiver. Try changing how often

    the GPS stream is updated.

    Displaying Specific GPS Data Elem ents

    With the following code, you can display specific GPS data elements, such as time,

    latitude, longitude, and altitude, from the selected data stream. To simplify matters, every

    GPS data stream is parsed in the background by a function within the gps.h header file.The parsed data is stored in an array called gps_data[ ], with each value in the array

    representing a different GPS data element. You can reference any element in the

    gps_data[ ] array in your code.

  • 7/28/2019 User Guide Ktgps1

    12/14

    For example, with the GGA data stream, selected a line of data might look like this:

    $GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M, , , ,0000*18

    In this instance, gps_data[0] would equal $GPGGA, gps_data[1] would equal

    161229.487, gps_data[2] would equal N, and so on.

    The following table shows the gps_data[] values for some of the more useful data

    elements in the GGA, RMC, and VTC data streams.

    GPS Data Example Units Format GGA RBC VTG

    Message ID $GPGGA 0 0 0

    Latitude 3723.2475 Degrees ddmm.mmmm 2 3and

    minutes

    North/South N 3 4Longitude 12158.3416 Degrees dddmm.mmmm 4 5

    and

    minutes

    East/West W 5 6

    Altitude 9.0 Meters 9

    Speed 0.2 Kilometers 7

    / hour

    Course 309.62 Degrees 8 1

    Time 161229.487 hhmmss.ss 1 1Date 120598 ddmmyy 9

    Satellites 07 0 to 12 7

    This program uses the chip's internal interrupts, which allow the microcontroller toexecute multiple tasks at the same time. A few new statements are added to enable and

    initialize the interrupts.

    #include "mxapi.h"1.#include "usart.h"2.

    #include "lcd.h"3. #include "gps.h"4.5.

    int main ( void )6.7. {

    usart_init ( 4800 ) ; //Initialize the USART to8.4800 baud

  • 7/28/2019 User Guide Ktgps1

    13/14

    usart_interrupt_rx ( ENABLE) ; //Enable9.interrupts for the USART

    sei () ; //Turn on interrupts10.lcd_init () ; //Initialize the LCD11.

    12.

    while ( 1 == 1 ) //Start an infinite loop13. {14.lcd_instruction ( FIRST_LINE ) ; //Move the15.cursor to the first line

    lcd_instruction ( CLEAR) ; //Clear the LCD16.lcd_text ( gps_data [ 2 ]) ; //Display the 3rd17.value in the selected data stream

    }18.}19.

    Formatting GPS Data on Two Lines

    The last code example in this project will display and format multiple GPS data fields on

    both lines of the LCD. The added functions in this example should be familiar to youfrom other Machine Science projects.

    #include "mxapi.h"1.#include "usart.h"2.#include "lcd.h"3.

    #include "gps.h"4.5.

    int main ( void )6.

    7. {usart_init ( 4800 ) ; //Initialize the8.Atmega168s USART to 4800 baud

    usart_interrupt_rx ( ENABLE) ; //Enable9.interrupts for the USART

    sei () ; //Turn on interrupts10.lcd_init () ; //Initialize your LCD11.

    12.

    while ( 1 ) //Run the following code in an13.infinite loop

    {14.lcd_instruction ( FIRST_LINE ) ; //Move the15.cursor to the first line

    lcd_text ( gps_data [ 2 ]) ; //Display value16.of third data field

    lcd_character ( ':' ) ; //Display ':'17.character

  • 7/28/2019 User Guide Ktgps1

    14/14

    lcd_text ( gps_data [ 3 ]) ; //Display value of18.fourth data field

    19.

    lcd_instruction ( SECOND_LINE ) ; //Move the20.curse to the first line

    lcd_text ( gps_data [ 4 ]) ; //Display value21. of fifth data field

    lcd_character ( ':' ) ; //Display ':'22.character

    lcd_text ( gps_data [ 5 ]) ; //Display value of23.sixth data field

    lcdBlankLine () ; //Send blanks to24.clear the lines

    }25.}26.