Can a 18LF1220 be put into deep sleep when using the internal oscillator

Status
Not open for further replies.

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?

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
        }
    }      
}
 
Timer1 is not clocked during sleep. You need to use the WDT to periodically wake the chip or use idle mode.

Mike.
 
Guess my first message was not too clear (long day trying to fix the %^* problem ).

So my situation is this :
1) MCU is running on internal oscillator clock
2) I set OSCCON to 0b01100000 (ie 4MHz, IDLEN=0, SCS0 and SCS1 = 0)
3) One of the MCU pin is turned on to light a LED
4) Sleep() is executed, but LED is still lighted

One possibility for the above situation is the CPU is put to sleep, but the peripherals are not. But the OSCCON settings seems ok.

Any thoughts? Thanks!
 
When putting the micro in deep sleep... You may want to tri-state the pins so they don't consume any power anyway!!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…