Detect Teensy power failing in time to save data?

Status
Not open for further replies.

DaQue

Well-known member
Is there a way to trigger a save of a few items to eeprom just before the teensy has to shut down due to low voltage on the 3.3v Vreg? I'm experimenting with a lipo and OLED (Teensy to feather adaptor) and so farm I'm impressed how long it has run a test program just monitoring its own battery voltage( 8 hours so far) and thought for some projects it would be good to save state if the battery runs out before power returns. I could poll the battery voltage like I'm doing now but it might not always fail at the same point due to whatever.
 
There are special battery monitoring ICs for that purpose. You connect one of them between the LIPO and the Teensy so that its "power good" signal will trigger a pin interrupt on the Teensy when falling. During the ISR, the Teensy would rapidly save the important data and/or you could use the same interrupt to put the Teensy in sleep mode, allowing it to wake up with the rising "power good" signal.
 
To do this reliably, you really need to sense the 5V power at the regulator input. Then you can detect when it's falling below some threshold like 4V, where the 3.3V power is still good and you have (hopefully) enough time to complete those EEPROM writes before the CPU stops.
 
Is there a way to trigger a save of a few items to eeprom just before the teensy has to shut down due to low voltage on the 3.3v Vreg? I'm experimenting with a lipo and OLED (Teensy to feather adaptor) and so farm I'm impressed how long it has run a test program just monitoring its own battery voltage( 8 hours so far) and thought for some projects it would be good to save state if the battery runs out before power returns. I could poll the battery voltage like I'm doing now but it might not always fail at the same point due to whatever.

Since you have the feather adapter, the feather adapter connects pin A7 via a voltage divider to the raw battery power input. When the battery is freshly charged (4.2v), the voltage should read 2.1v (and analogRead (A7) should be around 650). When the battery is at its normal voltage (3.7v), analogRead(A7) should probably read about 575. If analogRead(A7) drops to around 475, the battery is nearly exhausted. Note, this is done by doing calculation, assuming the voltage divider divides the voltage in half. You should measure it yourself what the normal values are for freshly charged battery (4.7v) and normal battery (3.7v), and extrapolate for low voltage (3v), and give yourself some padding.
 
Thanks all. I am already reading the bat and a resistor pair to Vin wouldn't be hard. I just thought there might be an interupt or something built for just for that somewhere in thousands of pages of technical docs.
 
Note that sensing the voltage of a battery under use is a rather poor indication of it's charge level. If you draw a current spike, the voltage will probably drop below the level you would assume is 'battery empty'. A more correct estimate of state-of-charge is the Coulomb counting method, but this is quite complex. If your current draw is rather constant, you'll probably be alright.
 
Either Sparkfun or Adafruit, maybe both, sell a coulomb counter chip. If I decide to get deep into it I will pick one up. For right now I think just having the battery back up will be good enough. It was still going strong after 12 hours and I didn't put in any effort to making it low power like using the snooze library instead of delay or running slower than 96 MHz. It has ran twice as long I was hopping. What I need to do next is read up on the LIPO charger chip.
 
Status
Not open for further replies.
Back
Top