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.

Lifetime of a memory

Status
Not open for further replies.

EngIntoHW

Member
Hi,

There are data which I need to change consistently, and would also want that data to be stored in case of a power outage.
Meaning, I need to use the non-volatile memory of the Uc.

However, non-volatile memories have certain amount of writings and readings.

So, how do you take it into account when you want to frequently write data into a non-volatile memory?
 
Reading is unlimited. WRITING is limited. Consider how many times you can write memory vs how often it will be written, and the expected lifetime of the device. Also, the "max writes" is typically a conservative estimate. It would not surprise me if you exceeded that endurance number by several times before encountering a cell that fails to write.

EEPROM space is limited. If your part is capable of self-programming, you can write variables into the program space, but it's risky and limited to block writing only. If there's some sort of glitch you can overwrite an address used for programming and "brick" the part, requiring a programmer to rewrite the original program.

If you have a lot of data which needs to be logged and protected if the power is disconnected, you could get an external EPROM, but nowadays many people just use an external flash card like SD. Those are cheap and huge and a file can be read directly by a computer, rather than having to set up an RS232 data interface and read the raw serial data.
 
You could look into a battery backup (or super cap) for standard volatile memory.
 
Depending on how critical the saved data is, you might want to consider something like the following:

Code:
#define MAX_INDEX 24
#define MAX_STRUCTURES_IN_EE 23
struct ee_data_element
{
   Uint8 index,
   Uint16 data,
   Uint8 checksum,
};

What you would do when you want to read the EE is read from address 0
Calculate checksum of index and data and compare it to the checksum stored in the EE to verify that the data is OK (you are afterall concerned about losing data due to power loss, if you lose power during a write your data may be corrupt)
If data is OK, read the next address
Verify checksum
If data is OK, compare the index of the current read to the index of the previous read. If the index of the current read is not the index of the previous read plus 1, then the previous read is the latest data

When you want to write, perform the above action to find the last valid written data. Increment the index of that data structure by 1, calculate the checksum, and write it to the EEPROM

You need your max EE address to be less than the max index number allowed
You need to account for making your EE address and your structure index to roll-over

This is just a rough idea, may need some fleshing out
 
If you're using a linear regulator my method is pretty easy to do even with only modest electrolytic capacitors, simple add a diode before the regulator (if one isn't already there for regulator saftey) and then just tie the regulators incoming voltage before regulation via a small bypass capacitor and current limit resistor to the micro controller. If you use a properly valued resistor and an I/O line that has clamp diodes then the higher voltage on the I/O line won't be a problem. When power is lost that I/O line will go low so it should immediately trigger a high priority interrupt to write the contents of ram so eeprom and otherwise shut down the chip safely. The diode will prevent the I/O line from reading the voltage from the regulators input capacitor and if you chose a high enough value of capacitor for the input you should get seconds of backup power time as long as you don't have heavy loads on the micro controller itself. If that I/O line asserts itself you could also immediately turn off ALL external peripherals LEDs and things like that to give enough back up time to write the eeprom, it depends on your exact implementation as to if this is practical or not, if you have heavier loads on your micro controller that need to be powered you could go with a couple super caps as power supply hold up caps. They're expensive but you can get hold up times of minutes if you need it depending on the incoming voltage to the regulator.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top