Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to store variable values when power is down in PIC

Status
Not open for further replies.

GreenBeret

New Member
I am writing a count down timer using PIC. I want to store the last set time to a permenant storage so that even after restart i want to get the last set time. How can i do this?
 
The simple answer is in the EEPROM. Chose a PIC with EEPROM in it and store any data you want.

However, there is a significant problem with that. The EEPROM can only be written to a limited number of times, maybe 1 million times. If you store time every second, you would wear the EEPROM out after two weeks running. What you have to do is store the time only when the power is failing. You have to detect loss of power, but still have enough power remaining to run the PIC for long enough to store what readings you need in EEPROM.

Alternatively you can have a small battery or a big capacitor to keep the PIC going. When you loose power, put the PIC into sleep mode, and wake it when power is restored. Power consumption in sleep mode is virtually nothing, and all the values in RAM are kept.
 
You can use a circular buffer too in order to increase the number of times you can write to EEPROM. However, I'm with Diver, I think it is better to write to EEPROM only when you need to do so.
 
+1 to Diver300's response. Both options are possible, each with the issues he stated.

One more note, writing to EEPROM to make things available if power goes down is touchy. IF the power goes out WHILE the EEPROM is being written, then we don't know what'll be stored. In fact it's somewhat uncertain that it won't write and corrupt a completely different EEPROM location.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top