4

Hi I'm a newbie and working on a project with Arduino Due(Atmel3X8E).I want to try and save the important variables to the eeprom during a power outage,using the brown out detector.Is it possible to do this? Thank you.

  • What is your power source? – gbg Feb 7 at 8:38
  • We plan on using the ac mains 220v 50hz stepped down to 12v. – Tejus Vivek Feb 7 at 9:41
  • Okay, that is good - see my answer for the details – gbg Feb 7 at 9:55
9

Not a good idea - if the power goes down when you writing to EEPROM, your EEPROM data will be corrupted. The brown-out detector goal is to shut off the MCU, before it goes mad due to low power voltage.

The solution of this issue - use some huge capacitors (about 4700 mkF) - like a small UPS device.

Scheme

When external power goes off, you well get enough time and power to store your bytes safely.

How it works

When +5V is okay, the capacitor is charged on, and the light diode (pins 1-2) inside of PC817 is on, so the transistor part of PC817 (pins 3-4) is open, and POWER_GOOD signal is LOW.

When power goes off, capacitor starts to discharge and give power to the right part of scheme. The Schottky diode acts as a valve, that stops the power to go to the left part. The another diode, which is inside of PC817 now goes off, and the transistor goes to close - POWER_GOOD signal goes to HIGH level and your program may start save data to EEPROM.

Why the optocoupler?

We need to investigate about internal AVR chip circuit. It has couple of diodes on each pin: AVR internals

So, when we connect PIN directly to power, +5V, and connect AVR's VCC to +5V over the Schottky diode, we've got two diodes in parallel! This situation is very bad, because they may compete, which will conduct the current - and, in some cases, internal (which is weak), chip diode wins. All controller power current start flow thru this weak diode, heats it up and toasts the chip! Not very good.

| improve this answer | |
  • 1
    I have the same circuit but without the U1 for a "solar power" display. Just connecting the 5V to an interrupt pin. Your solution is more elegant (but why an optocoupler and not just a mosfet?), but it could be more simple. – Adriano Feb 7 at 10:29
  • 1
    @Adriano - updated my answer – gbg Feb 7 at 10:56
  • 5
    I think you could still use a simple transistor instead of an opto-coupler as per Adriano's comment. Or even just put a resistor in series with the pin. You have a resistor there already! – user253751 Feb 7 at 16:34
  • 1
    Upvote for answering the question and schematics. I do share concerns about the optocoupler working voltage vs. actual supply levels, but it's a good solution that directly answers the question. FRAM and EERAM are also good, but that depends on use case. – RDragonrydr Feb 12 at 19:13
3

An alternative solution to this is to use an "EERAM". This is an EEPROM with an SRAM buffer in front of it. A large capacitor is used to provide power while the contents of the SRAM are stored in the EEPROM.

It sounds complex, but it's simple since they are made as a dedicated chip. One good example is the 47C16 from Microchip. The EEPROM backup is completely transparent to the user, and you can use it just like an I2C connected SRAM chip (so no worries about wearing out the EEPROM by writing too often).

It's a chip I love so much that I made a breakout of the 3.3V version 47L16 (since I work mainly with 3.3V devices), and a library to support it.

| improve this answer | |
  • +1 I forgot about these myself. It's an excellent suggestion and also something I have been wanting to use. The one downside is still if you are writing to it when the power goes down; then there's still the chance that you get corrupted data. There are also FRAM chips available that require no backup and have effectively unlimited endurance too. Adafruit sells a few of them. – RDragonrydr Feb 12 at 19:08
2

I think the gbg's circuit will fail in many situations. It will cause interrupt only when the power source voltage is quite low. If there is no considerable load before the diode filtering caps of the power source will likely hold enough charge and the "5V" will be falling slowly. Arduino will drain the the backup capacitor before it gets "power bad" interrupt.

Since OP is using 12V power supply a simple brownout detector giving warning when this source drops under some reasonable value (i.e. 9V) is the best way. A Zener diode and transistor (or the optocoupler) should be enough because the value of the threshold is not critical.

| improve this answer | |
  • 1
    I suggest to add an example circuit. – the busybee Feb 8 at 14:46
  • But we can directly connect the optocoupler to the AC mains (with corresponding resistor and diode, of course). And change firmware to detect pulses of 50/60Hz instead of HIGH level – gbg Feb 12 at 19:23
  • Connection to mains makes the circuit more dangerous. OP is a newbie after all. – Jan Drasnar Feb 13 at 20:30
1

I use FRAM for this. It's always write a byte if it was received, much faster and safety. Additionally you can use chain like approach to save data blocks in EEPROM for controlling of the data integrity. Try to use mosfet instead of diode and optocoupler when it powered from battery.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.