GPS decoding problems


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Jul 2006
    Location
    Surrey, BC, Canada
    Posts
    31

    Unhappy GPS decoding problems

    Hello everybody. Does anyone have experience with GPS data string decoding? I surfed Internet for a while and found that most successful it can be do by Basic Stamp BS2p. This microcontroller employs scratchpad RAM for collect serial input. Once the string is in the scratchpad, it can be parsed and converted as required. My question- is it possible to avoid using scratchpad memory for handling GPS data? If it isn’t possible which PICs have scratchpad memory? So, anyone who has idea how to handle this problem please let me know.
    Thank you in advance
    Vladimir
    Last edited by vladimir059@hot; - 28th December 2006 at 04:19.

  2. #2
    Join Date
    Mar 2003
    Posts
    41


    Did you find this post helpful? Yes | No

    Default GPS parsing

    I use a PIC 16F877 to decode. I use an array of 85 characters to collect the input data string then set about unpacking the string based on counting the commas.


    GetData:
    ProcessRMC:
    serin2 rx232, 188, 2000, nogps,[WAIT("$GPRMC")] ' find start
    for i = 0 to 84 ' plenty of length - can be cut back
    serin2 rx232, 188, [a[i]]
    next i

    FindTrackField:
    commacount = 0
    ' lcdout $FE, $01
    for i = 0 to 84
    e = a[i]
    if e = "," then commacount = commacount + 1
    if commacount = 8 then gettrack 'Track follows 8th comma
    '10 gives MagVar - 8 gives Track
    next i

    HTH
    Brian

  3. #3
    Join Date
    Jul 2006
    Location
    Surrey, BC, Canada
    Posts
    31


    Did you find this post helpful? Yes | No

    Talking

    Thank you Brian!
    I will try your code today.
    Thanks again.
    Vladimir

  4. #4
    Join Date
    Jul 2006
    Location
    Surrey, BC, Canada
    Posts
    31


    Did you find this post helpful? Yes | No

    Default

    Brian Please Help!
    Please post all code for “Find Field Track Routine”

    I already tested your code and it successfully finding “GPRMC” string and storing data in 65 elements array (memory of PIC16F872 doesn’t allow to create bigger array).
    But still cannot figure out how to find right field and extract numeric data from the string.

    This is a sample of string I have:

    $G,092713.867,A,4913.0722,N,12256.9039,W,1.16,73.6 5,291206,,*20
    $G,092714.867,A,4913.0712,N,12256.9078,W,0.81,78.5 6,291206,,*25 and so on

    Maybe I made mistake in my code?

    '---------------- Definitions---------------------------------------------
    define OSC 20
    '------------- Define LCD registers and bits------------------------------
    Define LCD_DREG PORTB 'Set LCD data port
    Define LCD_DBIT 0 'Set starting data bit
    Define LCD_RSREG PORTB 'Set LCD register select port
    Define LCD_RSBIT 4 'Set LCD register select bit
    Define LCD_EREG PORTB 'Set LCD enable port
    Define LCD_EBIT 5 'Set LCD enable bit
    '------------- Define DEBUG registers and bits----------------------------
    define DEBUG_REG PORTC 'Set DEBUD port
    DEFINE DEBUG_BIT 3 'Set DEBUG pin
    DEFINE DEBUG_BAUD 4800 'Set DEBUG baud rate
    DEFINE DEBUG_MODE 0 'Set DEBUG mode

    '------------Allocate Variables for GPS-----------------------------------
    TimeOut CON 3000 'Time out delay
    baudGPS CON 16572 '16572 - 4800 baud inverted
    ParseCycle var byte ' Parse counter
    commacount var byte 'Commas counter
    e var byte
    GPSdata var byte[65] ' Data array
    TEMPdata var byte ' Temp debug data

    '--------------------- Pins definitions-----------------------------------
    GPSin VAR PORTc.7 'pin
    '-----------------------Program routine-----------------------------------


    GetData:

    serin2 gpsin,baudgps, timeout, nogps,[WAIT("$GPRMC")] ' find start of string
    for ParseCycle = 0 to 64
    serin2 gpsin, baudgps, [GPSdata[ParseCycle]]
    next ParseCycle

    'for parsecycle = 0 to 64 'test routine
    'TEMPdata = gpsdata[parsecycle] 'test routine
    'Debug TEMPdata 'test routine


    FindTrackField:
    commacount = 0
    for ParseCycle = 0 to 64
    e = GPSdata[ParseCycle]
    if e = "," then commacount = commacount + 1
    if commacount = 8 then gosub gettrack 'Track follows 8th comma

    debug e
    'debug " Gps data value ", gpsdata '10 gives MagVar - 8 gives Track

    next ParseCycle


    goto getdata

    Nogps:
    LCDOut $FE, 1 'Clear Screen
    LCDOut "No GPS"
    low portc.0
    Pause 2300
    high portc.0 'error LED flashes
    pause 2300
    low portc.0
    goto getdata


    gettrack:
    lcdout $FE, $01
    lcdout $fe, 1, "Time" 'not finished line
    lcdout $fe, $c0, "Speed " 'not finished line
    return

    Brian, please push me forward one more time.
    Vladimir
    Last edited by vladimir059@hot; - 29th December 2006 at 17:04.

  5. #5
    Join Date
    Mar 2003
    Posts
    41


    Did you find this post helpful? Yes | No

    Default GPS $GPRMB parser and decoder

    Here is a routine that will extract all fields of the RMB sentence. You can modify it for other strings.

    Cheers
    Brian

    GetData:
    ' Add code here for GPRMC, etc

    GetRMBData: ' capture 84 character frame in real time
    serin2 rx232, 188, 2000, nogps,[WAIT("$GPRMB")] ' find header
    for i = 0 to 83 'grab data stream
    serin2 rx232, 188, [a[i]]
    next i
    ' now we have an 84 character array starting with the first comma after
    ' $GPRMB. $GPRMB is of variable length depending on field values.
    ' Processing is now done while the next GPS frames pass by. Need a bigger
    ' RAM to handle RMB & RMC on every GPS frame.

    UnpackRMB: ' unpack frame & show on SEROUT
    CommaCnt = 0
    for i = 0 to 83
    if a[i] = "," then
    CommaCnt = CommaCnt + 1 ' found a new field
    serout bootout, 2, [$0D, $0A, #CommaCnt , ","]
    if CommaCnt = 1 then getvalidity
    if CommaCnt = 2 then getxte
    if CommaCnt = 3 then getsteer
    if CommaCnt = 4 then getorigin
    if CommaCnt = 5 then getdestination
    ' if CommaCnt = 6 then getdestnlatt
    ' if CommaCnt = 7 then gethemisphere
    ' if CommaCnt = 8 then getdestlong
    ' if CommaCnt = 9 then geteorw
    ' if CommaCnt = 10 then getrangetogo
    if CommaCnt = 11 then getbearing
    ' if CommaCnt = 12 then getclosingvelocity
    if CommaCnt = 13 then getarrival
    if CommaCnt = 14 then getdata 'all done so get next RMC
    GetFieldData:
    for j = i+1 to (i+15) 'get the next character
    if a[j] = "," then
    goto getnextfield
    endif
    serout bootout, 2, [a[j]]
    next j
    endif
    GetNextField:
    next i

    goto getdata

    GetValidity:
    ' This is needed since both Track and Bearing collapses to 0.0 when no
    ' GPS data is being received. This could be falsely interpreted as
    ' traveling due North with the destination dead ahead.
    ' A FailSafe check must be done here to prevent this. Currently omitted.
    if a[i+1] = "V" then
    serout bootout, 2, ["V = bad frame"]
    goto GetNextField
    endif
    if a[i+1] = "A" then
    serout bootout, 2, [ "A = good frame"]
    goto GetNextField
    endif
    serout bootout, 2, [ "NO sync"]
    goto GetNextField

    GetXTE:
    xte = 0
    for j = (i+1) to (i+8) ' get (up to) the next 8 characters
    if a[j]="," then xtedone ' end of field or blank field found
    if a[j]<>"." then ' ignore any decimal point
    e = a[j] - 48
    'ASCII representation - subtract 48 to get numeric value
    xte = 10* xte + e
    endif
    next j
    XTEDone:
    ' at this point we have XTE * 10
    serout bootout, 2, ["XTE = ", #xte/10, ".", #xte//10]
    goto GetNextField

    GetSteer:
    if a[i+1] = "L" then
    serout bootout, 2, ["Turn LEFT"]
    goto GetNextField
    endif
    if a[i+1] = "R" then
    serout bootout, 2, [ "Turn RIGHT"]
    goto GetNextField
    endif
    serout bootout, 2, [ "NO turn info"]
    goto GetNextField

    GetOrigin:
    'This is an alphanumeric field - needs unpacking
    serout bootout, 2, ["Origin = "]
    for j = (i+1) to (i+15) ' get (up to) the next 15 characters
    if a[j]="," then origindone ' end of field or blank field found
    serout bootout, 2, [ a[j]]
    next j
    OriginDone:
    goto GetNextField

    GetDestination:
    'This is an alphanumeric field - needs unpacking
    serout bootout, 2, ["Destination = "]
    for j = (i+1) to (i+15) ' get (up to) the next 15 characters
    if a[j]="," then destinationdone ' end of field or blank field found
    serout bootout, 2, [ a[j]]
    next j
    DestinationDone:
    goto GetNextField

    GetBearing:
    bearing = 0
    for j = (i+1) to (i+8) ' get (up to) the next 8 characters
    if a[j]="," then bearingdone ' end of field or blank field found
    if a[j]<>"." then ' ignore any decimal point
    e = a[j] - 48
    'ASCII representation - subtract 48 to get numeric value
    bearing = 10* bearing + e
    endif
    next j
    BearingDone:
    ' at this point we have BEARING * 10
    serout bootout, 2, ["Bearing = ", #bearing/10, ".", #bearing//10]
    lcdout $FE, $01, "Track ", #track/10, ".", #track//10
    lcdout $FE, $C0, "Bearing ",#bearing/10, ".", #bearing//10
    goto GetNextField

    GetArrival:
    if a[i+1] = "A" then
    serout bootout, 2, ["Arrived"]
    goto GetNextField
    endif
    if a[i+1] = "V" then
    serout bootout, 2, [ "not there yet"]
    goto GetNextField
    endif
    serout bootout, 2, [ "NO arrival info"]
    goto GetNextField

    NoGPS:
    lcdout $FE, $01, "No GPS data " , $FE, $C0, "Check GPS "
    pause 1000
    goto startup

  6. #6
    Join Date
    Apr 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    anybody can provide full description for this project ???

  7. #7
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default here's how I do it

    Here is how I decode the $gprmc sentence...

    Partial code below

    Code:
    GPRMC VAR BYTE[64]
    
    hh      VAR BYTE  'hours
    mm      VAR BYTE  'minutes
    ss      VAR BYTE  'seconds
    sss     var word  'milliseconds
    fix     VAR WORD  'GPS fix
    latdeg  VAR BYTE  'degrees latitude
    latmin  VAR BYTE  'minutes latitude  
    latminn var word  'fractional minutes latitude
    NS      VAR BYTE  'north or south
    londeg  VAR BYTE  'degrees longitude
    lonmin  VAR BYTE  'minutes longitude
    lonminn var word  'fractional minutes longitude
    EW      VAR BYTE  'east or west
    Knots   VAR byte  'speed in knots (units)
    Knotss  var byte  'speed in fractional knots
    course  var word  'heading
    dy      VAR BYTE  'day
    mt      VAR BYTE  'month
    yr      VAR BYTE  'year
    
    
    '============= Main Program ==========================================
    Main:
    high gpwr
    pause 3000
    
    GPSin:
        serin2 gps,188,3000,tmout,[WAIT("$GPRMC,"),STR GPRMC\63\"$"] 'Data IN from GPS
        
        arrayread gprmc,[DEC2 hh,DEC2 mm,dec2 ss,_
          wait(","),fix,wait(","),DEC2 latdeg,DEC2 latmin,wait("."),dec4 latminn,_
          wait(","),NS,wait(","),DEC3 londeg,DEC2 lonmin,wait("."),dec4 lonminn,_
          wait(","),EW,wait(","),dec knots,dec Knotss,dec course,_
          wait(","),DEC2 dy,DEC2 mt,DEC2 yr]      'parse the GPS array into parts
    
    if fix = "V" then gpsin  'jump to "waiting for fix" display
    
    low gpwr
    high xpwr
        pause 1000
        
        SEROUT2 xbtx,188,[$0D,$0A,"$GPRMC,",STR GPRMC\63]            'Data OUT to XBEE
        pause 500
    Hope this helps
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  8. #8
    Join Date
    Apr 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Thanx so much .. I really appreciate it
    Could you please provide me with GPS hardware connections with the pic ?

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What are you using for the GPS? A handheld unit or a module?
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Apr 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    What are you using for the GPS? A handheld unit or a module?
    I am using a module.

  11. #11
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The module data sheet should give the pin out. RX and TX.
    Dave
    Always wear safety glasses while programming.

  12. #12
    Join Date
    Apr 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    The module data sheet should give the pin out. RX and TX.
    Thanks, but to which pins of the pic16f877 should these pins be connected ??

  13. #13
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Well.... Back to the data sheet if you are planning to use the USART. Pins RC6 and 7.

    If you are going to use SERIN2 then just about any of the pins will work.
    Dave
    Always wear safety glasses while programming.

  14. #14
    piceighteen's Avatar
    piceighteen Guest


    Did you find this post helpful? Yes | No

    Default Re: GPS decoding problems

    Anyway does anyone have experience with GPS data string decoding for pic18LF4620?

  15. #15
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: GPS decoding problems

    Quote Originally Posted by piceighteen View Post
    Anyway does anyone have experience with GPS data string decoding for pic18LF4620?
    It would be the same as with any other MCU.
    Dave
    Always wear safety glasses while programming.

  16. #16
    Join Date
    Oct 2011
    Posts
    1


    Did you find this post helpful? Yes | No

    Default Re: GPS decoding problems

    can you post schematic of GPS receiver

  17. #17
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: GPS decoding problems

    Quote Originally Posted by nguyenphuocho View Post
    can you post schematic of GPS receiver
    Do you mean how the receiver is connected to a MCU?
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 10:47
  2. GPS clock timing !
    By bethr in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 3rd July 2008, 21:11
  3. Replies: 2
    Last Post: - 28th April 2006, 13:10
  4. GPS Receiver
    By lester in forum Adverts
    Replies: 2
    Last Post: - 22nd February 2006, 13:47
  5. GPS decoding
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th May 2005, 21:42

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts