Hello, World!
I have a cheep chinese Pro Mini with ATmega168PA. I made some changes in order to reduce the power consumption - removed voltage regulator and changed the oscilator cristal 16 MHz to 32 kHz one. I burned LilyPad bootloader, that runs 8 MHz internal RC oscilator. Then I ran this code:
in setup() :
void setupSleep()
{
/*** Configure timer 2.***/
TCCR2A = 0x00; //overflow 0xFF (:256)
TCCR2B = 0x05; //5 gives 1 sec. prescale (clk/128)
TIMSK2 = 0x01; //enable timer2A overflow interrupt
ASSR = 0x20; //enable asynchronous mode AS2=1 xtal
sei();
set_sleep_mode(SLEEP_MODE_PWR_SAVE);
}
in loop() :
void enterSleep(uint16_t t, uint16_t mils)
{
power_adc_disable();
power_spi_disable();
power_timer0_disable();
power_timer1_disable();
power_twi_disable();
seconds=0;
TCNT2 = 0; // null counter
while(seconds<t){
sleep_enable();
sleep_mode(); // Now enter sleep and power down
//---- The program will continue from here after the timer timeout ----
sleep_disable(); // First thing to do is disable sleep.
// Serial.println(seconds);
}
mils>>=2;
if(mils!=0){
/*
TCNT2 = -mils; // set counter
sleep_enable();
sleep_mode(); // Now enter sleep and power down
//---- The program will continue from here after the timer timeout ----
sleep_disable(); // First thing to do is disable sleep.
*/
}
power_all_enable(); // Re-enable the peripherals.
}
T2 interrupt :
ISR(TIMER2_OVF_vect)
{
++seconds;
digitalWrite(A3, !digitalRead(A3)); // heart beat LED
}
All works fine, but after certain time hangs. Heart beat LED also stops. When I change enterSleep() to delay() there are no hanging. I think that internal 8 MHz RC oscilator can't start again for some reasons?
Is it posible to tweak some registers or fuses for stabilising the RC oscilator?