PDA

View Full Version : Can't get 18F2221 PLL to run with INTOSC



Charles Linquis
- 5th February 2008, 18:26
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?

skimask
- 5th February 2008, 18:45
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...

Charles Linquis
- 5th February 2008, 19:04
But I DO have 8 MHz selected.

OSCCON <6:4> are "111"

skimask
- 5th February 2008, 19:11
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.

Charles Linquis
- 5th February 2008, 19:16
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

skimask
- 5th February 2008, 19:19
So you're only getting about 12.5Hz on PortB.0?

Charles Linquis
- 5th February 2008, 19:28
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.

skimask
- 5th February 2008, 19:52
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!!!

Bruce
- 5th February 2008, 19:54
Have you tried OSCCON = %01110010?

skimask
- 5th February 2008, 20:02
Have you tried OSCCON = %01110010?

Don't I feel like a dipstick! Internal OSC block was never selected in the first place!!!

Darrel Taylor
- 5th February 2008, 20:02
Also, try putting the OSCCON statement before the OSCTUNE.


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>

Bruce
- 5th February 2008, 20:11
Yep I think DT just nailed it. Might be holding it off until it's in the right mode for the switch.

Charles Linquis
- 5th February 2008, 20:18
Confirmed -

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

Thanks!

Darrel Taylor
- 5th February 2008, 20:25
S-W-W-EET! :)
<br>

Charles Linquis
- 5th February 2008, 21:26
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!