Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Saving variable content to EEPROM before power is cut-off

Status
Not open for further replies.

emavil

Member level 2
Joined
Oct 18, 2005
Messages
53
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,738
avr save date before power loss

anybody who has an idea on how to save variable value to EEPROM before power is lost? I'm using PIC16F628A with internal RC osc enabled.
 

save eeprom power down

You need to detect moment when voltage on voltage regulator input begins to fall. Use controller's internal ADC or comparator - connect its input to input voltage through resistive divider. And use input filtering capacitor with capacitance enough to supply microcontroller while saving data to EEPROM
 

power saving eeprom

umup said:
You need to detect moment when voltage on voltage regulator input begins to fall. Use controller's internal ADC or comparator - connect its input to input voltage through resistive divider. And use input filtering capacitor with capacitance enough to supply microcontroller while saving data to EEPROM

Yea, that will work but only if you separate the processor supply from general board supply with a diode (Schottky of 0.2V drop would be best) to prevent discharging the capacitor supplying PIC by the rest of the circuit. And you should supply the EEPROM from processor supply, or some port pin.
 

write variable to eeprom

janni8 Yes, diode needed if there are some high power components besides controller, but emavil said nothing about it

I used this configuration (with Atmega8, internal reference 1.23V, so comparator detected voltage fall below 11V) :
35_1170512239.png
 

Re: Saving variable content to EEPROM before power is cut-of

There are a few other points to consider after detecting the upcoming power loss:
1. According to Microchip DS40044E-Page 139, Tdew, Data EEPROM Erase/Write cycle time, Typical is 4 ms. Which depending on your power circuit may not be enough time.
2. The 4ms may be per byte, so consider total data length.
3. The 4ms requires that Vmin is maintained during write.
4. If circuit does not allow enough time for your writes, consider using the LF version of the chip.
5. Use a I/O pin to determine the real-world time for the write.
6. If power is maintained long enough, consider writing the same data 2 or 3 times at different address, and compare the results at restart for validity.
7. Depending on what eeprom_write code is being used, be aware that interrupts may be disabled during the actual write.

Hope some of these pointers help you.
 

Re: Saving variable content to EEPROM before power is cut-of

I agree, you need to detect when the power fail.
for that I can recomend a way of doing:
- Conect the voltage supply to the base of a transistor and conect it to the external interrupt port, use a battery backup pack (just a few mA) save the variable to EEPROM, then go to sleep, when the power is restore the instrument wake up.

Hope that helps.
 

Re: Saving variable content to EEPROM before power is cut-of

A software solution.
This may not apply to your application.

In some applications a periodic update of the EEPROM can be used instead of saving the data on powerfailure. To do this you need to understand the nature of the data.

Some applications do not require that EEPROM have exact informaton. As long as the current value and that stored in the EEPROM are "close enough" there is no need to change the EEPROM value.

If you are saving a count or quanity it may be ok to save the value every n counts. It depends on how much error is acceptable.

The datasheet lists the EEPROM as good for 1 million write cycles.
If you saved you data every minute the EEPROM would only last about two years.
If the application only requires 1/4 of EEPROM that could be extended to 8 years

The upside is this requires no additional circuitry. Less cost and hardware complexity. Another bonus is that you have valid stored data at all times. Should the processor crash for whatever reason it comes up with valid data.

The downside is that software complexity goes up and in time it may wear out the EEPROM.

Edit:

After I posted I found a Microchip Appnote AN601
https://ww1.microchip.com/downloads/en/AppNotes/00601.pdf

As will be described in more detail later, if the designer
has any control over certain environmental or operation
conditions he should observe the following basic
guidelines:
• Keep the application temperature as low as
possible
• Keep the application voltage (or the V
CC
voltage
on the EEPROM-based device) as low as
possible
• Write as few bytes as possible
• Use page write features wherever possible
• Write data as infrequently as possible
With these basic guidelines applied to the fullest
extent, the endurance of EEPROM-based devices can
be extended well beyond the guaranteed minimum
endurance. Under certain very specific conditions,
Microchip Serial EEPROMs have been shown to last
for well over 100 million cycles.

3v0
 

3v0
What if power drops down in the process of EEPROM writing. Data will be invalid...
 

In microprocessor terms, the voltage usually takes a few milliseconds to drop a few volts. If you are using a reasonably big capacitor, you will have a few tens of milliseconds. If you can generate an interrupt as the voltage starts to fall, you can easily store the data in EEPROM and give it about 10ms to complete its internal write time.
 

techie
with input capacitor that is big enough (> 1000uF) and separation of power hungry components from MCU supply power can last several seconds, it is enough even for slow AVR internal eeprom, for faster backup better use paged external eeprom
 

Re: Saving variable content to EEPROM before power is cut-of

One more thought, otherwise some of the others ideeas are very good.
1. use a supercap instead of an 1000uF capacitor
2. store variables as RAM pages and write a whole page if you're using an external eeprom, this will save time
3. use a LF microcontroler backup powered at 3V coin cell and you don't need this anymore
 

Supercap or ram pages are not required. New external eeproms are cheap and have 64 to 256byte pages. Moving distributed RAM variables to the EEPROM takes a few milliseconds only on a decent 8-bit controller. YOu can easily move dozens of bytes to serial eeprom and give it the 10ms write time and do that with a 1000uf cap as long as you turn off the power hungry components off as soon as you get the warning interrupt.
 

janni8 i think ur method is very perfect, can you please suggest some common Schottky diode part number. Thanks

With regards,
Garg
 

Re: Saving variable content to EEPROM before power is cut-of

umup said:
3v0
What if power drops down in the process of EEPROM writing. Data will be invalid...
This can be handled and it extends the EEPROM life too. Keep two or more copies of data in EEPROM. When an update is done it overwrites the oldest copy. An update is handled like a database transaction. The last thing you write is a marker that indicates it is valid.

To ensure that the stored data is useful save a new copy when the difference between the working value and the stored value is half the tolerance.

3v0

PS: Recall that I did not claim this would work in every application. I just wanted to point out that for some cases a software solution exists.

Everything is a trade off.
 

The definition of a real-time system lies in its predictability. Why would the voltage drop before the EEPROM write is completed if your design is not faulty.
 

Re: Saving variable content to EEPROM before power is cut-of

Don't forget to turn off all devices that are no necessary to write to EEPROM when power fail is detected (by an interrupt can be), by example LEDs, LCD, External Devices, etc.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top