GPS Project: PIC18F26K22 or PIC18F46K22


Closed Thread
Results 1 to 40 of 69

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Is there any way to measure this with an Oscilloscope?
    measure the led on/off time with the Oscilloscope if the osc is correct then the on/off times will be as per your code


    I would leave CONFIG PWRTEN = ON


    AND ADD THIS
    OSCCON = %01110000 ; 64Mhz
    OSCTUNE.6 = 1 ; Enable 4x PLL
    while ! osccon2.7 :WEND

    to make sure the pll has stabilised before you run any other code , if timing is critical
    Warning I'm not a teacher

  2. #2
    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 richard View Post
    measure the led on/off time with the Oscilloscope if the osc is correct then the on/off times will be as per your code


    I would leave CONFIG PWRTEN = ON


    AND ADD THIS
    OSCCON = %01110000 ; 64Mhz
    OSCTUNE.6 = 1 ; Enable 4x PLL
    while ! osccon2.7 :WEND

    to make sure the pll has stabilised before you run any other code , if timing is critical
    Hi Richard,

    Thanks, i will do that. So that means that the 8th Bit of the OSCCON2 which is the .7 must be presented?
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    I seldom use crystals [you lose two pins for marginal increase in accuracy ] but I believe you can set pll mode in the config section and is all you need

    CONFIG PLLCFG = ON
    ;CONFIG PLLCFG = OFF // pll can only be engaged with software selection for int osc


    and then all this is not valid , it applies to internal osc only

    OSCCON = %01110000 ; 64Mhz
    OSCTUNE.6 = 1 ; Enable 4x PLL


    this may or may not be necessary with xtal osc , I have found bootloaders won't sync up unless this is done using int osc with pll.
    the PLLRDY bit is asserted when pll is stable [although I can find no mention in data sheet]
    while ! osccon2.7 :WEND
    Warning I'm not a teacher

  4. #4
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Hi Richard,

    i got confused. Really im reading the datasheet and there is nowhere clear setting for using external crystal.

    I came up with the following

    Code:
    OSCCON = %01110000 ; 64Mhz
    OSCTUNE.6 = 1 ; Enable 4x PLL
    Because i was thinking that in order to specify the OSCCON, and the multiplier PLL we need to add those lines even if it is for internal or external source. I didnt think that those where valid only for internal OSC.

    So what should i add as OSCCON value, as i use and external crystal 16Mhz? How do i specify the OSCCON value for 64Mhz?

    thanks once again. Apologize for all my questions.

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


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    So what should i add as OSCCON value, as i use and external crystal 16Mhz? How do i specify the OSCCON value for 64Mhz?
    nothing , leave it alone

    OSCTUNE.6 = 1 ; Enable 4x PLL becomes non functional if CONFIG PLLCFG = ON
    Warning I'm not a teacher

  6. #6
    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 richard View Post
    nothing , leave it alone

    OSCTUNE.6 = 1 ; Enable 4x PLL becomes non functional if CONFIG PLLCFG = ON
    Thanks i'll do so. Tonight i will post result in addition to some pictures from Oscilloscope. Lets see.

  7. #7
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    I did the following code test in order to check communication with an uLCD 144 and the LED as before at the same port.

    I would love to use the .inc files for the Nokia 3310 or 5110 LCD but really i dont know which files are the ones match.

    Anyway i think the code works as it is and the configuration settings are ok.

    Code:
    '*********************************************************************************
    @ ERRORLEVEL -306 ; this command prevents the compiler to give you a notice of   *
                      ; crossing page boundary - make sure bits are set              *
    '********************************************************************************* 
     
      #CONFIG   ;  The PBP configuration for the PIC18F26K22 is:
    ;    CONFIG FOSC     = RCIO6	    ; External RC oscillator
         CONFIG FOSC     = HSHP	        ; HS oscillator (high power > 16 MHz)
         
    
    ;*---------------------------------4x PLL ENABLE--------------------------------------*|
    ;*  4X PLL Enable                                                                     *|
    ;*    CONFIG PLLCFG  = OFF	        ;Oscillator used directly                         *|
        CONFIG PLLCFG    = ON	        ;Oscillator multiplied by 4                       *|
    ;*------------------------------------------------------------------------------------*|
    ;
    ;  Primary clock enable bit
    ;    CONFIG PRICLKEN = OFF	        ;Primary clock can be disabled by software
        CONFIG PRICLKEN  = ON	        ;Primary clock enabled
    ;
    ;  Fail-Safe Clock Monitor Enable bit
        CONFIG FCMEN     = OFF	        ;Fail-Safe Clock Monitor disabled
    ;    CONFIG FCMEN    = ON	        ;Fail-Safe Clock Monitor enabled
    ;
    ;  Internal/External Oscillator Switchover bit
        CONFIG IESO      = OFF	        ;Oscillator Switchover mode disabled
    ;    CONFIG IESO     = ON	        ;Oscillator Switchover mode enabled
        
        CONFIG  BOREN    = SBORDIS      ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
        
    ;*--------------------------------------------------------------------------------------------------------;|
        CONFIG  WDTEN    = ON           ; WDT is always enabled. SWDTEN bit has no effect                     ;|
        CONFIG  WDTPS    = 32768        ; 1:32768 ---> HERE enable the watchdog timer with a 1:32768 postscale;|
    ;*--------------------------------------------------------------------------------------------------------;|
        
        CONFIG  PWRTEN   = ON
        CONFIG  HFOFST   = ON           ; HFINTOSC output and ready status are not delayed by the oscillator stable status
        CONFIG  MCLRE    = EXTMCLR      ; MCLR pin enabled, RE3 input pin disabled
        CONFIG  LVP      = OFF          ; Single-Supply ICSP disabled
        CONFIG  XINST    = OFF          ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        CONFIG  DEBUG    = OFF          ; Disabled
    
    ;*----------------------------------------------------------------------------------|
    ;*---------------Available configuration settings for PIC18F26K22-------------------|
    ;*----------------------------------------------------------------------------------|
    ;
    ;  Oscillator Selection bits
    ;    CONFIG FOSC = RC	    ;111X External RC oscillator, CLKOUT function on RA6
    ;    CONFIG FOSC = ECLPIO6  ;EC oscillator (low power, <500 kHz)
    ;    CONFIG FOSC = ECLP	    ;EC oscillator, CLKOUT function on OSC2 (low power, <500 kHz)
    ;    CONFIG FOSC = ECMPIO6  ;EC oscillator (medium power, 500 kHz-16 MHz)
    ;    CONFIG FOSC = ECMP	    ;EC oscillator, CLKOUT function on OSC2 (medium power, 500 kHz-16 MHz)
    ;    CONFIG FOSC = INTIO7   ;Internal oscillator block, CLKOUT function on OSC2
    ;    CONFIG FOSC = INTIO67  ;Internal oscillator block
    ;    CONFIG FOSC = RCIO6    ;External RC oscillator
    ;    CONFIG FOSC = RC	    ;External RC oscillator, CLKOUT function on OSC2
    ;    CONFIG FOSC = ECHPIO6  ;EC oscillator (high power, >16 MHz)
    ;    CONFIG FOSC = ECHP	    ;EC oscillator, CLKOUT function on OSC2 (high power, >16 MHz)
    ;    CONFIG FOSC = HSMP	    ;HS oscillator (medium power 4-16 MHz)
    ;    CONFIG FOSC = HSHP	    ;HS oscillator (high power > 16 MHz)
    ;    CONFIG FOSC = XT	    ;XT oscillator
    ;    CONFIG FOSC = LP	    ;LP oscillator
        
    ;*--------------------------------------------------------------------------------------------------------|
    ;*                                  | -------------------------- |                                        |
    ;*  -----------------------------   |  [PROTECTED OPTION FUSES]  |  ------------------------------------  |
    ;*                                  | -------------------------- |                                        |
    ;*--------------------------------------------------------------------------------------------------------|
    
        CONFIG  CP0 = OFF             ; Block 0 (000800-003FFFh) not code-protected
        CONFIG  CP1 = OFF             ; Block 1 (004000-007FFFh) not code-protected
        CONFIG  CP2 = OFF             ; Block 2 (008000-00BFFFh) not code-protected
        CONFIG  CP3 = OFF             ; Block 3 (00C000-00FFFFh) not code-protected
        CONFIG  CPB = OFF             ; Boot block (000000-0007FFh) not code-protected
        CONFIG  CPD = OFF             ; Data EEPROM not code-protected
        CONFIG  WRT0 = OFF            ; Block 0 (000800-003FFFh) not write-protected
        CONFIG  WRT1 = OFF            ; Block 1 (004000-007FFFh) not write-protected
        CONFIG  WRT2 = OFF            ; Block 2 (008000-00BFFFh) not write-protected
        CONFIG  WRT3 = OFF            ; Block 3 (00C000-00FFFFh) not write-protected
        CONFIG  WRTC = OFF            ; Configuration registers (300000-3000FFh) not write-protected
        CONFIG  WRTB = OFF            ; Boot Block (000000-0007FFh) not write-protected
        CONFIG  WRTD = OFF            ; Data EEPROM not write-protected
        CONFIG  EBTR0 = OFF           ; Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR1 = OFF           ; Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR2 = OFF           ; Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR3 = OFF           ; Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTRB = OFF           ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    
      #ENDCONFIG
      
    ;*---------------------------------------------------------------------------------------------------------|
    ;*---------------------------------------------------------------------------------------------------------|
    
    define  OSC 64
    
            INCLUDE "modedefs.bas"
            INCLUDE"ALLDIGITAL.pbp"
    
    OSCCON    = %01110000   ; 64Mhz
    OSCTUNE.6 = 1           ; Enable 4x PLL
    
    while ! osccon2.7 :WEND ; to make sure the pll has stabilised before you run any other code
    
    TRISA = %00000000   'use TRISA to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    TRISB = %10000000   'use TRISB to specify which pin is (1 = input) and which (0 = output)  (RB7 PORTB.7 is the RX input pin of the EUART, the rest are output)
    TRISC = %10000000   'use TRISC to specify which pin is (1 = input) and which (0 = output)  (RC7 PORTC.7 is the RX input pin of the EUART, the rest are output)
                        'in PORTC the RC3 attached is an LED. 
    
    '           --------------- TRIS A-B-C ---------------
    '------------------------------------------------------------------------|
    ' PORTA.7  PORTA.6  PORTA.5  PORTA.4  PORTA.3  PORTA.2  PORTA.1  PORTA.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   0        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTB.7  PORTB.6  PORTB.5  PORTB.4  PORTB.3  PORTB.2  PORTB.1  PORTB.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   1        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTC.7  PORTC.6  PORTC.5  PORTC.4  PORTC.3  PORTC.2  PORTC.1  PORTC.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   1        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    
    PORTA = 0            'make low all ports at A range
    PORTB = 0            'make low all ports at B range
    PORTC = 0            'make low all ports at C range
    PORTE = 0            'make low all ports at E range 
    
           
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | 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
            
    '*-----------------------------------------------------------------------------|
    '*-----------------------------------------------------------------------------|
    
    Timeout         CON 1000
    Counter         var byte
    ser_in_data     var byte
    LED             var PORTC.3
    
    
    ' -------------------------------------------------------------------------/  
    '                          [ LCD Initialization ]                         /
    '------------------------------------------------------------------------/
              ' FIRST TIME BOOTUP: We give plenty of time for tbe LCD '
    pause 2000  
    HSEROUT2[$55]      ' uOLED Initialize this is the 'U' character of autoband rate to LCD
    Hserin2  timeout,main,[wait(6)]
    hserout2[$56,$01]  ' this is the Version info --> '01 10 17 28 28   -->> "(("
    Hserin2  timeout,main,[wait(1),wait(16),wait(23),wait(40),wait(40)]
    HSEROUT2 [$45]    ' clear the LCD
    Hserin2  timeout,main,[wait(6)]
    pause 500
    
    hserout2[$73,$00,$03,$11,$ff,$ff," Leonardo Bilalis",$00] 
    Hserin2  timeout,main,[wait(6)]           
    hserout2[$73,$02,$06,$10,$ff,"     Copyright 2018",$00]
    Hserin2  timeout,main,[wait(6)]
    pause 500
    
    Hserout2[$4F,01]
    Hserin2  timeout,main,[wait(6)]
    
    HSEROUT2 [$45]    ' clear the LCD
    Hserin2  timeout,main,[wait(6)]
    
    Start:
    for counter = 1 to 100
    HSEROUT2 [$73,$03,$02,$11,$ff,$ff,"Counter:", #counter,$00]
    pause 10
    next counter
    ;gosub main ---> i did commented this as from Ioannis's advice. 
    
    main:
    high LED
    pause 1000
    low LED
    pause 1000
    goto main
    Last edited by astanapane; - 2nd July 2018 at 21:00.

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