• PicŪ Basic


  • Using the Amicus GPS Shield with the Proton compiler

    GPS. What is it?
    For those who are unfamiliar with the term GPS, it stands for Global Positioning System, and is a method of locating a receiver in three dimensional space anywhere on the planet.

    In order for GPS to operate, a network of satellites were placed into orbit, each broadcasting a radio signal. The information transmitted from the satellites is specific enough that the GPS receiver's firmware can identify its location in space, and the time that the signal took to travel from the satellite to the GPS receiver. This is termed TOA (Time Of Arrival). Using many different signals, the GPS firmware is able to triangulate the position of the receiver. The result of the triangulation of at least three satellites enables the firmware to calculate, within a margin of error, where the device is located in terms of its latitude (East-West) and longitude (North-South).

    Each satellite contains an atomic clock which is extremely accurate, and is continually synchronized with the other members of the network. This is important for location accuracy, but it also means that anyone with a GPS receiver also has a precise time piece, because as well as transmitting location information, the satellites also transmit time and date information.


    GPS shield
    The Amicus GPS shield contains a 16 channel ZX4120 GPS receiver, as well as a 16k byte (128 kbit) serial (I2C) eeprom, and a 3 Volt, 12mm battery socket in order to maintain the receiver's built-in RTC (Real Time Clock). An SMA socket allows attachment of the GPS receiver's aerial.


















    The circuit for the GPS shield is very straightforward, and is shown below:



















    There is space on the PCB for an additional three I2C eeproms, each with a differing address, as shown below:



















    Software

    The receiver transmits a series of ASCII strings serially at 9600 baud. The strings contain all the required information in a format known as NMEA0183. This is a standardised format, where the strings are separated into sentences, each sentence contains differing information. An example of the output is shown below:

    $GPGGA,112344.237,5681.9100,N,00030.8303,E,1,10,00.9,6.6,M,45.8,M,,*65
    $GPGSV,3,1,11,3,54,146,47,6,45,136,47,8,08,292,33, 11,29,265,46*48
    $GPGSV,3,2,11,14,15,110,25,18,18,045,25,19,84,190, 46,22,47,069,41*7F
    $GPGSV,3,3,11,26,20,085,39,28,16,323,35,32,11,197, 30,,,,*4C
    $GPRMC,112344.237,A,5681.9100,N,00030.8303,E,0.05, 303.00,120110,020.3,E,A*65
    $GPVTG,303.00,T,,,0.00,N,0.00,K,A*70


    Each sentence starts with the text $GP, and the following characters indicate which type of sentence follows. For example, the location and time sentence that we'll use is $GPRMC. The values contained within the sentence are all comma delimited for easy parsing, and break down to:

    112344.237 Time of fix hh:mm:ss (11:23:44) UTC (milliseconds after the decimal point)
    A Navigation receiver warning (A = Valid position, V = Void)
    5681.9100,N Latitude 56 deg. 81.91 min. North
    23710.7003,W Longitude 237 deg. 10.7003 min. West
    0.05 Speed over ground. (in Knots)
    303.00 Course Made Good. (degrees true)
    120110 UTC Date of fix, dd:mm:yy (12 December 2010)
    020.3,E Magnetic variation, 20.3 deg. East
    A*65 Checksum

    In order to see the sentences transmitted on the IDE's serial terminal, use the following program:

    Code:
    '
    ' Re-transmit the GPS NMEA sentences to the serial terminal
          Include"Amicus18.inc"        ' Configure the compiler for a PIC18F25K20 at 64MHz. i.e. An Amicus18 board
    '
    ' Setup the software serial port to receive data from the GPS receiver
    '
        Declare Serial_Baud = 9600   ' GPS receiver baud rate
        Declare Rsin_Pin = PORTA.1   ' From GPS receiver TX line
        Declare Rsin_Mode = 0        ' Non-Inverted serial data
    
        Dim bChar As Byte            ' Holds the character to receive and transmit
    '-----------------------------------------------------------------------------
    Main:
        While                         ' Create an infinite loop
            bChar = RSIn             ' Read a character from the GPS unit
            HRSOut bChar             ' Transmit the character to the serial terminal
        Wend                         ' Do it forever
    
    Once the program is compiled and loaded into the Amicus18's microcontroller, open the serial terminal and use the default baud rate of 9600. You will see that each group of sentences is transmitted at 1 second intervals.
















    However, the sentences are confusing to look at, and with all that information on the screen it's difficult to pick out the relevant parts, and virtually impossible to work with. We need to parse it into a more easily workable format, where each parameter is a variable.

    Luckily, the sentences are easy to parse because of the comma delimiters, and a parsing example program is shown below:

    Code:
    '
    ' Amicus18 GPS Receiver Shield Demo
    '
    ' Receive GPS data and parse it into date, time, and position
    ' Display the information on the serial terminal
    '
        Include "Amicus18.inc"                                      ' Configure the compiler for a PIC18F25K20 at 64MHz. i.e. An Amicus18 board
        Declare Float_Display_Type = Fast                           ' Faster, more accurate floating point display routine
        
        Include "GPS.inc"                                           ' Load the GPS routines into the program
           
    '------------------------------------------------------------------------------
    ' Main program loop starts here
    '
    Main:      
        While                                                       ' Create an infinite loop
            GPS_Parse()                                             ' Gather the GPS serial data and parse it
            '
            ' Display the GPS information on the serial terminal
            '
            HRSOut "Date: ", Dec2 GPS_Day, ":", Dec2 GPS_Month, ":", Dec2 GPS_Year, 13,_
                   "Time: ", Dec2 GPS_Hours, ":", Dec2 GPS_Minutes, ":", Dec2 GPS_Seconds, " UTC", 13
            Select GPS_FixType                                      ' Has a GPS fix has occured?
                Case > 0                                            ' Yes. So display the results
                    HRSOut "Latitude: ", Dec4 GPS_Latitude, " ", GPS_LatBearing, 13,_ 
                           "Longitude: ", Dec4 GPS_Longitude, " ", GPS_LonBearing, 13,_ 
                           "Satellites in view: ", Dec GPS_SatsInView, 13,_
                           "Fix type: ", Dec1 GPS_FixType, 13
                Case Else                                           ' Otherwise...
                    HRSOut "Satellites in view: ", Dec GPS_SatsInView, 13, "No GPS Fix\r"
            EndSelect       
            DelayMS 255                                             ' Wait before taking another GPS sample
        Wend                                                        ' Do it forever
    The above GPS parsing program, as well as other examples, can be downloaded from here: GPS_Shield_Sources.zip

    Unzip the file and place it in the compiler's User folder located at "C:\Documents and Settings\User Name\PDS\User". For Vista and Windows 7 Operating Systems it will be "C:\Users\User Name\PDS\User"

    After compiling the program and loading it into the Amicus18's microcontroller, open the serial terminal and it will be displaying the Time, Date, Latitude, and Longitude. Note that latitude and longitude values will only be displayed if a valid satellite lock is accomplished:




















    Because the GPS receiver has a built in Real Time Clock (RTC) and a backup battery, the correct time and day will be displayed even if the aerial is unplugged. As long as it has previously had a valid GPS lock. This will be corrected whenever a signal from a satellite is received, even if no location information is present. This means that you have in your possession the accuracy of an atomic clock! Therefore, the program will always display the time and date.

    ZX4120 GPS module overview
    The GPS module WD-G-ZX4120 is a high sensitivity ultra low power consumption cost efficient, compact size, GPS module board designed for a broad spectrum of OEM system applications, and is based on the Nemerix chipset. The GPS module receiver will track up to 16 satellites at a time while providing fast time-to-first-fix and a default 1Hz navigation update.

    The WD-G-ZX4120 design utilises the latest surface mount technology and high level circuit integration to achieve superior performance while minimising dimension and power consumption. This hardware capability combined with software intelligence makes the board easy to be integrated and used in all kinds of location based applications or products. The module communicates via RS232 (TTL level) with the NMEA0183 protocol.

    Electrical Characteristics

    General
    Frequency L1, 1575.42 MHz
    C/A code 1.023 MHz chip rate
    Channels 16

    Sensitivity
    Tracking -152dBm typical
    Acquisition -139dBm typical

    Accuracy
    Position 7 meters CEP (90%) horizontal, SA
    Velocity 0.1 meters/second
    Time 1 microsecond synchronised to GPS

    Datum
    Default WGS-84

    Acquisition Rate (Open sky, stationary requirements)
    Reacquisition 0.1 sec, average
    Snap start 2 sec, average
    Hot start 10 sec, average
    Warm start 38 sec, average
    Cold start 45 sec, average

    Dynamic Conditions
    Altitude 18,000 meters (60,000 feet) max
    Velocity 515 meters/second (1000 knots) max
    Acceleration 4g, max
    Jerk 20 meters/second, max

    Power
    Main power input 3.3 ą5% VDC input.
    Power consumption 89mW (Continuous mode)
    Supply Current 27 mA @ 3.3V(Continuous mode)

    Serial Port
    Electrical interface One full duplex serial communication, TTL interface
    Protocol message NMEA-0183, version 3.0
    Default NMEA GGA, GSA, GSV, RMC and VTC. 9600 baud rate, 8 bits data, 1 start, 1 stop, no parity.

    Time-1PPS Pulse
    Level TTL
    Pulse duration 100ms
    Time reference At the pulse positive edge
    Measurements Aligned to GPS second, +-1 microsecond


    Suggest External Antenna Specification
    Gain 20dB(including cable loss)
    Noise figure 1.5dB
    Current 3 ~ 30mA
    Operate Voltage 2.5 ~ 2.8V

    Environmental Characteristics
    Operating temperature range -40 deg. C to +80 deg. C
    Storage temperature range -55 deg. C to +100 deg .C

    Physical Characteristics
    Dimension: 25.9 mm x 25.9 mm x 2.7 mm
    Weight: 3.4g

    Physical Dimensions