I am running my Arduino projects like this:
My goal is to have this project run at 8mhz so that (1) battery last longer and (2) so that I am following the specs. I was able to burn a 8mhz bootloader to my Atmega328 chip thanks to this video: https://www.youtube.com/watch?v=fzZ2TR_mwgs
After following the video I am able to run sketches at 8mhz and they consume less current. But my original project crashes to the point where I have to burn a bootloader again. Even if I press the reset button it will not become responsive. I have discovered that this line of code is the one that makes my atmega328 chip unresponsive:
wdt_enable(WDTO_4S); // #include <avr/wdt.h>
I find out about that because removing that line made my project work. That line enables waking up after 4 seconds. So I basically perform some work and go to sleep for 4 seconds. I then repeat the same steps forever in order to save battery. So before going to sleep I execute this:
// wake up from sleep after 4 seconds
wdt_enable(WDTO_4S);
// go to deep sleep
if (true)
{
// BIG difference when in sleep
// Diable ADC (analog to digital converter)
ADCSRA &= ~(1 << 7);
SMCR |= (1 << 2); // power down mode
SMCR |= 1; // enable sleep;
// BOD DISABLE (big difference when in sleep only)
MCUCR |= (3 << 5); // set both BODS and BODSE at the same time
MCUCR = (MCUCR & ~(1 << 5)) | (1 << 6); // then set the BODS bit and clear the BOSE bit at the same time
__asm__ __volatile__("sleep");
}
// this line will not execute....
Anyways how could I solve this problem? Should I keep the original project and just replace the crystal to 8mhz? I will then have to keep in mind that all delays will be half the speed correct?