5

Before I get to the question, let me give you some background info.

I'm trying to make a digitally controlled power supply. I'm going to use an MCP4725 DAC to set the reference voltage for the power supply. The DAC will be controlled by an STM32 Blue Pill development board.

When I turn the PSU off, I want to store the last set output voltage in the DAC's EEPROM so that when I turn the PSU on again, it will output the same voltage as it was before I turned it off.

When I was going through this article about the DAC, I came across this statement:

You shouldn't set the flag to true unless you require it as it will take longer to do, and you could wear out the EEPROM if you write it over 20,000 times.

I went through the datasheet of the DAC twice and I did not find the above statement anywhere (Sections 5.6 and 8.2 of the datasheet talk about the DAC's EEPROM).

My questions are:

  • Why does Adafruit say that the DAC's EEPROM will wear out after 20,000 write operations when there is no mention of such a thing in the DAC's datasheet?
  • What do they mean by "wear out"? Will the EEPROM circuit get damaged or can it not store more than 20,000 voltage values?
  • How do I erase the EEPROM so that it doesn't wear out (if running out of memory is what "wears it out")?
  • 2
    use the non-save call to set the voltage, then wait a few seconds and set it again with save, to the same value for persistence and wear-avoidance. This avoids writing 50 values as you dial up and decide on an output. – dandavis Aug 10 '21 at 05:01
  • 1
    @JRE you made this correction: What do they mean by "wear out"ou?". According to [this](https://www.ultimateproofreader.co.uk/blog/placing-full-stop-correctly-in-academic-writing) website, when the stuff in the quotation marks isn't a stand-alone sentence, the full stop (can extrapolate to question mark too, I suppose), should be outside the quotation marks. – Prathik Prashanth Aug 10 '21 at 11:18
  • @PrathikPrashanth: Difference between US English and UK English. I wouldn't just change from UK to US - both are valid. If I have to fix other things, though, I change everything to the standard I was taught in school. – JRE Aug 10 '21 at 11:22
  • @PrathikPrashanth I agree with you. The stuff inside the quotation marks in not a quoted question, so it doesn't read properly to put the question mark inside those quotes. It would be different if the quotation marks surrounded a complete sentence that was a question. – Elliot Alderson Aug 10 '21 at 12:09
  • @ElliotAlderson even the question mark inside the brackets should be moved back out, if I'm not wrong - How do I erase the EEPROM so that it doesn't wear out (if running out of memory is what "wears it out"?) – Prathik Prashanth Aug 10 '21 at 12:27
  • ~20,000 cycles at one cycle per day is 60 years. How much longevity do you need? – Joshua Aug 10 '21 at 16:29
  • @PrathikPrashanth Yes, I see your point there. You can edit the question if you want. – Elliot Alderson Aug 10 '21 at 19:26
  • @Joshua ideally infinite. When you know that something can wear out after a finite number of cycles, you worry. Or I worry, at least. But that wasn't why I asked the question. I asked to question to find out what adafruit meant by "The DAC will wear out after 20k write operations". – Prathik Prashanth Aug 11 '21 at 09:08

2 Answers2

9

All EEPROMS have a finite write cycle endurance (all FLASH memory too). There are more exotic forms of non-volatile memory (MRAM, FRAM, or simply battery-backed RAM) that have infinite write endurance but most "normal" non-volatile memory will wear out over a certain number of write cycles. This spec is commonly 100,000 cycles or 1 million cycles for regular EEPROM parts. As @jpa pointed out, this datasheet does specify a write endurance of 1 million cycles, so it's pretty standard.

It's always important to note that the write endurance specification presumes "normal" writes with adequate time from one write to the next. If you perform a large number of writes rapidly (for example, when developing code it's common to have a bug where the code accidentally enters a small write-loop), then the part will fail much sooner than its spec. (This, along with operating at temperatures different from the nominal 25°C, might by why Adafruit published the much more conservative estimate of 20k cycles, but I'm just guessing here.)

So, regarding your questions:

  1. As @jpa pointed out, there is in fact a mention, so no issue here.
  2. When the part "wears out" it will no longer reliably hold the value you wrote to it. If you're lucky (and or the part is thoroughly worn out), you'll end up with "stuck bits" that always sit at a 1 value or a 0 value. If you're unlucky or the part is just starting to fail, you'll have a value that looks correct when you write it, but later on the voltage (and bit reading) have drifted back to the wrong value. No fun.
  3. The EEPROM gets worn out by writing values to it, so there's no way to avoid this problem except avoiding writing to the EEPROM.

Just figure out a scheme that writes to EEPROM as infrequently as possible, while still meeting your non-volatile storage needs. And then do a bit of math to estimate your expected EEPROM lifetime.

Mr. Snrub
  • 2,513
  • 8
  • 11
  • 4
    Regarding 1.: the datasheet *does* mention EEPROM endurance (as 1 million write cycles), even though OP didn't notice it. I have no idea where Adafruit's 20 000 comes from. No vendor mistake as far as I can tell. – jpa Aug 10 '21 at 13:59
  • 1
    @jpa I found it now. It was in the electrical characteristics table under the name "endurance". I thought I would find it in a paragraph. – Prathik Prashanth Aug 10 '21 at 15:03
  • 1
    @jpa well noted (as you've probably guessed I just took OP's word for it and didn't review the datasheet myself). I've corrected to reflect this. – Mr. Snrub Aug 11 '21 at 01:42
7

We don't know why Adafruit says that. You should ask them about it.

The datasheet says the EEPROM endurance at room temperature is 1 million write cycles.

The EEPROM does wear out. It gets a small amount of damage each time it is written, as internally it erases the cells and reprograms them. It's not about getting full, and you can't erase it or do anything about it.

After enough erase/write cycles, it is damaged enough to not hold the written value for the specified time. So if it typically can hold the value for 200 years, after 1 million writes the time can be lower, but there is no guarantee how many years it is. Given enough writes, it might not hold the written value at all.

The only thing you can do is to not write it. If you store to the EEPROM, it can take up to 50 milliseconds, meaning the update rate can be as low as 20 writes per second.

It might be better to store the value somewhere else or maybe only at power off.

Justme
  • 127,425
  • 3
  • 97
  • 261
  • Yea, I only want to store a value during power off. Is it possible to store the set value in the STM32 itself and restore it later? – Prathik Prashanth Aug 10 '21 at 05:55
  • Of course it is **possible** for sure. Whether or not you want to do it and in which way, that it is another thing. – Justme Aug 10 '21 at 05:58
  • Storing the set voltage in the STM32 itself before powering down the PSU sounds better. Share it with me if you have the link to a program that can store and retrieve values from the memory. – Prathik Prashanth Aug 10 '21 at 06:20
  • It will be good if someone can explain why this little 'damage' occurs in a typical flash memory write operation. – Mitu Raj Aug 10 '21 at 06:37
  • I read in the comments section of [this video](https://www.youtube.com/watch?v=BKgh896Bj8Q&ab_channel=ControllersTech) that the STM32's flash has a write endurance of 1k to 10k write operations. So it looks like it's better if I avoid using the flash/eeprom. – Prathik Prashanth Aug 10 '21 at 07:03
  • 4
    @MituRaj the mechanism is different in EEPROM and Flash types. Erase and program cycles apply large voltage fields to tunnel electrons in or out a floating gate, and after many cycles less and less electrons will move and voltage differential becomes too small to determine if it is a logic 1 or 0. The oxide that insulates the floating gate can also deteriorate and start leaking electrons so the floating gate does not hold the charge that was transferred to it. – Justme Aug 10 '21 at 07:08
  • 2
    @PrathikPrashanth No that is not true either - it is not 10k write operations, it's 10k erase operations. Obviously you would use a smart wear leveling algorithm that fills a whole page before erasing. You could also use the battery backup SRAM for storing voltages, as it's just SRAM. – Justme Aug 10 '21 at 07:17
  • @PrathikPrashanth storing in flash is a much worse option than storing in EEPROM. To store one byte in flash a whole flash page has to be erased, which will probably decrease your system's lifetime by a lot. – Sim Son Aug 10 '21 at 08:51
  • 2
    @SimSon That is not true and I already explained how it is done. Of course erasing a block just because you want to write one byte would be a bad way to do it. – Justme Aug 10 '21 at 09:02
  • 1
    It looks like storing the set voltage value in the DAC during power down is probable the best idea since the DAC can endure 20,000 - 1,000,000 write operations. – Prathik Prashanth Aug 10 '21 at 11:07
  • @Justme I agree that the key point in such a case is to choose *when* to store values carefully. I don't agree that using a different storage medium makes much sense: if implemented like you wrote, even 20k write cycles would be sufficient. The internal storage is there any way, it has "automatic initialization" already, flash on the other side is even more limited (flash pages, wear-leveling required) and the endurance is practically not a problem - you said it. So I see no good reason why the OP shouldn't use the internal EEPROM. I felt like that's what the OP concluded... – Sim Son Aug 10 '21 at 14:44