Author Topic: prevent EEPROM corruption when battery runs out  (Read 3094 times)

0 Members and 1 Guest are viewing this topic.

Offline curiousZombieTopic starter

  • Newbie
  • Posts: 1
  • Country: us
prevent EEPROM corruption when battery runs out
« on: December 08, 2016, 02:28:05 am »
Hi all, first post --- be gentle  ;)

I have a project where a PIC12F1840 with some LEDs are powered by 2 coin cell CR2032 batteries. I'm gathering data and storing to EEPROM every minute. The device will eventually run out of batteries and I notice the EEPROM data often gets corrupted, I'm guessing the voltage gets too low during an EEPROM write.

Is there a graceful way to stop EEPROM writing before the power gets too low?

The challenge is that I've exhausted all I/O pins for digital input and output so hardware modification is not an option, I need a reliable software routine that stops EEPROM writes when the battery is about run out (battery mileage may vary so a set timer isn't suitable).

Any expertise in this matter would be much appreciated.

Thank you
 

Offline Gixy

  • Regular Contributor
  • *
  • Posts: 232
  • Country: fr
Re: prevent EEPROM corruption when battery runs out
« Reply #1 on: December 08, 2016, 06:35:09 am »
Each time you have to write data, first write dummy data and read them back. If ok then write real data, if not battery is low. Not 100% safe but should lower the problem.
 

Offline obiwanjacobi

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: prevent EEPROM corruption when battery runs out
« Reply #2 on: December 08, 2016, 07:00:59 am »
- backup a last known good config
- CRC checks over records (parts) or the whole configuration
- two phase commit (like Gixy said) - but not with dummy data. Write the real data and set a flag for temp/phase 1. Read back and clear flag if ok. If you read data with this flag set, you know its going downhill. Use the backup value instead. This will wear down your EEPROM twice as fast (2 writes).

[2c]
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline lwatts666

  • Supporter
  • ****
  • Posts: 76
  • Country: au
Re: prevent EEPROM corruption when battery runs out
« Reply #3 on: December 08, 2016, 09:05:07 am »
The easy approach for the PIC12F1840 is to use the programmable brown-out-reset. This will hold the chip in reset when the supply voltage falls below the programmed limit.
 

Offline tszaboo

  • Super Contributor
  • ***
  • Posts: 7307
  • Country: nl
  • Current job: ATEX product design
Re: prevent EEPROM corruption when battery runs out
« Reply #4 on: December 08, 2016, 09:08:44 am »
The PIC works down to 1.8V. Set up a brownout reset. Also, some EEPROMs will work down to 1.5V, change to one like that.
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3452
  • Country: it
Re: prevent EEPROM corruption when battery runs out
« Reply #5 on: December 08, 2016, 09:38:15 am »
you could also add a bigger bypass cap in parallel with the usual 100n ones so the voltage will sag slower during eepom writing
then once in a while you could read vdd and determine if batteries are depleted (hint: read the FVR value. that's what i do in these situations)
 

Offline TheDane

  • Regular Contributor
  • *
  • Posts: 209
  • Country: dk
Re: prevent EEPROM corruption when battery runs out
« Reply #6 on: December 08, 2016, 09:56:27 pm »
It might be possible to read out the supply voltage, without a hardware modification.

According to the datasheet, under the ADC section the following is stated:
16.1.3 ADC VOLTAGE REFERENCE
The  ADPREF  bits  of  the  ADCON1  register  provides control  of  the  positive  voltage  reference.  The  positive voltage reference can be:
• VREF + pin
• VDD
•  FVR 2.048V
•  FVR 4.096V (Not available on LF devices)
See  Section 14.0 “Fixed Voltage Reference (FVR)” for more details on the fixed voltage reference

- so measuring the VDD and a Fixed Voltage Reference (and possibly doing some scaling/comparing if the 2.048FVR drops as well) it might give you an idea software wise, when to stop (or slow down) writing to the EEprom.
I have not worked that much with PIC's, so I don't know if it interferes with some of the GPIO pins while sampling VDD/FVR 'registers'.
 

Online wraper

  • Supporter
  • ****
  • Posts: 16796
  • Country: lv
Re: prevent EEPROM corruption when battery runs out
« Reply #7 on: December 08, 2016, 10:04:59 pm »
Each time you have to write data, first write dummy data and read them back. If ok then write real data, if not battery is low. Not 100% safe but should lower the problem.
Not even remotely safe at all and will wear out EEPROM twice as fast. Another issue is that when you write something at low voltage, it's not guaranteed that write will occur even at the correct address. You may just corrupt some other data.
 

Online wraper

  • Supporter
  • ****
  • Posts: 16796
  • Country: lv
Re: prevent EEPROM corruption when battery runs out
« Reply #8 on: December 08, 2016, 10:17:20 pm »
Set brown-out reset (2.4 or 2.7 V). If you are using internal EEPROM, use CODE-PROTECT against accidental writes (in 11.2 chapter in the datasheet). You can also use combination of DAC with ADC or comparator for detecting the power voltage without utilizing any pins.
 

Online wraper

  • Supporter
  • ****
  • Posts: 16796
  • Country: lv
Re: prevent EEPROM corruption when battery runs out
« Reply #9 on: December 08, 2016, 10:31:14 pm »
Silabs EFM8UB10 MCUs I work with, unless internal voltage monitor is enabled, won't even try writing into the FLASH (they have area with small page size instead of EEPROM). And MCU will just reset if try doing so. I recall woes about "unreliable" EEPROM in AVR MCUs (people too stupid to enable brown-out detect) and using external EEPROM ICs instead.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf