SLOW Serin2 and Serout2


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166

    Default SLOW Serin2 and Serout2

    so to start, my problem is that my program runs really slow. it is a basic circuit using an 18f6680 at 20MHz, a matrix orbital serial lcd and a Parallax GPS module.

    Im using an old board designed for a different project, so its not possible to use the hardware serial port at this time.

    the gps module needs the serout to tell it what data to send, and then it replies with the requested data. then once its returned to the PIC, it gets displayed on the serial LCD.

    the "timer" part of the circuit was just so i could tell how often it cycled through the program, and with the clock from the GPS, it takes approximately 5 seconds to run through one loop from Start to start. If i comment out everything except for one piece of data ( such as just getting the number of satallites and displaying it), it still takes close to 1 second for a loop.

    is there any way to optimize the code to make it a lot faster? Or do i need to use Hserin and change the gps to use NMEA data?

    thanks for the help

    <code>

    DEFINE OSC 20


    'VARIABLES

    lcd VAR PORTf.7
    gpsin VAR PORTb.3

    valid VAR byte
    sats var word
    hours var byte
    minutes var byte
    seconds var byte
    degreelat var byte
    minlat var byte
    seclat var word
    degreelong var byte
    minlong var byte
    seclong var word
    dirlat var byte
    dirlong var byte
    decdeglat var byte
    decdeglong var byte
    baudLCD CON 32
    baudgps con 188
    speed var byte

    degreelong = 0
    minlong = 0
    seclong = 0
    dirlong = 0
    degreelat = 0
    minlat = 0
    seclat = 0
    dirlat = 0
    speed = 0
    valid = 0
    sats = 0

    timer var byte
    timer = 0

    'STARTUP PROGRAM

    startup:

    Pause 800

    SerOut2 lcd, baudlcd,[254,"X"] 'clear screen
    Pause 200
    SerOut2 lcd, baudlcd,[254,"X"] 'clear screen again
    pause 200
    SerOut2 lcd, baudlcd,[254,"P",140] 'change Contrast
    pause 200
    SerOut2 lcd, baudlcd,[254,153,0] 'change lcd brightness to 0
    Pause 500


    SerOut2 lcd, baudlcd,[254,"G",1,1,"V="] 'display V= on screen
    serout2 lcd, baudlcd,[254,"G",1,2,"Sat="] 'display Sat= on screen
    serout2 lcd, baudlcd,[254,"G",12,2,"Speed="] 'display Speed= on screen

    'MAIN PROGRAM

    start:
    serout2 lcd,baudlcd,[254,"G",7,2,#timer]
    timer = timer + 1

    SerOut2 gpsin, baudgps,["!GPS", $01] 'checks for valid signal
    SerIn2 gpsin, baudgps,3000,no_response,[valid]
    SerOut2 lcd, baudlcd,[254,"G",3,1,#valid]

    SerOut2 gpsin, baudgps,["!GPS", $02] 'checks number of satellites
    SerIn2 gpsin, baudgps,3000,no_response,[sats]
    SerOut2 lcd, baudlcd,[254,"G",5,2,#sats]

    SerOut2 gpsin, baudgps,["!GPS", $03] 'gets time from satellite
    SerIn2 gpsin, baudgps,3000,no_response,[ hours, minutes , seconds]
    SerOut2 lcd, baudlcd,[254,"G",10,1, #hours, ":", #minutes, ":", #seconds]

    SerOut2 gpsin, baudgps,["!GPS", $05]
    SerIn2 gpsin, baudgps,3000,no_response,[degreelat,minlat,seclat,dirlat]
    decdeglat = (minlat * 1000 / 6 ) + (seclat / 60 )
    SerOut2 lcd, baudlcd,[254,"G",1,3,dec3 degreelat,".",dec4 decdeglat]

    SerOut2 gpsin, baudgps,["!GPS", $06]
    SerIn2 gpsin, baudgps,3000,no_response,[degreelong,minlong,seclong,dirlong]
    decdeglong = (minlong * 1000 / 6 ) + (seclong / 60)
    SerOut2 lcd, baudlcd,[254,"G",1,4,dec3 degreelong,".",dec4 decdeglong]

    SerOut2 gpsin, baudgps,["!GPS", $08]
    SerIn2 gpsin, baudgps,3000,no_response,[speed]
    serout2 lcd,baudlcd,[254,"G",18,2,#speed]


    GoTo start
    no_response:
    goto start

    end
    </code>

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    I hear DEBUG is supposed to be faster than any of the other software serial routines, although I do not know this as fact.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    I will lay odds it is the GPS that is slow.

    The Trimbles and Garmins I play with take around 2 seconds to do a loop through its data. I am not familiar with the module you have but it is probably the same as there are only a few GPS chips out there and add what ever Parallax did in front of it to receive command like ["!GPS", $05] is just going to slow the works down more.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    so, that old code used 3110 bytes and took about 5 seconds to run through.

    im still working on it, but i changed to using nmea data, which is something i have never been able to get working before, and its now down to 1204 bytes and cycles in 1 second!!! i think the problem was that the parallax module takes the nmea data, then rips it all apart, and only sends out what is requested. so i think going straight from the nmea to the PIC is probably a better way to do it anyways!

    so heres the new code:

    DEFINE OSC 20

    'VARIABLES

    lcd VAR PORTf.7
    gpsin VAR PORTb.3
    baudLCD CON 32 'baud rate for lcd
    baudgps con 188 'baud rate for gps 32


    valid VAR byte
    hours var byte(2)
    minutes var byte(2)
    seconds var byte(2)
    degreelat var byte(2)
    minlat var byte(2)
    seclat var byte(4)
    degreelong var byte(3)
    minlong var byte(2)
    seclong var byte(4)
    speed var byte(3)
    decspeed var byte


    course var byte(3)
    deccourse var byte
    decdeglat var byte
    decdeglong var byte


    degreelong = 0
    minlong = 0
    seclong = 0
    degreelat = 0
    minlat = 0
    seclat = 0
    speed = 0


    'STARTUP PROGRAM

    startup:

    SerOut2 lcd, baudlcd,[254,"X"] 'clear screen
    Pause 200
    SerOut2 lcd, baudlcd,[254,"X"] 'clear screen again

    'MAIN PROGRAM

    start:

    serin2 gpsin, baudgps,[WAIT ("$GPRMC"), SKIP 1, STR hours\2,str minutes\2, str seconds\2, SKIP 1, valid, skip 1, str degreelat\2,str minlat\2, SKIP 1, str seclat\4, SKIP 3, str degreelong\3, str minlong\2, SKIP 1, str seclong\4, SKIP 3, str speed\3, SKIP 1, decspeed, SKIP 1, str course\3, SKIP 1, deccourse]

    SerOut2 lcd, baudlcd,[254,"G",1,1, " TIME=", STR hours\2, ":", str minutes\2, ":", str seconds\2, " ", valid, 254,"G",1,2, str degreelat\2, str minlat\2,".", str seclat\4," ", str degreelong\3, str minlong\2,".", str seclong\4, 254,"G",1,3, str speed\3,".", decspeed," ", str course\3,".", deccourse]


    GoTo start
    end


    I will try changing to DEBUG sometime and see what happens, and im going to keep playing with this, but if anyone knows a better or more efficient way of doing this, let me know..

Similar Threads

  1. Serin2 pass through to Serout2
    By scottl in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th November 2007, 19:17
  2. Serin2 and serout2
    By abood in forum Forum Requests
    Replies: 1
    Last Post: - 15th August 2005, 13:20
  3. SEROUT2 and SERIN2 commands
    By bangunprayogi in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th August 2005, 09:03
  4. Simple PC Menu System with Serin2
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd April 2005, 08:27
  5. Serin2 and Serout2 with or without level converter
    By fbestepe in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st May 2004, 07:10

Members who have read this thread : 1

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