20MHZ External Oscillator Settings


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Apr 2009
    Location
    Boise, Id
    Posts
    44

    Default 20MHZ External Oscillator Settings

    I'm using an 18F2550, and having trouble figuring out the oscillator settings. Everything worked fine with 4Mhz Crystal, not so much with 20Mhz. I don't even get the crystal to work when looking at it with a scope. Ideally I need AD values sampled about 300 times in 10ms. I could go to 200-300 samples in 20 ms or slower, but what I have is too slow. With the 4Mhz XTAL I was getting about 30 samples in 20ms.

    I'm using the bootloader, I programmed the PIC with the 20mhz.hex file using a programmer.
    Then I try loading my code and I'm not getting any where. The boat loader was all working with 4Mhz XTAL.


    I believe the issue is the CONFIG1H, or a multiplier that I'm not setting or uderstanding HS vs XT.

    Here is all the configuration etc. I'm sure they can be optimized past my understanding, so comment on anything that should be different/better. The ADCON settings are at the bottom, I'll also include my A to D code, I'm doing it the recommended way from other posts I found here for A to D (not using the ADCIN). I'm not having any issue with the code, just including it so you have a more complete picture of what I'm doing.
    Thanks,

    Shane

    Code:
    DEFINE LOADER_USED 1
    
    Define OSC 20
    
    'Define LCD Port
      DEFINE LCD_DREG          PORTB  'Port used for LCD Data
      DEFINE LCD_DBIT          4      'First Pin connected to LCD DB4
      DEFINE LCD_RSREG         PORTB 'Port used for LCD RS line
      DEFINE LCD_RSBIT         3     'Pin used for LCD RS line
      DEFINE LCD_EREG          PORTB 'Port used for LCD E Reg
      DEFINE LCD_EBIT          0     'Pin used for LCD E line
      DEFINE LCD_BITS          4     'Four bit comm mode
      DEFINE LCD_LINES         2     '2 Line LCD
      DEFINE LCD_COMMANDUS     750    'Delay between sending LCD commands
      DEFINE LCD_DATAUS        5      'Delay time between data sent
    
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
      DEFINE HSER_TXSTA 164 ' Enable brg, Enable transmit, BRGH = 1
      
      'DEFINE HSER_SPBRG 12  ' 19200 Baud @ 4MHz, 0.16%  pg 245 spbrg vals
      DEFINE HSER_SPBRG 64 ' 19200 Baud @ 20MHz, 0.16%  pg 245 spbrg vals
      DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    'Re-Configure default values from the PBP 18F2550.inc and MCSP/MPASM .inc
            'These are commented out in the .inc file
    
    '__CONFIG  _CONFIG1H ,_FOSC_XT_XT_1H    ' Works with 4Mhz 
        '_CONFIG1H ,_FOSC_XTPLL_XT_1H           '20Mhz?
             
        asm
              __CONFIG  _CONFIG1H ,_FOSC_XTPLL_XT_1H
              __CONFIG  _CONFIG2L ,_BOR_ON_2L & _BORV_2_2L
         
            
        endasm
    
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
        INCLUDE "ReEnterPBP-18.bas"     ; Include if using PBP interrupts
        INCLUDE "Elapsed_INT-18.bas"  ; Elapsed Timer Routines
       
        ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
                INT_Handler    TMR1_INT,  _ClockCount,   PBP,  yes
                INT_Handler    TMR0_INT,  _ToggleLED1,   PBP,  yes
                INT_Handler    RX_INT,     _Check_Command, PBP, yes  
            endm
            INT_CREATE               ; Creates the interrupt processor
        ENDASM
             
    @ INT_ENABLE    TMR1_INT     
    @ INT_ENABLE    TMR0_INT
    @ INT_ENABLE    RX_INT
    
    OSCCON  = %01101100
    
    ADCON0 = %00000000  'Setup
      ADCON1 = %00001010  'Port A0 Analog, rest to digital
                        
      ADCON2 = %10101000   'A/D Right Justified for 10 bit, 8 bit needs Left.
                          '12 Tad, Osc/2
      PortC = $00

    Code:
    '****************************CheckVoltage Sub*****************************
    CheckVoltage:
    MaxV1ADVal   = 0
    MaxV2ADVal   = 0
    MaxV3ADVal   = 0
    For V1i = 0 to 19
        Gosub GetV1   
        Gosub GetV2 
        Gosub GetV3 
        'Pauseus 25
    Next V1i
         
    GoSub CheckState
      
    Return
    '***************************Get V1****************************************
    GetV1:
       ADCON0 = %00000000 ' Select Channel AN0
       ADCON0.0 = 1       'Turn on A/D
       GoSub GetADVal
       V1ADVal.HighByte = ADRESH  'PLACES THE HIGH AND LOW BYTE
       V1ADVal.LowByte  = ADRESL   'INTO VAR CHAN0
       MaxV1ADVal= V1ADVAL Max MaxV1ADVal
    Return
    '***************************Get V2****************************************
    GetV2:
       ADCON0 = %00000100 ' Select Channel AN1
       ADCON0.0 = 1       'Turn on A/D
       GoSub GetADVal
       V2ADVal.HighByte = ADRESH  'PLACES THE HIGH AND LOW BYTE
       V2ADVal.LowByte  = ADRESL   'INTO VAR CHAN0
       MaxV2ADVal= V2ADVAL Max MaxV2ADVal
    Return
    '***************************Get V3****************************************
    GetV3:
       ADCON0 = %00001000 ' Select Channel AN2
       ADCON0.0 = 1       'Turn on A/D
       GoSub GetADVal
       V3ADVal.HighByte = ADRESH  'PLACES THE HIGH AND LOW BYTE
       V3ADVal.LowByte  = ADRESL   'INTO VAR CHAN0
       MaxV3ADVal= V3ADVAL Max MaxV3ADVal
    Return
    '***************************Get A/D Val*************************************
    GetADVal:
       ADCON0.1 = 1 'Start Conversion
       WHILE ADCON0.1=1   'Waite for it to Complete
       WEND
    RETURN

  2. #2
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156


    Did you find this post helpful? Yes | No

    Smile Re: 20MHZ External Oscillator Settings

    Well, I don't know about the PLL, but I expect we should get your crystal oscillating first. I am using a 20MHz crystal with a PIC18F6722 and it oscillates fine using:

    @ __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H

    try that, and see if at least the crystal wakes up.

  3. #3
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156


    Did you find this post helpful? Yes | No

    Default Re: 20MHZ External Oscillator Settings

    Forgot to mention... I assume you have 2 suitable size caps from the crystal leads to ground. Somewhere near 18-22 pF depending on the crystal.

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


    Did you find this post helpful? Yes | No

    Default Re: 20MHZ External Oscillator Settings

    Yes, get rid of the PLL.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: 20MHZ External Oscillator Settings

    If you are using the PLL then you should be using a 5Mhz XTAL to get 20Mhz. The PLL multiplies by 4, so that will get you 20.

    If you have a 20Mhz Xtal, set the oscillator for HS and turn the PLL off as macrakit says.
    Charles Linquist

  6. #6
    Join Date
    Apr 2009
    Location
    Boise, Id
    Posts
    44


    Did you find this post helpful? Yes | No

    Default Re: 20MHZ External Oscillator Settings

    Thanks for the advice, I do have a 20Mhz Xtal and 20pf caps for it, It's set up just like the 4Mhz, as far as the hardware side goes. Is the PLL only for the USB, or does it speed up the Pic's code execuition also? I keep reading myself in circles in the data sheet trying to figure that one out. Should the OSCCON settings be removed?
    I'll try the configuration from circuitpro's post.
    Thanks,

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