View previous topic :: View next topic |
Author |
Message |
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
Two speed internal oscillator switching on PIC16F628A |
Posted: Tue Nov 15, 2005 7:59 am |
|
|
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
|
|
Posted: Tue Nov 15, 2005 1:13 pm |
|
|
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
|
|
Posted: Wed Nov 16, 2005 7:16 am |
|
|
Thats fine.. 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
|
|
Posted: Wed Nov 16, 2005 7:37 am |
|
|
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
|
|
Posted: Wed Nov 16, 2005 7:43 am |
|
|
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 |
|
|
|