MEL PICBASIC Forum - Amicus18 with GPS Shield


  • Amicus18 with GPS Shield

    Crownhill has a new GPS shield for the Amicus18. The Amicus GPS shield contains a 16 channel ZX4120 (or equivalent) GPS receiver, as well as a 16k byte (128 kbit) serial (I2C) eeprom(and empty sockets for three more eeproms), and a 3 Volt, 12mm battery socket in order to maintain the receiver's built-in RTC (Real Time Clock).

    Shield layout
    .
    Shield and Amicus18 circuit.

    The GPS module returns several sentences of data, from the number of satellites "visible" to the time and date, and of course the position of the device. The "DEBUG" command uses the same USB connection to send data to the PC terminal as is used to program the Amicus18 if the boot-loader is used.

    Below is sample code to receive and display the raw data from the GPS shield.
    Code:
    ' PIC18F25K20 ON THE AMICUS BOARD WITH GPS SHIELD
    ' COLLECTS RAW NEMA DATA AND DISPLAYS ON TERMINAL     
    DEFINE OSC 64           'THE 16MHz IS PLLed TO 64 MHz    
    DEFINE LOADER_USED 1    'USING THE AMICUS USB BOOT-LOADER    
    DEFINE DEBUG_REG PORTC  'SET DEBUG PIN PORT   
    DEFINE DEBUG_BIT 6      'SET DEBUG PIN BIT    
    DEFINE DEBUG_BAUD 9600  'SET DEBUG BAUD RATE    
    DEFINE DEBUG_MODE 0     'SET DEBUG MODE: 0 = TRUE, 1 = INVERTED        
    TRISA.0 = 1             ' MAKES PORTA BIT 0 AN INPUT    
    ANSEL.0 = 0             ' MAKES PORTA BIT 0 DIGITAL    
    BAUD    CON 84          ' 9600 TRUE MODE    
    GPSRX   VAR PORTA.0     ' PIN TO RECEIVE DATA FROM GPS MODULE    
    GPS     VAR BYTE[100]   ' DATA FROM GPS         
    MAIN:    
    DO                      ' CREATES AN INFINATE LOOP        
        ' COLLECTS DATA AFTER THE "$" UNTIL THE ARRAY IS_        
        '  FULL OR A LINE FEED ($a) IS ENCOUNTERED        
          SERIN2 GPSRX, BAUD,[WAIT("$"),STR GPS\100\$a]       
          DEBUG  STR GPS\100  ' SENDS THE ARRAY TO THE TERMINAL    
    LOOP
    Raw NEMA data received from the GPS as displayed on the terminal using the above code..
    GPGGA,121234.255,3240.5006,N,11408.5203,W,1,08,01. 4,82.6,M,-31.9,M,,*62
    GPGGA,121235.255,3240.5006,N,11408.5203,W,1,08,01. 4,82.6,M,-31.9,M,,*63
    GPGGA,121236.255,3240.5006,N,11408.5203,W,1,09,01. 0,82.6,M,-31.9,M,,*65
    GPGSV,3,2,11,10,20,315,23,13,53,333,27,16,58,063,3 6,19,08,143,*73
    GPVTG,135.00,T,,,0.00,N,0.00,K,A*77
    The data as presented is not very useful other than for testing the unit. Each Sentence can be parsed for the information needed.

    GPGGA - Global Positioning System Fix Data
    GPGGA,121234.255,3240.5006,N,11408.5203,W,1,08,01. 4,82.6,M,-31.9,M,,*62

    GPGSV - GPS Satellites in view
    GPGSV,3,2,11,10,20,315,23,13,53,333,27,16,58,063,3 6,19,08,143,*73

    GPVTG - Track made good and ground speed
    GPVTG,135.00,T,,,0.00,N,0.00,K,A*77

    We will be using the $GPGGA sentence. The $GPGGA sentence contains the following information.

    $GPGGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x ,M,x.x,M,x.x,xxxx*hh
    1 = UTC of Position
    2 = Latitude
    3 = N or S
    4 = Longitude
    5 = E or W
    6 = GPS quality indicator (0=invalid; 1=GPS fix; 2=Diff. GPS fix)
    7 = Number of satellites in use [not those in view]
    8 = Horizontal dilution of position
    9 = Antenna altitude above/below mean sea level (geoid)
    10 = Meters (Antenna height unit)
    11 = Geoidal separation (Diff. between WGS-84 earth ellipsoid and mean sea level. -=geoid is below WGS-84 ellipsoid)
    12 = Meters (Units of geoidal separation)
    13 = Age in seconds since last update from diff. reference station
    14 = Diff. reference station ID#
    15 = Checksum

    Below is sample code to read and parse the $GPGGA sentence.
    Code:
    ' PIC18F25K20 ON THE AMICUS BOARD WITH GPS SHIELD
    ' COLLECTS AND PARSE RAW NEMA DATA AND DISPLAYS ' THE POSITION ON TERMINAL     
    DEFINE OSC 64           'THE 16MHz IS PLLed TO 64 MHz    
    DEFINE LOADER_USED 1    'USING THE AMICUS USB BOOT-LOADER    
    DEFINE DEBUG_REG PORTC  'SET DEBUG PIN PORT    
    DEFINE DEBUG_BIT 6      'SET DEBUG PIN BIT    
    DEFINE DEBUG_BAUD 9600  'SET DEBUG BAUD RATE    
    DEFINE DEBUG_MODE 0     'SET DEBUG MODE: 0 = TRUE, 1 = INVERTED        
    TRISA.0 = 1             ' MAKES PORTA BIT 0 AN INPUT    
    ANSEL.0 = 0             ' MAKES PORTA BIT 0 DIGITAL    
    BAUD    CON 84          ' 9600 TRUE MODE    
    GPSRX   VAR PORTA.0     ' PIN TO RECEIVE DATA FROM GPS MODULE    
    H       VAR BYTE        ' HOLDS THE HOUR    
    M       VAR BYTE        ' HOLDS THE MINUTES    
    S       VAR BYTE        ' HOLDS SECONDS    
    ND      VAR BYTE        ' HOLDS NORTH/SOUTH DEGREE    
    NM      VAR BYTE        ' HOLDS NORTH/SOUTH MINUTES   
    NMD     VAR WORD        ' HOLDS NORTH/SOUTH MINUTES DECIMAL    
    WD      VAR BYTE        ' HOLDS EAST/WEST DEGREE    
    WM      VAR BYTE        ' HOLDS EAST/WEST MINUTES    
    WMD     VAR WORD        ' HOLDS EAST/WEST MINUTES DECIMAL    
    NS      VAR BYTE        ' POSITION NORTH OR SOUTH    
    EW      VAR BYTE        ' POSITION EAST OR WEST    
    FIX     VAR BYTE        ' SIGNAL QUALITY    
    NSAT    VAR BYTE        ' NUMBER OF SATELLITES USED    
    ALT     VAR BYTE        ' ALTITUDE WHOLE NUMBER    
    ALO     VAR BYTE        ' ALTITUDE DECIMAL        
    
    MAIN:   ' READ AND PARSE THE GPGGA SENTENCE                             
        SERIN2 GPSRX, BAUD,[WAIT("$GPGGA,"),DEC2 H,DEC2 M,DEC2 S,_            
          WAIT(","),DEC2 ND,DEC2 NM,WAIT("."),DEC3 NMD,WAIT(","),NS,_            
          DEC3 WD,DEC2 WM,WAIT("."),DEC3 WMD,WAIT(","),EW,DEC FIX,_            
          DEC2 NSAT,WAIT(","),WAIT(","),DEC ALT,WAIT("."),DEC ALO]                    
    
        IF FIX = 0 THEN NO_FIX ' POOR SIGNAL? GOTO NO_FIX                     
    
        ' IF SIGNAL IS GOOD DISPLAY ON TERMINAL        
        DEBUG "TIME: ",DEC2 H,":",DEC2 M,":",DEC2 S," UTC",$a,_            
          "LATITUDE: ",DEC2 ND,$60," ",DEC2 NM,".",DEC2 NMD," ", NS, $a,_            
          "LONGITUDE: ",DEC3 WD,$60," ",DEC2 WM,".",DEC2 WMD," ", EW,$a,_            
          "GPS QUALITY(1 IS GOOD): ",DEC FIX,$a,_            
          "SATELLITES USED: ",DEC2 NSAT,$a,_            
          "ALTITUDE(METERS): ",DEC ALT,".",DEC ALO,$a,$a                
     GOTO MAIN        
    
    NO_FIX:  ' POOR SIGNAL TERMINAL DISPLAY        
        DEBUG "TIME: ",DEC2 H,":",DEC2 M,":",DEC2 S," UTC",$a,_            
          "LATITUDE: ","POOR COVERAGE", $a,_            
          "LONGITUDE: ","POOR COVERAGE",$a,_            
          "GPS QUALITY(1 IS GOOD): ",DEC FIX,$a,_            
          "SATELLITES USED: ",DEC2 NSAT,$a,_            
          "ALTITUDE(METERS): ","POOR COVERAGE",$a,$a          
    GOTO MAIN


    Screen shot of terminal going from poor coverage to having a fix.
    All of that from one sentence!

    For more information about NEMA sentences go here.