View previous topic :: View next topic |
Author |
Message |
embedder
Joined: 11 Feb 2010 Posts: 19
|
PIC18F85K22 Internal Osc & PLL |
Posted: Fri Apr 08, 2011 9:34 am |
|
|
Can anyone clarify the settings to enable the PIC18F85K22 internal oscillator and PLL to achieve a clock speed of 64 MHz? At the moment I have these settings. Thanks.
V4.119
Code: |
#FUSES HSM
#FUSES INTRC_HP
#FUSES PLLEN
#use delay(clock=16000000)
setup_oscillator(OSC_16MHZ);
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 08, 2011 4:07 pm |
|
|
The #use delay(clock= ) statement should always match the exact running
frequency of the PIC. In this case, 64 MHz. HSM is not used for the
internal oscillator. It's used with an external crystal.
I don't have the 18F85K22, or any PIC in that family. I do have an
18F45K22, which is similar. The following program runs at 64 MHz with
vs. 4.119.
I think with your PIC, you should use INTRC_HP instead of INTRC_IO.
Code: |
#include <18F45K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=64M)
//======================================
void main(void)
{
// Blink the LED once per second. The 10/90 duty cycle
// makes it easier to time the flashes with a stopwatch.
while(1)
{
output_high(PIN_B0);
delay_ms(100);
output_low(PIN_B0);
delay_ms(900);
}
} |
|
|
|
embedder
Joined: 11 Feb 2010 Posts: 19
|
|
Posted: Fri Apr 08, 2011 5:30 pm |
|
|
Thanks. I will try it out and let you know. |
|
|
embedder
Joined: 11 Feb 2010 Posts: 19
|
|
Posted: Mon Apr 11, 2011 8:27 am |
|
|
Unfortuately, no luck with those settings.
Looking at other device .h files it appears that setup_oscillator(); needs to be correct, but there is no OSC_64MHZ option for this part. |
|
|
drolleman
Joined: 03 Feb 2011 Posts: 116
|
|
Posted: Mon Apr 11, 2011 12:02 pm |
|
|
setup_oscillator(OSC_16MHZ|OSC_PLL_ON); //64 mhz |
|
|
embedder
Joined: 11 Feb 2010 Posts: 19
|
|
Posted: Mon Apr 11, 2011 12:45 pm |
|
|
Thanks drolleman. Tried OR'ing OSC_PLL_ON. Sadly it has no effect. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 11, 2011 12:57 pm |
|
|
The 18F85K22 data sheet says you have to use the PLLEN fuse.
Quote: | For the INTIOx modes (HF-INTOSC):
• Only the PLLEN can enable the PLL (PLLCFG is
ignored).
• When the oscillator is configured for the internal
oscillator (FOSC<3:0> = 100x), the PLL can be
enabled only when the HF-INTOSC frequency is
8 or 16 MHz. |
|
|
|
w2drz
Joined: 27 Dec 2006 Posts: 55 Location: Western New York - USA
|
May be of interest also? |
Posted: Mon Apr 11, 2011 3:00 pm |
|
|
PCM programmer wrote: | The 18F85K22 data sheet says you have to use the PLLEN fuse.
Quote: | For the INTIOx modes (HF-INTOSC):
• Only the PLLEN can enable the PLL (PLLCFG is
ignored).
• When the oscillator is configured for the internal
oscillator (FOSC<3:0> = 100x), the PLL can be
enabled only when the HF-INTOSC frequency is
8 or 16 MHz. |
|
Hi,
CCS stated this:
#use delay(clock=64M, crystal=16M) // 4xPLL setting
This is for use with a 16 MHz crystal.
What setting for internal osc I do not know.
Here is a test pgm on site to look at with some notes for not to use ?
see on this forum: 18F46K80 Test Pgm. for new chip using Ver 4.119
If the MCLR is able to be set to a output pin in the K22 at this time do not use 'NOMCLR' fuse, that will/may put the chip in a state so as can not do a program of it for now.
Hope this will be fixed in V 4.120, as there is new programing requirements as NO "PGM" pin for the K80 series and have not looked at the K22 if have same issue.
As waiting on shipment of new K80 chips so can not say this is correct information as for now waiting on the fix of the programing problem by CCS to fix that and the release of V 4.120 with "K" series fix's.
W2DRZ |
|
|
embedder
Joined: 11 Feb 2010 Posts: 19
|
|
Posted: Mon Apr 11, 2011 3:17 pm |
|
|
Thanks w2drz.
Regarding PLLEN: OR'ing OSC_PLL_ON with OSC_16MHZ seems to set the correct bit in the OSCTUNE reg. But only delay(clock=16M) works correctly ... clock=64M gives 4 sec pulses (in PCM programmer's example).
Code: |
.................... setup_oscillator(OSC_16MHZ);
012E: MOVLW 70 (=16 MHz)
0130: MOVWF FD3 (OSCCON)
0132: CLRF F9B (OSCTUNE)
0134: CLRF F64 (OSCCON2)
.................... setup_oscillator(OSC_16MHZ|OSC_PLL_ON);
012E: MOVLW 70 (=16 MHz)
0130: MOVWF FD3 (OSCCON)
0132: MOVLW 40 (=PLL enabled)
0134: MOVWF F9B (OSCTUNE)
0136: CLRF F64 (OSCCON2)
|
|
|
|
w2drz
Joined: 27 Dec 2006 Posts: 55 Location: Western New York - USA
|
|
Posted: Mon Apr 11, 2011 3:23 pm |
|
|
embedder wrote: | Thanks w2drz.
Regarding PLLEN: OR'ing OSC_PLL_ON with OSC_16MHZ seems to set the correct bit in the OSCTUNE reg. But only delay(clock=16M) works correctly ... clock=64M gives 4 sec pulses (in PCM programmer's example).
------------------
PS: I programmed 2 K80 chips with NOMCLR,
dead in the water waiting on new chips or CCS Fix's.
------------------
W2DRZ
Code: |
.................... setup_oscillator(OSC_16MHZ);
012E: MOVLW 70 (=16 MHz)
0130: MOVWF FD3 (OSCCON)
0132: CLRF F9B (OSCTUNE)
0134: CLRF F64 (OSCCON2)
.................... setup_oscillator(OSC_16MHZ|OSC_PLL_ON);
012E: MOVLW 70 (=16 MHz)
0130: MOVWF FD3 (OSCCON)
0132: MOVLW 40 (=PLL enabled)
0134: MOVWF F9B (OSCTUNE)
0136: CLRF F64 (OSCCON2)
|
|
|
|
|
embedder
Joined: 11 Feb 2010 Posts: 19
|
|
Posted: Mon Apr 11, 2011 3:47 pm |
|
|
There doesn't appear to be a problem programming PIC18F85K22's with NOMCLR. They keep working, just not at the desired speed.
Code: | #use delay(internal=8M) |
is the highest internal speed, otherwise the complier throws "Internal Osc Freq Wrong"
Datasheet page 43 says Quote: | When the oscillator is configured for the internal
oscillator (FOSC<3:0> = 100x), the PLL can be
enabled only when the HF-INTOSC frequency is
8 or 16 MHz. |
Then page 52 says Quote: | The PLL is available only to HF-INTOSC.
The other oscillator is set with HS and EC modes. Additionally,
the PLL will only function when the selected
output frequency is either 4 MHz or 16 MHz
(OSCCON<6:4> = 111, 110 or 101). |
This 4 MHz must be a typo.
Anyway,
Code: | #use delay(internal=4M, clock=16M) |
throws the same error (99). |
|
|
embedder
Joined: 11 Feb 2010 Posts: 19
|
|
Posted: Tue Apr 12, 2011 11:13 am |
|
|
The solution is:
1. Upgrade to PCH 4.120
2. If you don't change the speed at run time remove the #fuses (INTRC_HP & PLLEN) and setup_oscillator(). Then use just:
Code: |
#use delay( internal=64mhz )
|
|
|
|
|