I am trying to put my controller in sleep mode and waking it up on a certain number of timer overflow. The code is as below:
//*******TIMER 2 INITILIZATION will be used
TCCR2=0X07; //clock source select, prescaler
TIMSK=0X40; //timer 2 interrupt selected
TCNT2=0X00; // timer resistor
sei();
// controller sleep mode
set_sleep_mode(SLEEP_MODE_PWR_SAVE); // sleep mode selected
sleep_enable(); // set SE bit
sleep_cpu(); // sleep mode activated
do
{
if(count>=1000) // min delay
{
sleep_disable(); // SE bit reset
_delay_ms(1000);
print("waking up.....");
_delay_ms(2000);
cmd(0xc0);
print("AT+CFUN=1");
_delay_ms(1000);
transmit("AT+CFUN=1\r\n");
_delay_ms(1000);
_delay_ms(2000);count=0;
break;
}
else
{
print("sleep");
sleep_enable();
sleep_cpu();
}
} while (1);
the corresponding ISR is as follows
ISR(TIMER2_OVF_vect)
{
count++;
}
The problem it is not coming out of sleep mode.
I am using internal clock 8MHz and timer2.
edit: i found this description in datasheet ,so this means i have to use asynchronous clock for timer 2 (i.e provided by external crystal osc).Is there any way i can do this with the help of internal clock.