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

How to set internal osc. freq?

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



Joined: 09 Sep 2007
Posts: 2

View user's profile Send private message

How to set internal osc. freq?
PostPosted: Sun Sep 09, 2007 3:23 am     Reply with quote

Hi everyone,

I'm trying to program a PIC16F88 in C. I am new to using C for PICs so this question might seem trivial to many of you.

The thing is that my PIC is always running on the lowest frequency, 31.250Hz. I use this line : #use delay(clock=4000000) to tell the delay loop the expected frequency. At first I thought that this would also take care of the OSCCON register that I used to set the freq in ASM. To me it looks like it doesn't.
The only thing I could do was to connect an external Xtal Clock to get the PIC to run on the frequency I wanted. That's not cool - so my question is:
How on earth do I adjust the frequency of the internal osc in C?

Thanks in advance
Steini
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Sep 09, 2007 7:20 am     Reply with quote

Code:
#use delay(clock=4000000)
This instruction tells the compiler the actual clock speed of your processor so it can create correct timings for the delay_us() and delay_ms() functions. The naming of this instruction is not very good in the CCS compiler as in newer functions of the compiler the same command is used to define the timing for more functions like RS232 and internal oscillator configuration.

If your processor is to run at 31.250Hz, than set that value in the above command. Don't set it to 4Mhz.

You can specify the clock speed using the setup_oscillator() function. If you have set the #fuses to ITRC or INTRC_IO then the compiler will set the correct configuration for you in the OSCCON register. I have confirmed this with a test in both v3.249 and v4.038.
Code:
.................... void main()
.................... {
0062:  CLRF   04
0063:  MOVLW  1F
0064:  ANDWF  03,F
0065:  MOVLW  71   // load value 0x71  (= 8MHz internal oscillator)
0066:  BSF    03.5   // Select bank1
0067:  MOVWF  0F   // Write value to 0x8F (OSCCON)


For a clock of 31.250Hz the above code is missing because this is already the default value after a hardware reset.
If your code is not working double check you have the INTRC or INTRC_IO fuses specified.
Also read the manual for the Setup_osscilator() function as there are some special concerns related to clock speed switching.
steinire



Joined: 09 Sep 2007
Posts: 2

View user's profile Send private message

PostPosted: Sun Sep 09, 2007 8:17 am     Reply with quote

Thank you so much, works perfectly!
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