Best/cheapest/fewest parts to save uC state and restore it during a power loss.. - Page 1
Forum section: electronics / projects

author: alank2
author_rank: Super Contributor
timestamp: November 25, 2014, 04:19:44 pm
content: Hi Everyone,So assuming you have a 5V project and you want to allow a power loss or dip to not affect it.Obviously you first need a way to detect the power loss before the power is depleted. Could one use a schottky diode to feed the 5V vcc and then use an ADC to sense the voltage of the power before it feeds the diode. You could then see when it drops and shut down any high current items like a lcd backlight, etc. At this point you would have a certain amount of time before power drops below the brownout to try to backup the state so that you can restore it when the power comes back.The AVR has some eeprom on it, but it isn't fast, so my first question is, what type of memory storage might be good to use to store a small amount of state data?Is there any advantage to using a different type of main cap like a super cap?Is there any advantage to making a secondary power rail for only the uC/memory with a diode and capacitor to keep it running?Could this type of process work on just the AVR and NO external memory? It has enough power to keep the AVR alive for 10 minutes for example. After that power is lost, but before that it will remember its state.My goal here is minimal parts count, minimal cost, most bang for the buck.Ideas?Thanks,Alan

author: dannyf
author_rank: Super Contributor
timestamp: November 25, 2014, 04:48:39 pm
content: QuoteWhether it is fast or not doesn't matter. What matters is if it is fast enough.Quoteany sort of memories (flash/eeprom/fram/sram/.....) can be made to work. Whether they work for your particular applications will depend on your applications.

author: Opticalworm
author_rank: Contributor
timestamp: November 26, 2014, 09:22:36 am
content: QuoteFor this type of application speed and low power is key.Your are probably better off using a comparator and a pot detect the voltage level state. Its much faster than ADC and with the pot you can set the trip level. With an ADC, you have to keep sampling to see if the voltage which will reduce the controller reaction time and waste processing time you could use to do other stuff in code.Newer controller have built-in comparators that can trigger an interrupt based on its state and because its interrupt driving you will be able to quickly react to the event. Alternatively you could use an external comparator and simply wire the output to a controller that support interrupt on its Input states.Or:You could use a controller that has a configurable high and low voltage detection modules which are better suited for this type of application. HLVD its essentially a comparator but the voltage reference used is independent to the power IC supply, its stable across the IC temperature range and you can set your trip voltage in software, and its has an interrupt trigger. A quick look at microchip site I found the PIC18F44K20 which has this feature built-inhttp://www.microchip.com/wwwproducts/Devices.aspx?product=PIC18F44K20QuoteIn most cases, people use capacitors as reservoir to give you time to power down safely. But generally speaking the less time you spent saving your data and the lower the power requirement you have the smaller this reservoir capacitor can get away with.Quote10 minutes seem like a long time to keep the controller on to save data. I'm guessing that's not what you want?Quoteusing an EEPROM is possible but are slow, consume quite a bit of current and you have to limit the number of write to the memory.I would suggest using an FRAM solution instead. They are much faster (Almost as fast and RAM), have very low power requirements, and have virtually unlimited amount of write cycle. For example:http://uk.farnell.com/fujitsu/mb85rc04vpnf-g-jne1/fram-4kbit-i2c-sop-8/dp/2429024How about using one of TI FRAM based controller such as the MSP430FR5739IDAR. You will save money from having to buying an external memory, it has built-in comparator, you can reprogram the FRAM in code, and you have the added advantage that the controller power consumption is extremely low. Here a development kit you could usehttp://uk.farnell.com/texas-instruments/msp-exp430fr5739/experimenter-board-for-msp430fr5739/dp/1893308- Ron

author: max_torque
author_rank: Super Contributor
timestamp: November 26, 2014, 11:28:10 am
content: You need to establish some basic numbers before this question can be answered, like:1) How often will "power be lost"2) How long could it be lost for3) How many bytes of data must be "saved" on a power loss4) Are there critical processes that must be "safely" suspended and then restarted on a power loss, and how long might that takeAnswer those^^^ and a solution will be more obvious, be that a back up battery, SuperCap, normal Cap, using the internal eeprom, or some battery backed RAM etc etc

author: alank2
author_rank: Super Contributor
timestamp: November 26, 2014, 01:28:41 pm
content: Quote from: max_torque on November 26, 2014, 11:28:10 am1 - unknown, not that often, but a possibility I'd like to prevent a uC reset from when/if it does.2 - might be a blip like a brownout or 2 or 3 second power outage, might be for longer. I don't need the unit to operate when the power is out, I just want it to not lose its state.3 - Maybe 512 bytes or so.4 - No - just need to shutdown the power consumers like lcd display, lcd backlight, led, etc.Simple is king here, no replaceable battery is also a benefit, but I'd deal with a cr2032 if it provided a tangible benefit such as long term memory retention until the power returned. I guess I see two distinct directions:1. Minimum part cost/number increase for a small period of time to survive a couple of minute power outage without losing its state.2. A cr2032 type solution that would not wear the cr2032 down even if the unit was unplugged for a long period of time.I'm leaning towards the first, but interested in the second...What have CMOS's in PC used all these years? I can turn on a very old notebook and it still remembers its bios settings if the cr2032 isn't dead yet and they last probably as long as the cr2032 is viable because they use so little power from it...

author: paulie
author_rank: Frequent Contributor
timestamp: November 26, 2014, 02:25:02 pm
content: MCUs like AVR have sleep modes that draw picoamps while retaining all normal RAM data. A couple diodes and coin cell is all that's needed to backup for years. Typical internet "experts" will suggest complicated solutions involving exotic costly memory types, complex mosfet circuits, secondary MCUs or supervisors, etc. but in reality none of that is appropriate for the situation you describe.

author: bingo600
author_rank: Super Contributor
timestamp: November 26, 2014, 02:30:22 pm
content: AlanWhat about the I/O Port states , the timers etc. do they have to be restored on "awakening" ?I think a solution instead of saving/restoring the states are as you suggest :Shutdown the powerconsumers , and enter sleep/deepslep mode , that way the contests of ram is still preserved.Maybe use a PSU & CR2032 via a dual schottkey for powering the MCU (See butterfly schematics) , and switch to CR2032 when power is lost. Most AVR's have a comparator (AINx) on them that you could use to generate the IRQ for preparing sleep mode.A "pico AVR" or a MSP430 should last a loooong time in sleep mode , on a CR2032.You might be able to wake up on the comparator IRQ also when power is restored .../BingoEdit: Paulie beat me to it

author: alank2
author_rank: Super Contributor
timestamp: November 26, 2014, 02:35:28 pm
content: Thanks guys, I'll take a look at the butterfly sch

author: paulie
author_rank: Frequent Contributor
timestamp: November 26, 2014, 02:40:12 pm
content: LOL. You gotta be quicker than that Bingo.In fact a 5 cent electrolytic (not super) when properly formed can power a Mega1284 for hours. ADC or comparator is not needed because a regular port bit works here. Cheap diodes like 1n914 are best because schottky reverse leakage will drag things down fast.