BasicMicro - Forums

www.basicmicro.com
It is currently Sun May 20, 2012 10:49 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Atom to Lassen IQ GPS
PostPosted: Sun Sep 13, 2009 12:14 pm 
Offline
Master

Joined: Sun Oct 05, 2008 9:40 am
Posts: 111
The hardware is a Atom Lab board connected to a lassen IQ development board. The TX/RX lines of the GPS are connected to pins 10 and 11 of the Atom.

This code will qurey the gps for the version and display the results in the terminal window.

Code:
Version var byte(40)         'Set up array to store data


Main:

serout p11, i9600, [">QVR<"]         'Send command to gps to quiry version

serin p10, i9600, [str Version40]  'Read in and store responce in Version

serout S_OUT, i9600, [str Version40,13]   'Send version out hardware serial port

pause 500

goto Main

end


The next sample will qury for the ST sentence (Status). From this sentence the antenna connection is checked. Then battery backup, RTC and almanac are checked and the results displayed in the terminal window. The program enters the tracking routine where it will stay until enough satalites are in veiw to do position fixes.

Code:
GPS_status var byte(15)         'Set up array to store data


Main:

serout p11, i9600, [">QST<"]         'Send command to gps to quiry version

serin p10, i9600, [str GPS_status15]  'Read in and store responce in Version

serout S_OUT, i9600, [str GPS_status15,13]   'Send version out hardware serial port


Antenna_Fault:                           'Check for antenna fault
 
if GPS_status(6) = "0" then
   serout S_OUT, i9600, ["Antenna Good", 13]
   
  elseif GPS_status(6) = "2"
   serout S_OUT, i9600, ["Feedline Open Fault", 13]
   goto Main
   
  elseif  GPS_status(6) = "6"
   serout S_OUT, i9600, ["Feedline Short Fault", 13]
   goto Main
   
endif


if GPS_status(7) = "1" then                               'Check battery backup
   serout S_OUT, i9600, ["Battery Backup Failed", 13]
   
else
      serout S_OUT, i9600, ["No Problems", 13]
     
endif 



if GPS_status(11) = "0" then                              'Check RTC and Almanac
   serout S_OUT, i9600, ["No Problems", 13]
   
  elseif GPS_status(11) = "2"
   serout S_OUT, i9600, ["RTC not available", 13]
 
  elseif  GPS_status(11) = "8"
   serout S_OUT, i9600, ["Almanac not complete", 13]
 
  elseif  GPS_status(11) = "A"
   serout S_OUT, i9600, ["No RTC or Almanac", 13]
   
endif


Tracking:                                    'Routine to monitor GPS until lock

if GPS_status(5) = "0" then
   serout S_OUT, i9600, ["Doing Position Fixes", 13]   'If doing fixes jump to GPS_Lock
   goto GPS_Lock                                 'If no lock read in ST sentence
     
  elseif GPS_status(5) = "1"
   serout S_OUT, i9600, ["No GPS Time Yet", 13]
   
  elseif  GPS_status(5) = "3"
   serout S_OUT, i9600, ["PDOP to High", 13]
 
  elseif  GPS_status(5) = "8"
   serout S_OUT, i9600, ["No Usable Satalites", 13]
   
  elseif  GPS_status(5) = "9"
   serout S_OUT, i9600, ["Only 1 Usable Satalite", 13]
   
  elseif  GPS_status(5) = "A"
   serout S_OUT, i9600, ["Only 2 Usable Satalites", 13]
   
  elseif  GPS_status(5) = "B"
   serout S_OUT, i9600, ["Only 3 Usable Satalites", 13]
   
  elseif  GPS_status(5) = "C"
   serout S_OUT, i9600, ["Chosen Satalite is Unusable", 13]

endif

serout p11, i9600, [">QST<"]         'Send command to gps to quiry version

serin p10, i9600, [str GPS_status15]  'Read in and store responce in Version

pause 500

goto Tracking                     'Repeat until lock


GPS_Lock:

  serout S_OUT, i9600, ["Start Logging LN Message", 13]
 
end


This example will query the gps for the LN message (Long Navigation) and the parase the information into usable information. The data is then displayed in the terminal window.

Code:
Long_Nav    var     byte(57)
char       var    byte
index        var     byte
feildwidth  var     byte
workval      var     long
GPS_Time     var     long
LatDeg     var     byte
LatMin       var    long
LongDeg     var     byte
LongMin     var     long
Altitude1     var     long
Altitude2     var     byte
HorSpeed     var     byte
VerSpeed     var    byte
Heading1    var     byte
Heading2     var    byte
SV        var     byte
LatNS      var      byte
LongEW      var      byte


serout p11, i9600, [">QLN<"]         'Send command to gps to quiry version

serin p10, i9600, [str Long_Nav53]  'Read in and store responce in Version

serout S_OUT, i9600, [str Long_Nav53,13]   'Send version out hardware serial port


Parase_GPS:                   'Parase Long_Nav Array

index = 4                'GPS Time   
feildwidth = 5
gosub String_to_Value
GPS_Time = workval

index = 13               'Latitude Degrees
feildwidth = 2
gosub String_to_Value
LatDeg = workval

index = 15               'Latitude Minutes
feildwidth = 7
gosub String_to_Value
LatMin = workval

index = 23                   'Longitude Degrees
feildwidth = 3
gosub String_to_Value
LongDeg = workval

index = 26                   'Longitude Minutes
feildwidth = 7
gosub String_to_Value
LongMin = workval

index = 34                   'Altitude Ft
feildwidth = 6
gosub String_to_Value
Altitude1 = workval

index = 40                   'Altitude FT
feildwidth = 2
gosub String_to_Value
Altitude2 = workval

index = 42                   'Horizontal Speed MPH
feildwidth = 3
gosub String_to_Value
HorSpeed = workval

index = 47               'Vertical Speed MPH
feildwidth = 3
gosub String_to_Value
VerSpeed = workval

index = 51                   'Heading1 degrees
feildwidth = 3
gosub String_to_Value
Heading1 = workval

index = 54               'Heading2 Degrees
feildwidth = 1
gosub String_to_Value
Heading2 = workval

index = 55                   'Satalites in veiw
feildwidth = 2
gosub String_to_Value
SV = workval

gosub Convert_Sign


'-----------------------Display Variables-----------------------------------

serout S_OUT, i9600, ["Time...", dec GPS_Time,  13]               
serout S_OUT, i9600, ["Latitude...", LatNS, dec LatDeg, ".", dec LatMin, 13]
serout S_OUT, i9600, ["Longitude...", LongEW, dec LongDeg, ".", dec LongMin, 13]
serout S_OUT, i9600, ["Altitude...", Long_Nav(33), dec Altitude1, ".", dec Altitude2, 13]
serout S_OUT, i9600, ["Horizontal Speed...", dec HorSpeed,  13]
serout S_OUT, i9600, ["Vertical Speed...", Long_Nav(46), dec VerSpeed, 13]
serout S_OUT, i9600, ["Heading...", dec Heading1, ".", dec Heading2, 13]
serout S_OUT, i9600, ["Satalites used...", dec SV, 13] 
 
pause 1000

end

String_to_Value:         'Routine to convert array
   
workval = 0           'Set workval to 0

if feildwidth = 0 or feildwidth > 7 then String_to_Value_Done    'Exit if 0 or bigger than max feild length of 7

Get_Feild_Digit:

char = Long_Nav(index)             'Read in charicter from array
workval = workval + (char - "0")      'Convert from ASCII to decimal and add to previous, "  Ver...", dec VerSpeed
feildwidth = feildwidth - 1            ' Decrement feildwidth

if feildwidth = 0 then String_to_Value_Done   'If no more charicters in feild then exit
 
workval = workval * 10            'If more feilds exist Shift data left
index = index + 1                  'Increment index to next array location
goto Get_Feild_Digit            'Get next Charicter

String_to_Value_Done:            'Done converting return
  return

Convert_Sign:                  'Convert sign (+ -) to direction

LatNS = "N"                             'Assume North
if Long_Nav(12) = "+" then Convert_Long_Sign     'Confirm if match convert next sign
  LatNS = "S"                             'If no match Change to South   
 
Convert_Long_Sign:

LongEW = "E"                              'Assume East
if Long_Nav(22) = "+" then Convert_Done            'Confirm if match convert next sign
  LongEW = "W"                              'If no match Change to West


Convert_Done:                                       'Sign conversion done return
   
return   


Top
 Profile  
 
 Post subject: Re: Atom to Lassen IQ GPS
PostPosted: Sun Sep 13, 2009 12:30 pm 
Offline
Master

Joined: Sun Oct 05, 2008 9:40 am
Posts: 111
This example combines all the above. This program will check the antenna for fault. The checks battery backup, RTC and almanac. The results are displayed on the LCD of the Lab board.

Next tracking status is monitered until enough fixes are avalable. Again the number of satalites in veiw is displayed on the LCD.

The Atom is now ready to read in the Long Navigation message and parase the data. Once the data is parased it is displayed to the LCD. The fist slide contains Lat and Long. The second slide has altitude, horizontal speed and vertical speed. The last slide contains the heading and satalites in veiw.

Code:
Long_Nav    var     byte(57)
GPS_status    var    byte(15)       
char       var    byte
index        var     byte
feildwidth  var     byte
workval      var     long
GPS_Time     var     long
LatDeg     var     byte
LatMin       var    long
LongDeg     var    byte
LongMin     var     long
Altitude1     var     long
Altitude2     var     byte
HorSpeed     var     byte
VerSpeed     var    byte
Heading1    var     byte
Heading2     var    byte
SV        var     byte
LatNS      var      byte
LongEW      var      byte

Initilize_Hardware:

lcdinit P0P1P2, outb

Gps_Initilization:

serout p11, i9600, [">QST<"]         'Send command to gps to quiry version

serin p10, i9600, [str GPS_status15]  'Read in and store responce in Version

serout S_OUT, i9600, [str GPS_status15,13]   'Send version out hardware serial port

Antenna_Fault:
 
if GPS_status(6) = "0" then
 
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "Antenna Good"]
   
  elseif GPS_status(6) = "2"
 
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "Ant. Open Fault"]
   goto Gps_Initilization
   
  elseif  GPS_status(6) = "6"
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "Ant. Short Fault"]
   goto Gps_Initilization
   
endif

pause 1000


Check_Batt_Backup:

if GPS_status(7) = "1" then
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "Battery Failed"]
   
else
      lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "No Problems"]
     
endif 

pause 1000


Check_RTC_Almanac:

if GPS_status(11) = "0" then

   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "No Problems"]
   
  elseif GPS_status(11) = "2"
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "No RTC"]
   
  elseif  GPS_status(11) = "8"
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "No Almanac"]
   
  elseif  GPS_status(11) = "A"
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "No RTC & Almanac"]
   
endif

pause 1000



Tracking:

if GPS_status(5) = "0" then
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "Doing Fixes"]
   goto GPS_Lock
     
  elseif GPS_status(5) = "1"
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "No GPS Time"]
   
  elseif  GPS_status(5) = "3"
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "PDOP to High"]
   
  elseif  GPS_status(5) = "8"
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "No Satalites"]
   
  elseif  GPS_status(5) = "9"
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "1 Satalite"]
   
  elseif  GPS_status(5) = "A"
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "2 Satalites"]
   
  elseif  GPS_status(5) = "B"
   
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "3 Satalites"]
   
  elseif  GPS_status(5) = "C"
 
   lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "Unusable"]
   
endif

serout p11, i9600, [">QST<"]         'Send command to gps to quiry version

serin p10, i9600, [str GPS_status15]  'Read in and store responce in Version

pause 1000

goto Tracking


GPS_Lock:

  serout S_OUT, i9600, ["Start Logging LN Message", 13]
 
gosub Get_Long_Nav
gosub Parase_Gps
gosub Convert_Sign
gosub Lcd_Display

pause 2000

goto GPS_Lock

end

Get_Long_Nav:

serout p11, i9600, [">QLN<"]         'Send command to gps to quiry version

serin p10, i9600, [str Long_Nav57]  'Read in and store responce in Version

serout S_OUT, i9600, [str Long_Nav57,13]   'Send version out hardware serial port

return


Parase_GPS:                   

index = 4
feildwidth = 5
gosub String_to_Value
GPS_Time = workval

index = 13
feildwidth = 2
gosub String_to_Value
LatDeg = workval

index = 15
feildwidth = 7
gosub String_to_Value
LatMin = workval

index = 23
feildwidth = 3
gosub String_to_Value
LongDeg = workval

index = 26
feildwidth = 7
gosub String_to_Value
LongMin = workval

index = 34
feildwidth = 6
gosub String_to_Value
Altitude1 = workval

index = 40
feildwidth = 2
gosub String_to_Value
Altitude2 = workval

index = 42
feildwidth = 3
gosub String_to_Value
HorSpeed = workval

index = 47
feildwidth = 3
gosub String_to_Value
VerSpeed = workval

index = 51
feildwidth = 3
gosub String_to_Value
Heading1 = workval

index = 54
feildwidth = 1
gosub String_to_Value
Heading2 = workval

index = 55
feildwidth = 2
gosub String_to_Value
SV = workval

return



String_to_Value:
   
workval = 0

if feildwidth = 0 or feildwidth > 7 then String_to_Value_Done

Get_Feild_Digit:

char = Long_Nav(index)
workval = workval + (char - "0")
feildwidth = feildwidth - 1

if feildwidth = 0 then String_to_Value_Done
 
workval = workval * 10
index = index + 1
goto Get_Feild_Digit



String_to_Value_Done:

  return



Convert_Sign:

LatNS = "N"
if Long_Nav(12) = "+" then Convert_Long_Sign
  LatNS = "S"
 
Convert_Long_Sign:

LongEW = "E"
if Long_Nav(22) = "+" then Convert_Done
  LongEW = "W"



Convert_Done:
   
return   



Lcd_Display:

lcdinit P0P1P2, outb

lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "Lat.", LatNS, dec LatDeg, ".", dec LatMin]
lcdwrite P0P1P2, outb, [$180 | $40, "Lon.", LongEW, dec LongDeg, ".", dec LongMin]

Pause 2000

lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "Alt.", Long_Nav(33), dec Altitude1, ".", dec Altitude2]
lcdwrite P0P1P2, outb, [$180 | $40, "Hor.", dec HorSpeed, "  Ver.", Long_Nav(46), dec VerSpeed]

Pause 2000

lcdwrite P0P1P2, outb, [$133, $132, $128, $101, $102, $10C, "Heading...", dec Heading1, ".", dec Heading2]
lcdwrite P0P1P2, outb, [$180 | $40, "SV...", dec SV]

return


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO