GPS Project: PIC18F26K22 or PIC18F46K22


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    I believe that any input pin must be pulled either up or down depends on the use. If there is a switch normally most of the people, pull up a resistor at the input pin, and the switch goes to ground.

    Now for the rest of the pins personally if the pins are output and digital, i leave them floating, but i use the command:

    Code:
    PORTx = low
    Just read Ioannis previous post. It is really useful info. Thanks a lot.
    Last edited by astanapane; - 4th July 2018 at 07:33.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    PortX=0
    TrisX=xxxx

    Thats all.
    Ioannis

  3. #3
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Ok lets move forward to the project.

    I have received the PIC18F26K22, and connected the ulcd and the Gps module at the EUSARTs.

    I tried to configure each EUSART with a different baudrate but didnt work. Anyway i did the baudrate the same for both of the ports and uLCd and GPS worked fine.

    Code:
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 1 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|
    
            DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
            DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
            DEFINE HSER_CLROERR 1 ' Clear overflow automatically
            DEFINE HSER_SPBRG 160 ' 38400 Baud @ 64MHz, -0,08%
            SPBRGH = 1
            BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    
    
    
            
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 2 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|
    
            DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
            DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
            DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
            DEFINE HSER2_SPBRG 160 ' 38400 Baud @ 64MHz, -0,08%
            SPBRGH2 = 1
            BAUDCON2.3 = 1         ' Enable 16 bit baudrate generator
    
            
    '*-----------------------------------------------------------------------------|
    '*-----------------------------------------------------------------------------|

    Then on the main program, i have placed the code to get the information from the GPS and display them to uLcd.

    Some coding is still not good, but at the moment i need to solve the problem that is mentioned at the end of this message. So please ignore any minor issues at them moment.

    Code:
    '--------------------------------------------------------------------------------|
    '                                                                                |
    ' ----------------------------    [ MAIN ]   ----------------------------------- |
    '                                                                                |
    '--------------------------------------------------------------------------------|
    
    main:
    
    '-------------------------------------------------------------------------------/
    '                                                                              /
    '                    [ Example NMEA Sentense of GNRMC ]                       /
    ' [$GNRMC,090045.000,A,3823.6645,N,02353.3600,E,0.02,195.80,170518,,,A*62]   /
    '                                                                           /
    '--------------------------------------------------------------------------/
    ;serin2  gps_tx,84,timeout,lostcable,[wait("$GNRMC"),_          ;we wait for $GNRMC
    HSERIN timeout,lostcable,[wait("$GPRMC"),_           ;we wait for $GPRMC
    wait(","),dec2 hh,dec2 mm,dec2 ss,wait("."),dec3 sss,_          ;we wait for 090045.000 which is the time when we got the info
    wait(","),fix,_                                                 ;we wait for A
    wait(","),dec2 degrees,dec2 minutes,wait("."),dec4 minutesd,_   ;we wait for 3823.6645
    wait(","),dir,_                                                 ;we wait for N/S ;wait(","),dec3 degrees2,dec2 minutes2,wait("."),dec4 minutesd2,_;we wait for 02353.3600
    wait(","),dec3 degrees2,dec2 minutes2,wait("."),dec4 minutesd2,_;we wait for 02353.3600
    wait(","),dir2,_                                                ;we wait for E/W
    wait(","),wait(","),_                                               
    wait(","),dec2 day,dec2 month,dec2 year,_                       ;we wait for 170518
    wait(","),SKIP 3]                          
    
    '------------------------------------------------------------------------------/
    '                                                                             /
    '                     [ Example NMEA Sentense of GNGGA ]                     /
    ' [$GNGGA,140405.000,3823.6010,N,02353.3054,E,1,9,0.88,0.8,M,35.9,M,,*40    /           
    '                                                                          /
    '-------------------------------------------------------------------------/
    'serin2 gps_tx,84,timeout,lostcable,[wait("$GNGGA"),_            ;we wait for GNGGA
    HSERIN timeout,lostcable,[wait("$GPGGA"),_            ;we wait for GPGGA
    wait(","),skip 35,_
    wait(","),modefix,_                                             ;we wait for modefix 1,2 or 3 check gps manual for NMEA
    wait(","),dec2 satno,_
    wait(","),skip 19]
    
    
    '------------------------------------------------------------------------------/
    '                                                                             /
    '                     [ Example NMEA Sentense of GPGSA ]                     /
    '          [$GPGSA,A,3,18,08,10,11,14,27,22,32,01,,,,2.62,1.11,2.37*03]     /           
    '                                                                          /
    '-------------------------------------------------------------------------/
    
    HSERIN timeout,lostcable,[wait("$GPGSA"),_
    wait(","),wait(","),mode2d3d,_
    wait(","),SKIP 50]
    
    '------------------------------------------------------------------------------/
    '                                                                             /
    '                     [ Example NMEA Sentense of GPVTG ]                     /
    '                  [$GPVTG,215.60,T,,M,0.44,N,0.82,K,A*37]                  /           
    '                                                                          /
    '-------------------------------------------------------------------------/
    
    'serin2 gps_tx,84,timeout,lostcable,[wait("GNVTG"),_
    HSERIN timeout,lostcable,[wait("GPVTG"),wait("N"),_
    wait(","),TS[0],TS[1],TS[2],TS[3],TS[4],_
    wait(","),SKIP 3]
    
    for i = 1 to 3
        if TS[i]="." then decimal = i   'TOTAL SPEED. find which character is the decimal point 
        next i
    
    select case decimal 'if the gps shows 1.45 it may be 145
                        'for the conversion ASCII to number we can use the -48
        case    1       'decimal position is x.xx
            SPEED = (10*(TS[0]-48))+(TS[2]-48)
        case    2       'decimal position is xx.xx
            SPEED = (100*(TS[0]-48))+(10*(TS[1]-48))+(TS[3]-48)
        case    3       'decimal position is xxx.xx
            SPEED = (1000*(TS[0]-48))+(100*(TS[1]-48))+(10*(TS[2]-48))
        end select     
        
    gosub OVERSPEED:
    
    '---------------------------------------------------------------------------------/
    ' Here if the GPS module havent been fixed to any satellite will jump to notfix  /
    '-------------------------------------------------------------------------------/
    
    if fix = "V" then notfix                               
    ;pause 100
    
    '-----------------------------------------------------------------------------/
    '                           [ Return from notfix ]                           /
    '                   [ We clear any character on the display ]               /
    '--------------------------------------------------------------------------/
    
    'serout2 lcd,6,[$45]     'Clear the ulcd 1'44
    'pause 100
    
    '-----------------------------------------------------------------------------/
    '                   Here we start the calendar conversion                    /
    '---------------------------------------------------------------------------/
    
    arraywrite ndays,13,NDAY,[0,31,28,31,30,31,30,31,31,30,31,30,31]
    if ndays = 2 then
    if ((year//4 = 0) and (year//400 != 0)) then    'check the leap year
     ndays[2] = 29                                  'then February has 29 days
       else                                         
     ndays[2] = 28                                  'else has 28 days
     endif
        endif
     hh = hh + 3                                    'the Hour from GPS is UTC so for our country in Greece we add +3
     if hh>23 then                                  'if the hh+3 hour is greater than 23 (23:00) then
     day = day + 1                                  'we check the day added is true
     hh = hh//24                                    'but the hour not exceed the 24 so go to 00:00
        if (day > ndays[month]) then
     month = month + 1
     day = 1 
            if (month > 12) then
     year = year + 1
     month = 1
            endif
         endif
     endif
    
    '--------------------------------------------------------------------------/
    ' here is where the code dispays the stored info from the NMEA sentenses  /
    '------------------------------------------------------------------------/
             
                    
    HSEROUT2 [$73,$03,$00,$00,$FF,$FF," Protocol:","NMEA",$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$01,$02,$01,$07,$E0," Date:",dec2 day,"/",dec2 month,"/",dec2 year,$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$00,$04,$00,$FF,$E0,"   TIME: ",dec2 hh," :",dec2 mm," :",dec2 ss,$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$00,$07,$00,$FF,$FF," Sats",$00] 
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$01,$09,$11,$6D,$BF,dec2 satno,$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$0E,$07,$00,$FF,$FF,"  Fixed",$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$0B,$09,$11,$6D,$BF,"   ",fix,"  ",mode2d3d,"D",$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$05,$06,$11,$FF,$E0," SPEED",$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$06,$05,$12,$6D,$BF,TS[0],TS[1],TS[2],TS[3],$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$06,$06,$12,$FF,$E0,"Km/h",$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$00,$0C,$00,$ff,$ff," Lat : ",dec2 degrees,"*",dec2 minutes,"'",dec4 minutesd,"@"," ",$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$BE,$0C,$10,$f8,$00,dir,$00]
    Hserin2  timeout,lostcable,[wait(6)]                
    HSEROUT2 [$73,$00,$0E,$00,$ff,$ff," Lon :",dec3 degrees2,"*",dec2 minutes2,"'",dec4 minutesd2,"@"," ",$00]
    Hserin2  timeout,lostcable,[wait(6)]                
    HSEROUT2 [$73,$BE,$0E,$10,$f8,$00,dir2,$00]
    Hserin2  timeout,lostcable,[wait(6)]
    
            goto main
    As you see in the main code there is a line that checking if there is no FIX, so will jump to a label notfix:

    Code:
    '---------------------------------------------------------------------------------/
    ' Here if the GPS module havent been fixed to any satellite will jump to notfix  /
    '-------------------------------------------------------------------------------/
    
    if fix = "V" then notfix
    See next the notfix label:

    As i do not use any interrupt at the moment, any instruction is waiting to be completed until the next one will continue.

    So at this code, when i POWERUP the circuit, until the GPS gets the signal, jumps at the notfix.

    Code:
    notfix:     ' Still looking for fixed signal
    
    hh = hh + 3
    hh = hh//24 
    HSEROUT2 [$73,$00,$03,$11,$6D,$BF,"   Waiting for GPS",$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$00,$07,$00,$07,$ff,rep "." \dots,$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$07,$09,$10,$6D,$BF,"SATs :",dec2 satno,$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$04,$07,$12,$F8,$00,"NOT FIXED",$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$06,$0D,$11,$6D,$BF,fix,"   ",mode2d3d,"D",$00]
    Hserin2  timeout,lostcable,[wait(6)]
    HSEROUT2 [$73,$03,$06,$10,$ff,$E0," Time:",dec2 hh," :",dec2 mm," :",dec2 ss,$00]
    Hserin2  timeout,lostcable,[wait(6)]
    pause 3000
    
    HSEROUT2 [$45]  ' clears the LCD 
    Hserin2  timeout,lostcable,[wait(6)]
    
    
    goto main       'returns to main
    QUESTION:
    Now, i need to clear at the end of the notfix the display, because if there is a FIX from the GPS, will go back to main, and i need to see the new data and not a mixed from notfix and main. Is there any way to clear the LCD before i go back to main without place the clear lcd command inside the main or the notfix label? ? Could you please help me and give me some advice?



    Still i havent design any circuit as i develop the test board some things are changing.

    I post pictures of the test board, and i would try to explain what i have done.
    Attached Images Attached Images   
    Last edited by astanapane; - 4th July 2018 at 10:49.

  4. #4
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    A Test with an not very good ATTEN oscilloscope.

    main:
    high LED
    pause 10
    low LED
    pause 100
    goto main

    With an Auto-trigger i get 9.11 Hz

    If i make the following change

    main:
    high LED
    pause 10
    low LED
    pause 50
    goto main

    i get a frequency of: 16.72 Hz.

    As far as i have discussed with Ioannis, it should be ok, and the setting for 64Mhz is activated up and running.
    Attached Images Attached Images  

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Obviously your picture shows the first piece of code. You Oscilloscope is set for 50ms/div, so your period seems to measure about 110ms.

    Your program is making high for 10ms and another 100ms low which makes for a 110ms plus any PIC delays and inaccuracies, very much close to 120ms.

    Good to go!

    Ioannis

  6. #6
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Dear all,

    i have a question it maybe answered in lots of different threads.
    http://www.picbasic.co.uk/forum/showthread.php?t=10389

    http://www.picbasic.co.uk/forum/showthread.php?t=10265

    QUESTION: Can i have different baudrates on the 2 EUARTs? How could i change baudrate during start up in one of the EUART port?

    Have in mind that i use both of the EUARTs. One for the Display and one for the GPS.

    The GPS has a firmware with the following configuration:

    Baudrate: 9600 default
    Refresh rate: 1hz

    On the code i have configured the EUART for 38400, because i set the GPS externally with serial terminal at 38400. But GPS keeps the configs only if a backup battery is presented.

    So i came up with this problem.

    I need to send the following command first to SET the BAURATE at 38400, but with the EUART at 9600, because at that stage the GPS communicate only at 9600.

    Code:
    HSEROUT2 ["$PMTK251,38400*27",13,10]      ' 38400 boundrate, check MTK manual configuration.
    Then GPS as i tested i connected successfully, at 38400, but the following command cannot be sent before i change on the fly the EUART at 38400.

    Code:
    HSEROUT2 ["$PMTK220,100*2F",13,10]        ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
    From the links above, i checked the way you are setting the new baudrate, and tried to do it as well but didnt really worked.

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Yes, you can have different baudrate(s) on different UARTs and yes you can change it at any time you want. But, as the posts in the other thread says, to change it you can't use PBPs DEFINE HSER_BAUD because that's a compile time directive and not a runtime command.

    If you want to set or change the baudrate at runtime you need to set or change the registers manually. BAUDCON, SPBRG, SPBRGH most of the time. And remember that the register names are different for the second UART - BAUDCON2, SPBRG2 etc.

    Without seeing your code we can't say why what you did didn't work.

Similar Threads

  1. PIC18F46K22 config issue
    By LGabrielson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th September 2012, 03:20
  2. Replies: 1
    Last Post: - 27th July 2008, 06:14
  3. Pic GPS project Demo
    By Art in forum GPS
    Replies: 0
    Last Post: - 28th October 2007, 03:05
  4. GPS project question
    By mjp130 in forum GPS
    Replies: 6
    Last Post: - 4th July 2007, 20:09
  5. gps project
    By chuckad in forum GPS
    Replies: 2
    Last Post: - 9th February 2007, 02:52

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