"Dying gasp" Circuit for arduino.

Hi,

I've got a battery powered arduino data-logging project that writes data to a SD card.

Currently it logs (among other things) the start-up time. I'd like to modify it to also record the moment it shuts down. The problem is how can I record the moment that someone pulls the plug - i.e. physically disconnects it from the battery? It's relatively easy to monitor the battery voltage, detect when it starts getting low, and then write the time to the SD card and then stop logging. But how can I do something similar if the power is disconnected suddenly?

I think what I need to do is something like this..... put a large capacitor in the supply circuit, monitor the battery voltage on one of the input pins, detect when the battery is disconnected and use the charge stored in the capacitor to quickly perform one last write to the SD card. I've not done this before, but I think this is known as a 'last gasp' or 'dying gasp' circuit.

The problem is complicated by the fact that although the arduino itself may not use much juice, writing to the SD card is relatively power-consuming, and the project also includes a GPS module which needs to be kept alive since it provides the time information.

Is what I'm describing feasible, and is it the correct approach? More importantly, has this been done before and if so can someone point me in the direction of a suitable circuit diagram?

Thanks

While a capacitor can work it all depends on the current of the system as a whole.
You might be better off float charging a rechargavpble battery.

it all depends on the current of the system as a whole

That's what I feared!

A capacitor is a nice simple concept and requires no complicated charging circuits, but may not have the juice required for one last write to the SD card.

I'm sure you can find a big enough capacitor to keep the arduino going. There are some pretty hefty capacitors, like 4700uF (although that seems a little much)

what time scale are you looking at. If you want the rough time it was turned off then you could just write to the card a future time stamp. If its not updated then it was switched off somewhere around that time.

Grumpy_Mike:
rechargavpble battery.

these special devices are very rare.

can you write to silicon, then on start-up, copy the data to the SD card ?

not a solution for a device you want to pull the card from to see the last failure as you would have to power up to see that data.

Would a supercapacitor (or two) be suitable? They seem to be available in values over 100 Farads.

...R

you can read the time as you normally do,
note the time and keep a running time from the last read of time using millis() to have it ready and not have to go read the time.

with the system clock, you would not be off very much by the time you needed to read the time again.

you could keep track of time since the last SD write, or some such.

then, once your main power failed and the back-up takes over, you just write everything to EEPROM.
if you keep the last 10 power fails, your risk of loosing the data is much less.

what would happen if the power came on and off as the power lines were being worked on ?

If you want the rough time it was turned off then you could just write to the card a future time stamp

That's actually what I'm currently doing, it's known as a LSL indicator 'last sign of life'. The catch with doing this is that each write to the SD card can take up to about 200ms, so the application ends up spending all it's time writing to the SD card, and not enough time doing it's proper job!

can you write to silicon, then on start-up, copy the data to the SD card

Good idea. That may be a the best solution, writing to eeprom should be relatively quick and not take much power. Writing to SD card consumes a lot of power and time.

Would a supercapacitor (or two) be suitable?

Possibly - can you point me to circuit diagram where someone has already done this?

There is a 2nd aspect to this project. The device also includes a GSM modem, I'd like to be able to send an SMS warning that the device has shut down, however this requires power for a lot longer (12 - 15 seconds to send a text message). This would almost certainly require a button cell or other device to provide the power, but this would require a circuit to keep the cell charged, a circuit to monitor the main supply, and a timer to shut down the device entirely after the 'dying gasp' has completed - after all, I don't want the device to continue running and drain the button cell until it's beyond recharge.

sounds like you need a full battery backup with 30 seconds of power.
read the time,
write to the eeprm
send out the last dying gasp
maybe try to write the eeprom again.

just how 'knife edge' do you need this to be ?

if I had this on my house and lost power, the txt message would be my timestamp.
a local save would be good as well, but a window of a few minutes would not be a problem.

simple AA cells or some such with a charging circuit, when the power fails to that, then blamo! start the end of life loop.