• AVR Freaks

Hot!How to configure the external crystal with PLL

Page: 12 > Showing page 1 of 2
Author
Nera
Super Member
  • Total Posts : 244
  • Reward points : 0
  • Joined: 2017/10/11 07:13:25
  • Location: 0
  • Status: offline
2020/11/24 05:28:15 (permalink)
0

How to configure the external crystal with PLL

Hi guys,
How can I configure an external 8 Mhz oscillator crystal and turn on the PLL to result in 32 Mhz?
What configuration bits should I change and what commands should I run?
The microcontroller I am using is the PIC18F4620.
 
Thanks.
post edited by Nera - 2020/11/24 05:38:32
#1

21 Replies Related Threads

    BroadwellConsultingInc
    Super Member
    • Total Posts : 97
    • Reward points : 0
    • Joined: 2020/06/09 06:07:55
    • Location: 0
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/24 07:03:27 (permalink)
    0
    I'd suggest creating a simple project in Microchip Code Configurator that does what you want.  It will also help you set up clocks for other peripherals you may want to use such as UART.  Even if it's an assembly project it will be easy to see the Config word and register values.
     
    An important thing to note about that family is that the crystal / PLL settings are read from the config bits at powerup, not reset.  So if you make changes to the config bits you need to power cycle the chip for them to take effect.  Just doing a reset with your PicKit or ICD won't do it.  It will look like your change didn't do anything.
    #2
    1and0
    Access is Denied
    • Total Posts : 11747
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/24 07:59:16 (permalink)
    0 (2)
    Neraildes
    How can I configure an external 8 Mhz oscillator crystal and turn on the PLL to result in 32 Mhz?
    What configuration bits should I change and what commands should I run?
    The microcontroller I am using is the PIC18F4620.

    Connect your crystal with two 22 pF to the PIC device, and use the HSPLL config bits setting.
     
    #3
    crosland
    Super Member
    • Total Posts : 2142
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: online
    Re: How to configure the external crystal with PLL 2020/11/24 10:28:54 (permalink)
    -2 (4)
    Have you tried RTFM?
    #4
    upand_at_them
    Super Member
    • Total Posts : 765
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/24 15:21:24 (permalink)
    0
    Is there a quick start guide we can direct beginners to?
    #5
    BroadwellConsultingInc
    Super Member
    • Total Posts : 97
    • Reward points : 0
    • Joined: 2020/06/09 06:07:55
    • Location: 0
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/24 16:31:02 (permalink)
    0
    In my opinion, any quickstart guide would probably use an internal oscillator.  And I feel like the MCC route is the quickstart method for most people.  
    #6
    upand_at_them
    Super Member
    • Total Posts : 765
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/24 18:23:42 (permalink)
    +2 (4)
    I meant a quick start guide for using a crystal.  Telling people to "RTFM" isn't as helpful as one might think; most beginners will be baffled by a datasheet that's 500+ pages.
    #7
    du00000001
    Just Some Member
    • Total Posts : 4071
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/24 21:29:49 (permalink)
    +2 (4)
    upand_at_them
    I meant a quick start guide for using a crystal.  Telling people to "RTFM" isn't as helpful as one might think; most beginners will be baffled by a datasheet that's 500+ pages.



    The oscillator section is less than 20 pages in the ..FM. One would expect that this little could be read and understood, although my daily experience differs.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #8
    mpgmike
    Super Member
    • Total Posts : 513
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/24 22:45:22 (permalink)
    0
    First question; if you have the option of using an internal oscillator, why would you opt for a crystal?
     
    Second question; with the blessing of numerous "modern" PIC chips, why do you choose the PIC18F4620?
     
    Third question; I see you have over 200 posts.  Have you successfully programmed a "Hello World" or even more complex program yet?
     
    Fourth question; out of curiosity, what are you ultimately hoping to accomplish?

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #9
    crosland
    Super Member
    • Total Posts : 2142
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: online
    Re: How to configure the external crystal with PLL 2020/11/25 02:11:06 (permalink)
    0 (2)
    mpgmike
    First question; if you have the option of using an internal oscillator, why would you opt for a crystal?
     



    Numerous reasons. CANbus for example.
    #10
    Nera
    Super Member
    • Total Posts : 244
    • Reward points : 0
    • Joined: 2017/10/11 07:13:25
    • Location: 0
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/25 05:27:10 (permalink)
    0
    1and0
    Neraildes
    How can I configure an external 8 Mhz oscillator crystal and turn on the PLL to result in 32 Mhz?
    What configuration bits should I change and what commands should I run?
    The microcontroller I am using is the PIC18F4620.

    Connect your crystal with two 22 pF to the PIC device, and use the HSPLL config bits setting.
     




    I'm doing as described below, but the PLL is
    disabled.
    My oscillator is 8Mhz.


    #pragma config OSC = HSPLL
    #pragma config FCMEN = OFF
    #pragma config IESO = ON


    What else should I configure? What procedure should I adopt for the PLL with external crystal to work?
    post edited by Nera - 2020/11/25 06:44:50
    #11
    du00000001
    Just Some Member
    • Total Posts : 4071
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/25 08:07:31 (permalink)
    +1 (1)
    Neraildes
    'm doing as described below, but the PLL is
    disabled.
    My oscillator is 8Mhz.


    #pragma config OSC = HSPLL
    #pragma config FCMEN = OFF
    #pragma config IESO = ON


    What else should I configure? What procedure should I adopt for the PLL with external crystal to work?



    How do you know that the PLL is disabled ?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #12
    Nera
    Super Member
    • Total Posts : 244
    • Reward points : 0
    • Joined: 2017/10/11 07:13:25
    • Location: 0
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/25 08:34:52 (permalink)
    0
    du00000001
    Neraildes
    'm doing as described below, but the PLL is
    disabled.
    My oscillator is 8Mhz.


    #pragma config OSC = HSPLL
    #pragma config FCMEN = OFF
    #pragma config IESO = ON


    What else should I configure? What procedure should I adopt for the PLL with external crystal to work?



    How do you know that the PLL is disabled ?




    I have serial communication that doesn't work and a 1 second time base that flashes an LED. This time base takes 4 seconds to flash the LED.
    #13
    du00000001
    Just Some Member
    • Total Posts : 4071
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/25 08:39:30 (permalink)
    +1 (3)
    Neraildes
    <...smipped…>
     
    I have serial communication that doesn't work and a 1 second time base that flashes an LED. This time base takes 4 seconds to flash the LED.



    Still some more opportunities for faults. You'd better post your code - we hate having to guess ...

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #14
    Nera
    Super Member
    • Total Posts : 244
    • Reward points : 0
    • Joined: 2017/10/11 07:13:25
    • Location: 0
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/25 10:27:35 (permalink)
    -1 (1)
    I will post my current code with the configuration I am using to work with 8 MHz internal clock + active PLL.
    My goal is to work with an external 8MHz crystal oscillator and active PLL.
     
            // CONFIG1H
            #pragma config OSC = INTIO67
            #pragma config FCMEN = OFF  
            #pragma config IESO = OFF     

            // CONFIG2L
            #pragma config PWRT = ON     
            #pragma config BOREN = SBORDIS 
            #pragma config BORV = 3        

            // CONFIG2H
            #pragma config WDT = OFF      
            #pragma config WDTPS = 16384

            // CONFIG3H
            #pragma config CCP2MX = PORTC 
            #pragma config PBADEN = ON     
            #pragma config LPT1OSC = OFF  
            #pragma config MCLRE = ON     

            // CONFIG4L
            #pragma config STVREN = ON   
            #pragma config LVP = OFF       
            #pragma config XINST = OFF   

            // CONFIG5L
            #pragma config CP0 = OFF      
            #pragma config CP1 = OFF      
            #pragma config CP2 = OFF      
            #pragma config CP3 = OFF      

            // CONFIG5H
            #pragma config CPB = OFF      
            #pragma config CPD = OFF      

            // CONFIG6L
            #pragma config WRT0 = OFF  
            #pragma config WRT1 = OFF  
            #pragma config WRT2 = OFF  
            #pragma config WRT3 = OFF  

            // CONFIG6H
            #pragma config WRTC = OFF  
            #pragma config WRTB = OFF  
            #pragma config WRTD = OFF  

            // CONFIG7L
            #pragma config EBTR0 = OFF  
            #pragma config EBTR1 = OFF  
            #pragma config EBTR2 = OFF  
            #pragma config EBTR3 = OFF  

            // CONFIG7H
            #pragma config EBTRB = OFF  
     
            #define _XTAL_FREQ 32000000


    //-----------------------------------------------------------------------------------------------
     
    void main(void)
    {
         OSCCONbits.IRCF0=1; //
         OSCCONbits.IRCF1=1; // 8 Mhz Internal
         OSCCONbits.IRCF2=1; //
         OSCCONbits.SCS0 =0;
         OSCCONbits.SCS1 =0;
         OSCTUNEbits.PLLEN=1; //pll 8*4 = 32Mhz    

         TRISA=0b11101111;  
         TRISB=0b00000001;
         TRISC=0b11110000;
         TRISD=0b11100011;
         TRISE=0xFF;
     
         T0CONbits.T0CS  = 0;
         T0CONbits.PSA    = 0;
         T0CONbits.T0PS1 = 1;
         T0CONbits.T0PS1 = 1;
         T0CONbits.T0PS2 = 1;      
         INTCON2bits.TMR0IP =0;
         INTCONbits.T0IE    =1;    
         
         //-------------------------------------------------------------------------
         RBIF=0;
         INTCONbits.INT0IE   =0;
         
         //-------------------------------------------------------------------------
         PIR1bits.TMR1IF = 0;  
         IPR1bits.TMR1IP=0;    
         TMR1H = 0x0B;         
         TMR1L = 0xBA;
         TMR1CS = 0;           
         T1CKPS0 = 1;          
         T1CKPS1 = 1;
         T1RUN=1;
         T1OSCEN=1;
         PIE1bits.TMR1IE=1;  
         TMR1ON = 1;           
             
         //-------------------------------------------------------------------------
         INTCONbits.PEIE    =1; 
         
         //-------------------------------------------------------------------------    
         INTCONbits.GIE        =1;  //Global Interrupt
    }
        



     
     
     
     
     
    #15
    crosland
    Super Member
    • Total Posts : 2142
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: online
    Re: How to configure the external crystal with PLL 2020/11/25 10:38:48 (permalink)
    0 (2)
    Posting working code is pointless, unless you are looking for a review.
     
    Post the failing code. And use code /code tags (put them in square brackets.
    #16
    upand_at_them
    Super Member
    • Total Posts : 765
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/25 11:54:49 (permalink)
    0
    Neraildes
            // CONFIG1H
           #pragma config OSC = INTIO67



    This is selecting the internal oscillator.  I thought you wanted to use a crystal?
    #17
    crosland
    Super Member
    • Total Posts : 2142
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: online
    Re: How to configure the external crystal with PLL 2020/11/25 12:18:13 (permalink)
    0
    upand_at_them
    Neraildes
            // CONFIG1H
          #pragma config OSC = INTIO67



    This is selecting the internal oscillator.  I thought you wanted to use a crystal?




    <sigh>Read what he posted, and then read my reply.
    #18
    Nera
    Super Member
    • Total Posts : 244
    • Reward points : 0
    • Joined: 2017/10/11 07:13:25
    • Location: 0
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/25 17:58:43 (permalink)
    0
    What I want to know is what should I change in this functional code so that I use the external crystal.
    #19
    davea
    Super Member
    • Total Posts : 585
    • Reward points : 0
    • Joined: 2016/01/28 13:12:13
    • Location: Tampa Bay FL USA
    • Status: offline
    Re: How to configure the external crystal with PLL 2020/11/26 00:21:20 (permalink)
    +1 (1)
    2.5.1 HSPLL OSCILLATOR MODE
    The HSPLL mode makes use of the HS Oscillator
    mode for frequencies up to 10 MHz. A PLL then multiplies
    the oscillator output frequency by 4 to produce an
    internal clock frequency up to 40 MHz. The PLLEN bit
    is not available in this oscillator mode.
    The PLL is only available to the crystal oscillator when
    the FOSC3:FOSC0 Configuration bits are programmed
    for HSPLL mode (= 0110).

    data sheet
    using correct pins ???
    OSC1/CLKI/RA7
    OSC2/CLKO/RA6
    is oscillator running check with scope ??
    post edited by davea - 2020/11/26 00:50:58
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2021 APG vNext Commercial Version 4.5