CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC18F85K22 Internal Osc & PLL

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
embedder



Joined: 11 Feb 2010
Posts: 19

View user's profile Send private message

PIC18F85K22 Internal Osc & PLL
PostPosted: Fri Apr 08, 2011 9:34 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 4:07 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 5:30 pm     Reply with quote

Thanks. I will try it out and let you know.
embedder



Joined: 11 Feb 2010
Posts: 19

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 8:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 12:02 pm     Reply with quote

setup_oscillator(OSC_16MHZ|OSC_PLL_ON); //64 mhz
embedder



Joined: 11 Feb 2010
Posts: 19

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 12:45 pm     Reply with quote

Thanks drolleman. Tried OR'ing OSC_PLL_ON. Sadly it has no effect.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 12:57 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

May be of interest also?
PostPosted: Mon Apr 11, 2011 3:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 3:17 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 11, 2011 3:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 3:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 11:13 am     Reply with quote

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 )
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group