I have been working on a remote water pressure measuring device that needs battery life optimisation.
It uses Aruino UNO, a MPX2010DP differential pressure transducer. I power the thing with a 12V 1.2 Ah lead-acid sealed rechargable battery and it only lasts about 5 days =(.
I used the Todd Houstein code for this (https://sites.google.com/site/toddsstuffnthat/arduino-code-1/DataLogger.pde?attredirects=0&d=1)
I need to log data roughly every 1, 10, 60 min and 24 hrs in some cases.
Looking into the code and the debugging in the serial I found that the longest sleep time for the Arduino is set to 8 secs.
Then when setting up the logging interval in 1 min (60 secs)
const int StepTime = 60;
The result in the serial/file debugging looks like this
Logging to: LOGGER18.CSV
Date/time, MPX, Solar-Panel, Batt
1311819062,Sleep for,0.50 ***
"2011/7/28 2:11:3",592.00,627.00,682.00
1311819063,Sleep for,8.00 ***
1311819071,Sleep for,8.00 ***
1311819079,Sleep for,8.00 ***
1311819088,Sleep for,8.00 ***
1311819096,Sleep for,8.00 ***
1311819105,Sleep for,8.00 ***
1311819113,Sleep for,8.00 ***
1311819121,Sleep for,1.00 ***
1311819122,Sleep for,0.50 ***
"2011/7/28 2:12:3",592.00,627.00,682.00
So in 1 minute it checks out seven times if it was time to wake up. Then when setting log time to 1 hr, the code makes the Arduino check about 450 times without any need of it :~.
I figured out the SleepTimeIndex and the indexation of the vector, but have not been able to correctly setup the watchdog in order to use other SleepTime Indexes allowing larger sleep time intervals.
///////////////
// GoToSleep //
///////////////
// set system into the sleep state
// system wakes up when watchdog is timed out
void GoToSleep()
{
cbi(ADCSRA,ADEN); // switch Analog to Digitalconverter OFF
sleep_enable();
sleep_mode(); // System sleeps here
sleep_disable(); // System continues execution here when watchdog timed out
sbi(ADCSRA,ADEN); // switch Analog to Digitalconverter ON
}
///////////////////
// SetupWatchdog //
///////////////////
void SetupWatchdog(int SleepTimeIndex)
{
byte bb;
int ww;
if (SleepTimeIndex > 9 ) SleepTimeIndex=9;
bb=SleepTimeIndex & 7;
if (SleepTimeIndex > 7) bb|= (1<<5);
bb|= (1<<WDCE);
ww=bb;
MCUSR &= ~(1<<WDRF);
// start timed sequence
WDTCSR |= (1<<WDCE) | (1<<WDE);
// set new watchdog timeout value
WDTCSR = bb;
WDTCSR |= _BV(WDIE);
}
/////////
// ISR //
/////////
// Watchdog Interrupt Service: executed when watchdog timed out
ISR(WDT_vect)
{
f_wdt=1; // set global flag
}
///////////////////////
// GetSleepTimeIndex //
///////////////////////
int GetSleepTimeIndex(uint32_t TargetTime)
if (TargetTime > 8)
{
SleepTimeIndex = 9;
}
else if (TargetTime > 4)
{
SleepTimeIndex = 8;
}
else if (TargetTime > 2)
{
SleepTimeIndex = 7;
}
else if (TargetTime > 1)
{
SleepTimeIndex = 6;
}
else
{
SleepTimeIndex = TimingTolerance;
}
return SleepTimeIndex;
}
//////////////////
// GetSleepTime //
//////////////////
float GetSleepTime(int SleepTimeIndex)
{
float SleepTimes[] = {0.016, 0.032, 0.064, 0.128, 0.250, 0.500, 1, 2, 4, 8};
float SleepTime;
SleepTime = SleepTimes[SleepTimeIndex];
return SleepTime;
}
Any hint is more than welcomed.
AGT