Another odd GPS/queue problem

Started by Chris Odom June 6, 2007
I'm confused (again) and would love some help. I am still trying to
get my GPS application to give solid data. I've ripped the app down
to the most basic components (simply printing raw data from the input
queue to the screen) and can't make sense of it.

Below are two programs that _should_ do the same thing. The first
one (Print1.bas) works beautifully. The second program (Print2.bas)
is nearly identical to the first, but about of the output string is
garbled: will lose a comma here, a decimal there, and reverse some
numbers in the output. The only difference between the two is I use
a subprogram in the second app to grab the bytes from the queue.

Any ideas as to why one works and the other doesn't? I've been
cranking on this one for a while and it seems that the following code
should provide clues to the problem that I just can't see.

Here's the first program, which works just fine:

' Print1.bas
Option Explicit

Public Const GPSRxPin as Byte = 20
Public Const NullTXPin As Byte = 0
Public Const Baud As Long = 4800
Public Const InputQueueSize As Integer = 10
Public Const OutputQueueSize As Integer = 10
Public Com3In(1 To InputQueueSize) As Byte
Public Com3Out(1 To OutputQueueSize) As Byte

' ////////////////////////////////////////////
Public Sub Main()
Dim ByteOut as Byte

' initialize the GPS
Call OpenQueue(Com3In, InputQueueSize)
Call DefineCom3(GPSRxPin, NullTXPin, bx1000_1000)
Call OpenCom(3, Baud, Com3In, Com3Out)
Call Delay(2.0)

' The following code works great:
Do
Call GetQueue(Com3In, ByteOut, 1)
Debug.Print Chr(ByteOut) ;
Loop

End Sub
' ///////////////////////////////////////////

Here's a sample of the "good" output from the above code:
$GPRMC,104108.000,A,4012.8016,N,07456.1129,W,0.39,305.18,060607,,*1C
$GPRMC,104112.000,A,4012.8019,N,07456.1135,W,0.07,53.05,060607,,*24
$GPRMC,104116.000,A,4012.8019,N,07456.1135,W,0.35,298.89,060607,,*10
$GPRMC,104120.000,A,4012.8019,N,07456.1133,W,0.09,82.35,060607,,*22
$GPRMC,104124.000,A,4012.8018,N,07456.1132,W,0.17,316.68,060607,,*1F
$GPRMC,104128.000,A,4012.8016,N,07456.1125,W,0.08,340.21,060607,,*1B
Here's the second program, which works sporadically:

' Print2.bas
Option Explicit

Public Const GPSRxPin as Byte = 20
Public Const NullTXPin As Byte = 0
Public Const Baud As Long = 4800
Public Const InputQueueSize As Integer = 10
Public Const OutputQueueSize As Integer = 10
Public Com3In(1 To InputQueueSize) As Byte
Public Com3Out(1 To OutputQueueSize) As Byte

' ////////////////////////////////////////////
Public Sub Main()
' initialize the GPS
Call OpenQueue(Com3In, InputQueueSize)
Call DefineCom3(GPSRxPin, NullTXPin, bx1000_1000)
Call OpenCom(3, Baud, Com3In, Com3Out)
Call Delay(2.0)

' The following code works sporadically (data is garbled):
Do
Debug.Print Chr(GetByte) ;
Loop

End Sub
' ///////////////////////////////////////////

'////////////////////////////////////////////
Public Function GetByte() as Byte
' Read (and remove) the next byte from the input queue
Dim ByteOut as Byte

Call GetQueue(Com3In, ByteOut, 1)
GetByte = ByteOut

End Function
' ///////////////////////////////////////////

Here's a sample of the "bad" output from the above code:
$GPRMC,105004.000,A,012.8012,N,07456.157,W,0.32,134.43060607,,*18
$GPRMC,105008.000,A4012.7993,N,0745.1121,W,0.86,114.8,060607,,*1F
$GPRMC,105012.000,,4012.7977,N,074561061,W,0.80,125.87,60607,,*1F
$GPRMC,105016.000,A4012.7976,N,07456.141,W,0.38,98.78,00607,,*2C
$GPRMC,105020.000,A4012.7980,N,074561039,W,0.31,103.6,060607,,*18
$GPRMC,105024.000,,4012.7988,N,0746.1041,W,0.29,29.98,060607,,*1D
Thanks in advance for your help.

chris
Chris,

I think that your queue sizes are too small. At 4,800 baud, a
character is showing up in the queue roughly every 2.1 millsecs ((1 /
4800 baud) * 10 bits/char) and the jump to the subroutine and back
can take that long or longer. If you do any other processing the
problem will get even worse. Remember that the GPS msgs are showing up
once a second but the entire msg arrives in 147 millseconds (.0021 *
68 chars/msg). The remaining time is idle time as far as the Comm3 is
concerned. The queue has to be processed in 147 millisecs or the queue
will be overrun.

I did a project some years ago with a SiRF III GPS module and the
small ram of the BX24 couldn't handle the data stream. My project was
rescued by another BX24 type processor that has considerably faster
code execution stream AND much more ram.

Paul

--- In b..., "Chris Odom" wrote:
>
> I'm confused (again) and would love some help. I am still trying to
> get my GPS application to give solid data. I've ripped the app down
> to the most basic components (simply printing raw data from the input
> queue to the screen) and can't make sense of it.
>
> Below are two programs that _should_ do the same thing. The first
> one (Print1.bas) works beautifully. The second program (Print2.bas)
> is nearly identical to the first, but about of the output string is
> garbled: will lose a comma here, a decimal there, and reverse some
> numbers in the output. The only difference between the two is I use
> a subprogram in the second app to grab the bytes from the queue.
> Public Const InputQueueSize As Integer = 10
> Public Const OutputQueueSize As Integer = 10

Your queues are only one byte long, Chris. Add nine for a 10-byte queue.
Tom