futz
Active Member
I've written a little routine to kick my clock down to a low power state for when it's on battery backup. I'm trying to get it to switch from the 20MHz main crystal to the 32.768kHz on Timer1 on loss of main power, and then switch back on power restore. But when power is restored the clock isn't running anymore. I've read the datasheet oscillator chapter four times and I don't see any "gotchas" I've missed. Here's the routine. RA5 senses main power. Oh ya, it's a 18F248:
Yes, the OSCSEN config bit is set enabled. ![Big Grin :D :D](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Code:
void lo_power(void){
ccpr1l=0; //turn off LCD backlight
adcon0.ADON=0; //A/D off
osccon=1; //switch to timer1 osc (32.768kHz) - low power mode
while(!porta.5) //wait while no power
delay_ms(100);
osccon=0; //switch back to 20MHz crystal
adcon0.ADON=1; //turn A/D back on
ccpr1l=bl; //restore backlight
}
Last edited: