SUART.bas and NMEA.bas

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
gramo
Registered User
Registered User
Posts: 200
Joined: Tue Mar 20, 2007 6:55 am
Location: Australia
Contact:

SUART.bas and NMEA.bas

Post by gramo » Sun Sep 27, 2009 11:49 am

I've used the LS20031 GPS module for a few projects, and have recently stumbled onto an error that took some time to pin down.

When using the software uart module in the following program it works fine (note that the NMEA commands are commented out of the main program loop);

Code: Select all

// device and clock
Device = 18F2620
Clock = 10


// import modules...
Include "NMEA.bas"
Include "Usart.bas"
Include "SUART.bas"


' local variables
Dim NMEAItem As TNMEA
Dim Sentence As String


' program start
USART.SetBaudrate(br38400)

UART.SetTX(PORTB.0)
UART.SetMode(umTrue)
UART.SetBaudrate(sbr9600)

While True
    'If NMEA.GetItem(NMEAItem) And NMEAItem.Valid Then
        Sentence = "XXXXXXXXXXXXXXXXXXXXXXX"
        UART.Write("[Test]",Sentence,13,10)
    'endif    
Wend
And I get this output on the PICKIT 2 UART tool (the correct, 'expected' output);
Image

However, with this code the software uart will not function correctly (NMEA commands now included in the main program loop);

Code: Select all

// device and clock
Device = 18F2620
Clock = 10


// import modules...
Include "NMEA.bas"
Include "Usart.bas"
Include "SUART.bas"

' local variables
Dim NMEAItem As TNMEA
Dim Sentence As String


' program start
USART.SetBaudrate(br38400)

UART.SetTX(PORTB.0)
UART.SetMode(umTrue)
UART.SetBaudrate(sbr9600)

While True
    If NMEA.GetItem(NMEAItem) And NMEAItem.Valid Then
        Sentence = "XXXXXXXXXXXXXXXXXXXXXXX"
        UART.Write("[Test]",Sentence,13,10)
    endif    
Wend
The result (note that some of the data is missing every second line);
Image

I've stripped as much code as possible to simplify the bug, any assistance would be greatly appreciated!
digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples.

Australian distributor for the Swordfish Compiler

gramo
Registered User
Registered User
Posts: 200
Joined: Tue Mar 20, 2007 6:55 am
Location: Australia
Contact:

Post by gramo » Wed Oct 07, 2009 10:40 am

I suspect it was a timing clash with the NMEA interrupt and the software delays in the SUART.bas library. My PCB design ended up with a quick fix - a hardware switch to change the TX output from the PIC to either my PICKit 2 or GPS manually.

Edit: A thought after going through the NMEA.bas library - perhaps manually disabling the USART interrupt while performing other timing crucial tasks would be a solution. Untested though, and perhaps there is a better solution :wink:
digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples.

Australian distributor for the Swordfish Compiler

User avatar
ohararp
Posts: 194
Joined: Tue Oct 03, 2006 11:29 pm
Location: Dayton, OH USA
Contact:

Post by ohararp » Thu Oct 08, 2009 10:17 pm

gramo, this is interesting. I am looking at some 10 Hz gps modules and I am not sure my software routines are currently fast enough to handle these modules. I will be looking at using the NMEA.bas file here shortly and will report back to you on how things go.
Thanks Ryan
$25 SMT Stencils!!!
www.ohararp.com/Stencils.html

User avatar
RadioT
Registered User
Registered User
Posts: 157
Joined: Tue Nov 27, 2007 12:50 pm
Location: Winnipeg, Canada

Post by RadioT » Sat Oct 10, 2009 5:31 am

Is is not possible to use a hardware EUSART? Then you have a buffer. Is the EUSART in use all the time by another app? If not, maybe wire up an XOR circuit to route a couple of gates to the input to the EUSART depending on the functionality needed? Then you run the input much more independently and eliminate the operations spelled out in the software USART routines.

Ohararp, 10 hz sounds interesting but the bit rate must be like 56K +!

-Tom

Post Reply