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

    Quote Originally Posted by Dave View Post
    Especially when in the presence of stray RF. They make rather nice antenna's.
    Ok then what is the most professional way in most of the cases to configure the pins?

    Should we make all the non used pins as an outputs - low stage?

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    its my understanding that pins left as inputs and tied or pulled down to vss will minimise current consumption.
    when i'm breadboarding a design I let them float and have never had an issue , if you accidently plug something
    into a input pin at least smoke is not released.
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Depends. If you care about minimum current as is the case in battery operated devices, then yes. Do set them as inputs with proper pull up enabled inside the PIC or a large size output.

    I found that makes no difference, at least for the chips I used, to set them as outputs logic low, and use no pull up or down. Pull up/down can also contribute to current consumption.

    I attach the page 2-4 of the Tips and Tricks, file DS01146B regarding I/O that has more info on this.

    Ioannis

    Name:  Capture.PNG
Views: 3575
Size:  146.1 KB

  4. #4
    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.

  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

    PortX=0
    TrisX=xxxx

    Thats all.
    Ioannis

  6. #6
    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.

  7. #7
    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  

  8. #8
    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

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