No LowPowerTimer on mBuino?

Hello all.

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).

Ugg. the board ate my reply… Try again…

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.

1 Like

Hi @ AndyA, thank you for your reply, the modded library and your ideas. I think these should satisfy my needs. Keep you posted…

Edit: tested the timeElapsed() method in your version of the wakeUp library. Works great!

Directly after an uninterrupted sleep this method returns 0.0, After an interrupted sleep it returns the time elapsed until the interrupt. I presume this is the intended behavior. Am I correct?

@ maxint - That’s the opposite of what I was aiming for but it’s probably because I didn’t read the documentation correctly.

I though the system counted down from the value set and then interrupted when it reached 0.
Going by the results you are seeing it must count up from 0 and interrupt when it reaches the set value.

Oh well, as long as it works for you… :wink:

If you wanted the other way around it’s a one line function, change it to return LPC_WWDT->TV / (cycles_per_ms*1000) and you should get the a value that counts up from when the interrupt was set up.

@ 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.

Edit: see this program on mbed for more info

1 Like