Continue to Site

Welcome to

Welcome to our site! 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.

write the data in ram of mcu into eeprom when power outage

Not open for further replies.


Junior Member level 2
Jan 2, 2006
Reaction score
Trophy points
Activity points
hello everybody, my name is narender, a final year degree.

iam doing my project on pre piad energy meter. i am facing a trouble with the design. brief about my project. there will be an energy meter ic which wil be converting the instantaneeous load into pulses and a microcontroller which will be counting those pulses and when ever the count becomes 1500 pulses then some counter is incremented and is written into the serisl eeprom chip. now when ever the counter is just to less than 1500 pulses and there is a power outage, then all the ram contents are lost. i,e a total of 1 kwh is lost. so for this i have to design a power back up unit(from batery) which will detect a power outage and swith on very quickly whenever there is power outage and i will write a interrup service routine to write the contents of the counter into the serial eeprom and after that my back up(from battery) unit also should shut down. and on power resumption i should take the values from the serial eeprom and then start counting from there.

how can this be done, a non volatile ram is not an economical one so i cant go for it. can anyone help me with some other low cost circuit and get my purpose solved.

sorry for my english.

thanks in advance.

u can use serial eeprom from atmel, it is AT24c02 u need only three pin SDA,SDC, and gnd to interface it. dowload datasheet from there and code too, from, if u have any problem post here.

maybe you can refer to this thread created by me:

the question i raised in the thread is similar to yours..

Re: write the data in ram of mcu into eeprom when power outa

iam using at at24c04 ic , it is not the problem with the eeprom its the problem with the power back up for say 15 seconds.

Added after 36 minutes:

hello banh,
i have seen the post u mentioned, its quite educational, can you give me the final circuit which you used for your application.


Added after 36 minutes:

but i think battery will become bulky for my application,
how much size will a 9 volts NiMH battery be. and what will be its size.
i just want back up for vey small time less than a minute. the battery capacity (AH)should be very small.
i think lead acid battery will not suit my application(wall hanging energy meter).

is there any other battery which will be small in size and provide me 9 volts .


thank you

if ur controller can work on 3V u can use a 3V battery which is used in motherboard.
or a 3.6V used with cordless phone they are small in size.

Re: write the data in ram of mcu into eeprom when power outa

Hi, this may not help much, but have you thought about capacitors?

I mean the 1-5F ones. Their capacity rivals that of batteries, but you can charge them very quickly. Memory backup caps are cheap now, and last for about 3 years from full charge.

Hope this helps. The cap in the link is a big one, You can get tiny ones the size of a few button cells.


Re: write the data in ram of mcu into eeprom when power outa

hi , my circuit uses the atmel 89s52 microcontroller, i am not sure but the controller will reset itself if the voltage drops below 4 volts.

so i cant use 3 volts. i can use 3 compuiter motherboard cells in series, but how ling will they last i will be drawing power only until i write a byte of data into the eeprom and the total load on battery comprises of microcontroler, serial eeprom at24c04, lcd with back light, max 232, 2 led's. but all i need is not more than a maximum of 30 seconds in the worst case.

how much does the super capacitors cost and where in india (hyderabad) can i get them , will they supply power for the above laod for a minimum of 25 sefconds.

how much does the cells in computer cost how long wil they last for the above load.

thank you

15 seconds????? How much data are you writing??? From your earlier description, I would have guessed just a few bytes. Saving that can be accomplished in milliseconds. Have you actually measured save time?

I would put more thought into how you detect power-out in the fastest possible way. Do that as far upstream as possible. Don't wait for your filter caps to drop. Then beef up the power supply to give you the time you need.

At the worst case, use a p-mosfet to feed the non-critical components and turn it off when you see power fail. This will conserve power for the critical components (uC and eeprom).

Re: write the data in ram of mcu into eeprom when power outa

its not 25 or 30 seconds, its a matter if i think a max of 2 seconds.. my circuit is already soldered on the pcb i cant have mosfets to switch the power off to other devices. so i have to supply the other devices also. i just need to detect and save few bytes and then switch of fthe battery supply also.

i think i dont need a rechargable battery , does the batteries used on computer motherboards last long atleast for 1 or 2 years if they are only used when there is a power outage.

I'll repeat it, you need to measure how long the save takes. guessing is, well, amatuerish. Measure your current draw. Figure out the size of the problem. Use a scientific approach.

To bad you didn't understand the problem before building the circuit.

Re: write the data in ram of mcu into eeprom when power outa

hi , can u tell me how to measure the time exactly required for writing into the eeprom

sigh. doesn't anyone figure stuff out for themselves anymore?

well, you can read code and count clocks. assuming you have datasheets that show timing.

do you have an o'scope? put the code that does it in a loop amd toggle a pin high and then low at the top of the loop. look at the pin with the scope. measure time between pulses.

do you have a stopwatch? put the store code in a loop for say 1000 iterations. toggle a pin before the start of the loop, toggle it again at the end. put the whole thing in an infinite loop. use a dvm to watch the pin and use a stop watch to measure the high or low period. you may need to tweak up or down the number of itterations. if you have a free pin, you could jury-rig up an LED for visual indication.

if you have an emulator, count trace buffer clocks.

Dont update the data for every 1500 pulses you update it for lesser pulses like 100 or 50 etc so that the count loss due to power failure will be minimum.

Not open for further replies.

Part and Inventory Search

Welcome to