In my current project I’m using a battery powered mBuino. To preserve battery life I using the sleep and wakeup libraries by @ AndyA and @ Sissors. Every so many seconds, or when a button is pushed, mBuino wakes up and does something. I know that in PowerDownWD mode the Timer class can not be used to measure the time that mBuino was powered down. I also know that the low resolution watchdog timer can be used to wake mBuino up. Is there a way I can use that timer to measure the time it was powered down?
During my search I found the LowPowerTimer class which sounds like what I’m looking for. Unfortunately it seems that that class is not (yet) implemented for the mBuino platform. Is there an easy workaround to make it available?
Since opening two topics might be a bit over the top: I also want to detect a battery low status. While the mBuino still operates nicely on voltages below 3 Volts, the reference voltage also drops. On Arduino one can select an internal 1.1V reference voltage to get accurate analog readings. Is there a way to supply mBuino with an equally low reference voltage? (I’m now using a silly workaround involving a boost converter to pump the dropping battery voltage up to 5V to get a stable reference voltage that allows me to measure the battery voltage before the converter).
The LowPowerTimer can’t easily be ported, it uses an RTC module in the CPU, the LPC11U24 on the mbuino doesn’t have one.
The method used in the wakeup library is to use the watchdog timer to generate the wakeup interrupt. There is a way to read the time remaining from the watchdog and so if we wake up from some other source that will then give you some sense of the time elapsed.
WakeUp - Hack of the real wakup timer library to add time … | Mbed is a hacked version of the library which adds a timeElapsed() function that returns a float of the number of seconds since the wakeup timer was last set. A little arbitrary but since you’ll typically set the timer as the last thing before going to sleep that is a reasonable substitute for time spend asleep.
For the ADC/power supply issue there isn’t an easy way to separate the ADC reference from the power supply voltage.
There are two options I can think of, you could use the brownout detection circuit to indicate that the battery voltage is dropping below 3V and so the readings are unreliable. That gives you the option of generating an interrupt at 3 different thresholds between 2.8 and 2.4V. It doesn’t correct the readings but at least you know the battery is getting low.
Or if you want accurate ADC values all the way down you could add a voltage reference to one of the analog inputs, if you measure that you can calculate the current scale factor required to convert from ADC readings to voltage and so compensate for the dropping supply voltage. Something like a ~1V zener diode should be good enough and fairly simple to add.
@ AndyA: as I didn’t have a 1V zener laying around, but I looked into other ways of determining the VCC. I think I’ve found a method which seems to work, involving only a resistor! At the moment I’m still working on software adjustments to improve accuracy, but I intend to publish an example program and some documentation as soon as it is useful for my project involving battery powered mBuino’s.