I am building my project to be battery powered @3.3V using a LiPo battery.
The thing is that I am using software RTC, so I want it to never fully lose power.
What I want to do is feed the Vin to an analog input and monitor it. When the voltage shows that the battery is dying I will put the device on standby to protect its time keeping and other stuff.
My issue is that from what I have read and my experience with camera batteries, Lithium batteries tend to keep a steady voltage and then die fast.
Anyone knows what is the drop pattern on such a battery so that I can detect it in time to reserve some power to keep the device sleeping until it is recharged?
The actual discharge curve will vary depending on many things including: discharge rate, cell capacity, and manufacturer.
But at a relatively low discharge rate the voltage will slowly drop from 4.2volts down to around 3.6 volts. After that the voltage can drop quickly. Some of the LiPo manufactures publish discharge graphs, here is one: FMA Direct – Everything about RC Cars, RC Boats more & more.
I suggest you monitor your actual cells performance to figure out what the ideal reading is for your cell with your discharge rate.
Don't let the cell discharge below around 3.3 volts and remember that the default analogRead value uses the supply voltage as a reference so you need to use the 1.1 volt reference (or an external reference) if you want to measure the supply voltage.
By the way, the DEFAULT setting for analogreference() takes the reading from Vin right?
No. The reference voltage command defaults to using the voltage on the AVCC power pin on the micro. A analog reference(internal) switches to an internal regulated 1.1vdc reference. A analog reference(external) uses whatever voltage is wired to the AREF pin on the micro. The Vin pin is just wired to the external power input connector on the Arduino board and has nothing to do with being a reference voltage. In your case it's the voltage you want to monitor by wiring it through a resistor voltage divider and then on to an analog input pin.
Here is a better explanation from the Arduino site:
The default reference is the Vcc line and on a standard board (duemilinove) thats the pin marked 5v. The Vin pin is connected to the input of the regulator.
BTW, there is a recent thread that has a method to use the internal reference to get the voltage powering the chip without an external voltage dividier, but I think using the external divider is easier, see: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1253085100/12#12
Its not clear from your post what other information you were hoping for.
I don t need to execute anything. I just need to find the settings that don t turn off the counter used by millis()
The millis code works through an interrupt that gets called around four times every millisecond. With the controller coming out of standby that many times per second you may not be gaining much power savings.
I found out on some other site (can t find the link now) that timer0 is actually used for all arduino system timing stuff, including the millis() .
I guess using the power.h defined macros, I can disable everything I can except timer0. Which means, when I bring the device out of standby, the software rtc can be updated without losing time.
I ll check the pdf now as well florinc. thanks a lot
Even if you have millis() working, how does that equate to real time (HH:MM::SS)? (You would need to know when you started your arduino, plus how many times millis() rolled over).
Well arduino obviously started on millis() = 0, so calculating the real time based on some configuration point is easy.
millis() counter overflows after 50 days which is something I can leave with. But even so, I could program an ISR on lets say timer2 (8bit like timer0) to bring the device back to life before the counter overflows, handle the overflowing and then go back to sleep.
I don t know. I m just thinking here... keeping timers on might be expensive power-wise ... I need to do some more tests...
From some quick testing, from all the predefined power modes, only SLEEP_MODE_IDLE seems to leave millis() going, but also leaves loop along with many other stuff going .
I will have to do more tests tomorrow with the custom options on power.h
The biggest problem I have now is that I am seriously getting low on program space on the 328, so instead of that I might just add a GPS with integrated RTC and bring the project to an entirely different level... Anyway... quite off-topic...
I will have GPS available as an upgrade and up to some point I am seriously considering making it standard.
We ll see...
I really don t like the extra 15 bucks for something that can be implemented roughly in software.