Can't get 18F2221 PLL to run with INTOSC


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default Can't get 18F2221 PLL to run with INTOSC

    I have -

    OSCTUNE =%01000000 ' bit 6 to turn on the PLL
    OSCCON = $F0 ' %11110000

    Location 0x300001 (Config1H) = 0xF9 , as confirmed by my ICD2

    OSC2 shows 2MHz, so the internal oscillator is running at 8MHz.

    But, my code is only executing at the 8MHz rate. I'm not getting
    the benefit of the PLL.

    What am I doing wrong?
    Charles Linquist

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    I have -
    OSCTUNE =%01000000 ' bit 6 to turn on the PLL
    OSCCON = $F0 ' %11110000
    Location 0x300001 (Config1H) = 0xF9 , as confirmed by my ICD2
    OSC2 shows 2MHz, so the internal oscillator is running at 8MHz.
    But, my code is only executing at the 8MHz rate. I'm not getting
    the benefit of the PLL.
    What am I doing wrong?
    According to Section 2.6.4 of DS39689E, the PLL will only work on the internal oscillator if you have 4 or 8Mhz selected, thereby giving you the option of 16 or 32Mhz.


    Then again, it is a 'Preliminary' datasheet...aren't they all? almost...

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


    Did you find this post helpful? Yes | No

    Default

    But I DO have 8 MHz selected.

    OSCCON <6:4> are "111"
    Charles Linquist

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    But I DO have 8 MHz selected.

    OSCCON <6:4> are "111"
    Well, then, let's see some code. Might be some extra 'hidden' instructions in there that you aren't catching.

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


    Did you find this post helpful? Yes | No

    Default

    ASM
    ifndef __18F2221
    error "Wrong Processor Type"
    endif
    ENDASM

    DEFINE OSC 32
    DEFINE NO_CLRWDT 1
    DEFINE HSER_RCSTA 90H
    DEFINE HSER_TXSTA 24H
    DEFINE HSER_CLROERR 1
    DEFINE LOADER_USED 1 ' Tell compiler to relocate code for bootloader
    Define USE_LFSR 1



    TRISA = %11111111
    TRISB = %11111110
    TRISC = %10111111

    ADCON1 = $FF ' Start as all digital
    CMCON = %00000111 ' No Comparator used, turn it off
    ADCON2 = %10000110 ' Right Justify, /64
    OSCTUNE =%01000000 ' bit 6 to turn on the PLL
    OSCCON = %01110000 ' %11110000
    TopLoop:
    Toggle PORTB.0
    PAUSE 10
    GOTO TopLoop
    Charles Linquist

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    So you're only getting about 12.5Hz on PortB.0?

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


    Did you find this post helpful? Yes | No

    Default

    Yes, and as I mentioned, I'm getting 2MHz out of OSC2. Since that is a /4 , the oscillator is in fact running 8. Only the PLL isn't working properly.
    Charles Linquist

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    Yes, and as I mentioned, I'm getting 2MHz out of OSC2. Since that is a /4 , the oscillator is in fact running 8. Only the PLL isn't working properly.
    I'm guessing here...the datasheet is a bit convoluted and jumps back and forth a bit...
    2Mhz from OSC2 is right isn't it? OSC2 is FOsc/4, FOsc/4 is 8Mhz/4... System clock isn't FOsc in this case, it's the actual clock speed before the PLL...
    Try that test program with
    main:
    High portb.0
    pause 500
    low portb.0
    pause 500
    goto main
    .......just to see what happens. Should be one flash per second of course at 32Mhz. One flash every 4 seconds would certainly mean 8Mhz.


    Also, I'm wondering if the bootloader is messing with your bits for you and shutting off your PLL!!!

  9. #9
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Have you tried OSCCON = %01110010?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Have you tried OSCCON = %01110010?
    Don't I feel like a dipstick! Internal OSC block was never selected in the first place!!!

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Also, try putting the OSCCON statement before the OSCTUNE.

    Quote Originally Posted by datasheet
    Additionally,
    the PLL will only function when the selected output frequency
    is either 4 MHz or 8 MHz (OSCCON<6:4> = 111
    or 110). If both of these conditions are not met, the PLL
    is disabled and the PLLEN bit remains clear (writes are
    ignored).
    <br>
    DT

  12. #12
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Yep I think DT just nailed it. Might be holding it off until it's in the right mode for the switch.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    Confirmed -

    Darrel, you were right again. Now that I switch to 8MHz BEFORE I enable the PLL, it
    works as expected.

    Thanks!
    Charles Linquist

  14. #14
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Thumbs up

    S-W-W-EET!
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    And one last "Gotcha" that I forgot to mention earlier - bits 0 and 1 of
    OSCCON *MUST* be set to "00".

    Even though you are running off the Internal Oscillator Block, if you
    enable the PLL, you have to configure for PRIMARY OSCILLATOR.

    Summary -

    To run off the Internal oscillator and use the 4X PLL:

    Set OSCCON bits 6 through 4 for either 8MHz (111) or 4MHz (110) and OSCCON
    bits 1 and 0 for PRIMARY OSCILLATOR (00)

    Set OSCTUNE.6 = 1 to enable the PLL.

    In that order!
    Charles Linquist

Similar Threads

  1. Program compiles and writes but can't run
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 23rd March 2009, 04:38
  2. 18F4520 and internal osc & PLL
    By pwhitt in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th September 2008, 06:38
  3. 16F628 and LMX2306 PLL loading.. help
    By kessral in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 11th June 2008, 17:03
  4. Pll?
    By atwoz in forum General
    Replies: 2
    Last Post: - 19th December 2007, 10:20
  5. Cannot compile for 40MHz 4 x pll
    By passion1 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 21st October 2007, 17:50

Members who have read this thread : 0

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