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

Two speed internal oscillator switching on PIC16F628A

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



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

Two speed internal oscillator switching on PIC16F628A
PostPosted: Tue Nov 15, 2005 7:59 am     Reply with quote

We have an application where the PIC needs to power up using the 31kHz internal oscillator, and then be put to sleep. When PIC wakes up, then the 4MHz internal oscillator is selected.

It appears that for this part that the CCS compiler must clear the OSCF bit in the PCON register to run at 4MHz (probably because we have declared '#use delay(clock=4000000)'). Is there any way to change this or just use '#use delay(clock=31250)' and '#use delay(clock=4000000)' before the relevant code areas?

BTW, setup_oscillator() is not recognised for this device. Compiler version is 3.190

Any thoughts?
Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 15, 2005 1:13 pm     Reply with quote

Here is a test program that shows how to switch the internal oscillator
frequency for your version of the compiler.

Code:
#include <16F628A.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)

#bit  OSCF = 0x8E.3        // PCON register
#define osc_4MHz()   OSCF = 1
#define osc_48KHz()  OSCF = 0   

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

delay_ms(1);

// Switch to 48 KHz speed.
osc_48KHz();   
#use delay(clock=48000)   

delay_ms(1);

while(1);
}
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Nov 16, 2005 7:16 am     Reply with quote

Thats fine.. Smile but how do we ensure the compiler doesn't switch the PIC to 4MHz after reset? (which would take too much current in our application)?
I will do some testing and have a look at the code the compiler emits using different #use delay() statements.. will post the results later.
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Nov 16, 2005 7:37 am     Reply with quote

After reset, you should immediately switch to the lower frequency clock in your first few lines of code in main(), which of course gets executed following a reset.

As for #use delay statements, the code will follow the #use delay() statement immediately above it, so be careful where you physically type in your functions.
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Nov 16, 2005 7:43 am     Reply with quote

Thanks Mike,

This looks like the way to do it - the micro will just have to take some current from the bypass capacitance until it does the oscillator mode switch!
I suppose Microchip made the 4MHz the default to avoid breaking older code.

Incidentally, the compiler doesn't seem to be generating any code that changes the OSCF bit - this ties in with other posts I checked about the #USE delay statement.

Thanks for the posts everyone!
Vic
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