Urahara
Member
Hi
Am using a 18LF1220 (at 3.3V) and using the internal oscillator at 4MHz. No external crystals, etc.
Can the MCU in this configuration be put into deep sleep, ie CPU and peripherals turned off after X min of inactivity using timer1 to measure time?
I've tried setting IDLEN and SCS0 and SCS1 bits to zero as well but they do not seem to work.
The datasheet seems to suggest that the MCU cannot be configured for deep sleep with an internal oscillator.
Is that true?
Am using a 18LF1220 (at 3.3V) and using the internal oscillator at 4MHz. No external crystals, etc.
Can the MCU in this configuration be put into deep sleep, ie CPU and peripherals turned off after X min of inactivity using timer1 to measure time?
I've tried setting IDLEN and SCS0 and SCS1 bits to zero as well but they do not seem to work.
The datasheet seems to suggest that the MCU cannot be configured for deep sleep with an internal oscillator.
Is that true?
Code:
...
#pragma config OSC=INTIO2,WDT=OFF,LVP=OFF,MCLRE=OFF,IESO=OFF,BOR=OFF
...
void inactivity_timer_main(void)
{
if (PIR1bits.TMR1IF) { //overflow
PIR1bits.TMR1IF = 0; // clear interrupt flag
TMR1H = 0x0B; // Reset Timer 1
TMR1L = 0xDB;
gl_tick_cnt++;
if (gl_tick_cnt >= 60) { // 1 min = 120 ticks, 10 mins = 1200 ticks
gl_tick_cnt=0;
T1CONbits.TMR1ON = 0; //stop timer
//Prepare to sleep
PORTB=0xF0;
Nop();
INTCONbits.RBIF = 0; // Clear PORTB Interrupt Flag.
INTCONbits.RBIE = 1; // Enable Change-on-interrupt
OSCCONbits.IDLEN=0; // Device enters sleep mode upon Sleep instruction.
HC1_POWER=0;
Nop();Nop();Nop();Nop();
Sleep();
while (!OSCCONbits.OSTS); //loop until primary oscillator is ready
//Woke up...disable change on key interrupt, turn display on, show last menu
HC1_POWER=1;
INTCONbits.RBIE=0; // Disable Change-on-interrupt
Delay10KTCYx(20);
TMR1H = 0x0B; // Reset Timer 1
TMR1L = 0xDB;
T1CONbits.TMR1ON = 1; //start timer again
}
}
}