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 CCS Technical Support

using the internal oscillator

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



Joined: 15 Sep 2008
Posts: 8

View user's profile Send private message

using the internal oscillator
PostPosted: Fri Feb 20, 2009 11:56 am     Reply with quote

Hi,

I am using compiler V4.086 with a PIC18LF6722

I am trying to set the internal oscillator to give a 32MHz clock but am only getting 8MHz. I have tried various options using the built in function setup_oscillator() but none seem to give me this clock rate.

Tried:
Code:

#FUSES INTRC
setup_oscillator(OSC_32MHZ|OSC_INTRC|OSC_31250);
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON);


Has anyone any idea?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 20, 2009 2:25 pm     Reply with quote

I don't have that PIC to test in hardware, but I think this program should
work.
Code:
#include <18F6722.h>
#fuses INTRC_IO,NOWDT,PUT,NOBROWNOUT,NOLVP
#use delay(clock=32000000)

//=============================
void main(void)
{

while(1)
  {
   output_high(PIN_B0);
   delay_ms(500);
   output_low(PIN_B0);
   delay_ms(500);
  }

}


CCS reads the #fuses and #use delay() statements, and then creates
start-up code to set the correct frequency for the internal oscillator
and also to set the PLLEN bit. I notice you didn't have a #use delay()
statement in your code for 32 MHz. That's essential. Here's part of the
.LST file for the program shown above. This is with compiler vs. 4.085.
Code:
.................... void main(void) 
.................... { 
0002A:  CLRF   TBLPTRU
0002C:  BCF    RCON.IPEN
0002E:  CLRF   FSR0H
00030:  CLRF   FSR0L

00032:  MOVLW  70       
00034:  MOVWF  OSCCON   // Set INTOSC = 8 MHz

00036:  MOVLW  40
00038:  MOVWF  OSCTUNE  // Set PLLEN bit = 1

0003A:  MOVF   OSCCON,W
0003C:  MOVF   ADCON1,W
0003E:  ANDLW  C0
00040:  IORLW  0F
00042:  MOVWF  ADCON1
00044:  MOVLW  07
00046:  MOVWF  CMCON

Also, what's the Vdd voltage on your PIC ?
There's a formula in the Electrical Characteristics section of the PIC
data sheet:
Quote:
FMAX = (16.36 MHz/V) (VDDAPPMIN – 2.0V) + 4 MHz;

This works out to a maximum 25 MHz frequency for a 3.3v Vdd.
delphy_boy



Joined: 15 Sep 2008
Posts: 8

View user's profile Send private message

PostPosted: Sat Feb 21, 2009 2:29 am     Reply with quote

Thanks PCM programmer,

I will give this a try.

I did have the #use delay statement, i just didn't post it.

Also i have read a few other things that say the oscillator has to be set to the primary if the internal oscillator is to be used at 16 or 32MHz. The in-built functions of the complier do NOT allow for this, nor does the project wizard. In both instances they set the oscillator source to internal which I am assuming will be my problem seen as in your code the value written to the OSCCON register sets the source to primary.

Your right about the Fmax, i forgot about that. I will just have to settle for 16Mhz internal clock instead.

Thanks again
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