Shop OBEX P1 Docs P2 Docs Learn Events
PBASIC code GPS data problem? — Parallax Forums

PBASIC code GPS data problem?

JaundiceJaundice Posts: 11
edited 2007-06-27 02:56 in BASIC Stamp
Okay I have a sample of my code down below.· I have a problem that I CANNOT figure out for some reason this code isn't displaying any GPS data, well I mean I'm assuming that it's the codes fault because it goes through all the subroutines which tells me that its getting GPS data, but its just not displaying it properly.· Does anyone have any ideas.· Thank you in advance.· I've highlighted the area I think might be the problem in red, but I could be wrong.



#SELECT $STAMP
· #CASE BS2, BS2E, BS2PE
··· T1200······ CON···· 813
··· T2400······ CON···· 396
··· T4800······ CON···· 188
··· T9600······ CON···· 84
··· T19K2······ CON···· 32
··· TMidi······ CON···· 12
··· T38K4······ CON···· 6
· #CASE BS2SX, BS2P
··· T1200······ CON···· 2063
··· T2400······ CON···· 1021
··· T4800······ CON···· 500
··· T9600······ CON···· 240
··· T19K2······ CON···· 110
··· TMidi······ CON···· 60
··· T38K4······ CON···· 45
· #CASE BS2PX
··· T1200······ CON···· 3313
··· T2400······ CON···· 1646
··· T4800······ CON···· 813
··· T9600······ CON···· 396
··· T19K2······ CON···· 188
··· TMidi······ CON···· 108
··· T38K4······ CON···· 84
#ENDSELECT
'
[noparse][[/noparse] I/O Definitions ]
·Gps_Rxd··········· CON···· 6
Txd CON 15
'
[noparse][[/noparse] Constants ]
'

WRITE_EEPROM·· CON····· $02·············································· ' write data to memory
RDSR_EEPROM··· CON····· $05·············································· ' beginning at selected address
WREN_EEPROM··· CON····· $06·············································· ' read status register
CS·············· CON·· 2············································· ' chip select
Serdata········· CON·· 11'1·············································· ' serial data in/out
SerClk·········· CON·· 7'4··············································· ' EEPROM clock
WriteWord······ VAR··· Word
ByteData1······ VAR··· Byte
ByteData2······ VAR··· Byte

EEPROM_busy···· VAR··· ByteData1.LOWBIT································· ' first bit of the read status
address········ VAR··· Word············································· ' 25LCxxx memory address

SevenBit······· CON···· $2000
Inverted······· CON···· $4000
Open··········· CON···· $8000
Bd··········· CON···· T9600
Baud48········· CON T4800
'
[noparse][[/noparse] Variables ]
LAT1_DEG······ VAR Word
LAT1_MIN······ VAR Word
LAT1_FRACMIN·· VAR Word
LONG1_DEG····· VAR Word
LONG1_MIN····· VAR Word
LONG1_FRACMIN· VAR Word
ns············ VAR Byte
ew············ VAR Byte
Year·········· VAR Byte
Speed·········· VAR·· Byte
NumSats······· VAR Nib
day····· VAR······ Byte
month···· VAR····· Byte
'
[noparse][[/noparse] EEPROM Data ]
Scolon········· CON··· 58··············································· ' semicolon
MoveTo········· CON··· 2················································ ' for terminal screen control
DegSym········· CON··· 186·············································· ' degrees symbol for terminal
MinSym········· CON··· 39··············································· ' Minutes symbol for GPS
rxd CON 7
'
[noparse][[/noparse] Initialization ]
Reset:
GET 20, Word address
IF address > 0 THEN
· GOTO main
· ELSE

'
[noparse][[/noparse] Program Code ]
PAUSE 10 ' allow EEPROM write
address = address + 2
ENDIF

Main:
·GOSUB GetGpsData
·GOSUB Display_GPS
·PUT 1, Word LAT1_DEG
·PUT 2, Word LAT1_MIN
·PUT 3, Word LAT1_FRACMIN
·PUT 4, Word LONG1_DEG
·PUT 5, Word LONG1_MIN
·PUT 6, Word LONG1_FRACMIN
·GOSUB the_other
·PAUSE 500
·SEROUT txd,bd, [noparse][[/noparse]moveto,40,38,"password again in······ "]
·SEROUT txd,bd, [noparse][[/noparse]moveto,40,38,"password again in 3"]

·RUN 2
GOTO main
END

'
[noparse][[/noparse] Subroutines ]
GetGpsData:
SERIN· Gps_Rxd,Baud48, 5000, No_Data, [noparse][[/noparse]WAIT("GPGGA,"),SKIP 9,DEC2 LAT1_DEG,DEC2 LAT1_MIN ,··························
DEC LAT1_FRACMIN, SKIP 1, ns, DEC3 LONG1_DEG,DEC2 LONG1_MIN, DEC LONG1_FRACMIN,SKIP 1, ew, SKIP 2,DEC NumSats]···········
PAUSE 100
SERIN 6, Baud48, [noparse][[/noparse]WAIT("VTG,"), WAIT(","),··········································· ' Read the VTG sentence from GPS -
WAIT(","),WAIT(","),DEC Speed]·························································· ·' $GPVTG,x.x,T,x.x,M,x.x,N,x.x,K,i*hh<CR><LF>
PAUSE 100
writeword = speed
GOSUB writeworddata
SERIN 6, Baud48, [noparse][[/noparse]WAIT("GPZDA,"),SKIP 9,DEC Day, DEC Month,DEC Year]·· ' $GPZDA,hhmmss.ss,xx,xx,xxxx,,*hh<CR><LF>
RETURN

No_Data:
·SEROUT txd,bd, [noparse][[/noparse]moveto,0,28,"No data from GPS!" ,CR]
RETURN

Display_GPS:
SEROUT txd,bd, [noparse][[/noparse]moveto,0,29,DEC LAT1_deg DIG 1,DEC LAT1_deg DIG 0,DegSym, "· ",
DEC LAT1_min DIG 1,DEC LAT1_min DIG 0 ,".",DEC LAT1_fracmin DIG 3,· DEC LAT1_fracmin DIG 2, DEC LAT1_fracmin DIG 1,MinSym,CR]

SEROUT txd,bd, [noparse][[/noparse]moveto,0,30,DEC LONG1_deg DIG 2, DEC LONG1_deg DIG 1, DEC LONG1_deg DIG 0,DegSym, " ",
DEC LONG1_min DIG 1, DEC LONG1_min DIG 0,".",DEC LONG1_fracmin DIG 3,· DEC LONG1_fracmin DIG 2, DEC LONG1_fracmin DIG 1,MinSym,CR]' ,CR,CR]
RETURN


the_other:
SEROUT txd,bd, [noparse][[/noparse]moveto,40,9,DEC LAT1_deg DIG 1,DEC LAT1_deg DIG 0,DegSym, "· ",
DEC LAT1_min DIG 1,DEC LAT1_min DIG 0 ,".",DEC LAT1_fracmin DIG 3,· DEC LAT1_fracmin DIG 2, DEC LAT1_fracmin DIG 1,MinSym,CR]
SEROUT txd,bd, [noparse][[/noparse]moveto,40,10,DEC LONG1_deg DIG 2, DEC LONG1_deg DIG 1, DEC LONG1_deg DIG 0,DegSym, " ",
DEC LONG1_min DIG 1, DEC LONG1_min DIG 0,".",DEC LONG1_fracmin DIG 3,· DEC LONG1_fracmin DIG 2, DEC LONG1_fracmin DIG 1,MinSym,CR]' ,CR,CR]
SEROUT txd,bd, [noparse][[/noparse]moveto,40,7,"GMT Date is: ", DEC Month,"/",DEC Day,"/",DEC Year]
SEROUT TXD,BD, [noparse][[/noparse]moveto,40,12,"SOG is: ", DEC Speed, CR]
SEROUT TXD,BD, [noparse][[/noparse]moveto,40,13,"Satellites in use :· ", DEC NumSats, CR]
RETURN

WriteWordData:
· GOSUB EEPROMreadstatus·········································· ·' Check to see if the EEPROM is busy
· IF EEPROM_Busy =1 THEN WriteWordData······················ ' If its busy loop until its not
· LOW CS··································································· ·' Tell EEPROM a transmission is coming
· SHIFTOUT SerData,SerClk,MSBFIRST,[noparse][[/noparse]WREN_EEPROM]·······' Tell the EEPROM you want to
················································································ ' set the write enable latch
· HIGH CS··································································· ' Tell EEPROM its done transmitting
· LOW CS··································································· ·' Tell EEPROM a transmission is coming
················································································ ' Tell the EEPROM you want to write to it, send the 16bit address to write to,
·················································································' and send two bytes of data to write at that location
· SHIFTOUT SerData,SerClk,MSBFIRST,
· [noparse][[/noparse]Write_EEPROM,Address\16,WriteWord\16]
· HIGH CS···································································· ' tell EEPROM its done transmitting
· address = (address + 2)··············································· ' Increment address location by two
· PUT 20, Word address
RETURN

EEPROMreadstatus:
· LOW CS····································································· 'tell EEPROM a transmission is coming
··················································································'send the command to EEPROM that a device wants to read the status register
· SHIFTOUT SerData,SerClk,MSBFIRST,[noparse][[/noparse]RDSR_EEPROM]········ 'return the byte containing the status of the read register
· SHIFTIN SerData,SerClk,MSBPRE,[noparse][[/noparse]ByteData1\8]
· EEPROM_busy = Bytedata1
· HIGH CS····································································· 'tell EEPROM its done transmitting
RETURN

Comments

  • LarryLarry Posts: 212
    edited 2007-06-27 01:01
    I haven't gone over the program line by line, so I could be off base, but I see you are trying to capture formatted data of almost entire sentences.

    If you are trying to do it with a BS2, I think your program won't be able to capture all the data. During the course of capturing the data, you have a bunch of formating that you are doing to get that data in the format you want, and those extra statements take processor time. A stamp can't keep up. I've tried.

    The best way to capture GS data I've found is to write the incoming data to the scrattchpad on a BS2p or similar variant, then do the conversions later.
    Alternatively, read the data over two passes of the data, capturing different parts of the sentence each time.
    Or, read only the parts of the sentence you really need, skipping over the rest. Often times the data can be found in several of the sentences your GPS put out, and you can spread out where you collect the data.

    Hope that helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JaundiceJaundice Posts: 11
    edited 2007-06-27 01:35
    Thanks Larry
  • LarryLarry Posts: 212
    edited 2007-06-27 02:56
    I should have added a couple references.


    I f you have a BS2p, look here: www.parallax.com/dl/docs/article/rambal-gps.pdf for an article by Jon Williams with code for reading/writing the scratchpad ram.

    If you are trying to use the BS2, look here: www.parallax.com/dl/docs/article/GPSReadings.pdf for an artilce by Randy Price to show how to stay within the BS2 limits.

    One last thought. If you have a Garmin unit, there's a format it provides that's easier to read with a stamp, and faster(9600 baud, faster repeat) , since it is fixed format.
    Look here: www.parallaxinc.com/dl/docs/cols/nv/vol3/col/nv83.pdf and see if it gives you the information you want.

    If you keep your SERIN statement simple, you might even read most of the data you need with a BS2.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.