Maker Pro
Maker Pro

EEPROM data corruption Atmega32a

BHARGAV SHANKHALPARA

Nov 6, 2013
35
Joined
Nov 6, 2013
Messages
35
Hello all...!!

I am making one application in which i am controlling two motors, there are too many measurements, current measurement of all 3 phase using CT and other things...!! I am using internal EEPROM of ATMEGA32A to store data.

My problem is..

When i restart my circuit many time, its internal EEPROM data corrupt. I enable Brownout reset after reading ATMEGA32A datasheet. I choose 4V for brown out reset. But than after my EEPROM data is corrupted.

I use external crystal of 16MHz with 22pf capacitor for better timing accuracy.

But when i choose internal oscillator at 8MHz from fuse bit setting , and then restart circuit many times but EEPROM data is safe.

No problem at all...!!

Please suggest what is problem with external crystal and internal EEPROM data...?

Thank you.
 
Last edited by a moderator:

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Chances are that a write cycle hasn't completed when power was turned off. Also, EEPROM has a limited nmber of write cycles before it will wear out. It is very different from SRAm in that respect.

Also timing is important. Check and verify your EEPROM write routines that they work correctly at the frquency of the external quartz. In case you use C for programming the Atmega, a typical set of statements at the beginning of the code is this:
Code:
#ifndef F_CPU
#define F_CPU xxxxxxxxxxxUL   //xxxxxxxxxxx = CPU frequency in hertz
#endif

Possibly a technique using double buffering and a buffer arranged in circular order may help. The idea is to use different EEPROM addresses at each write cycle for storing the same variable. After writing you verify the correct contents of the new address and then advance a pointer to point to th enew address. Therefore, if writing the new data fails, you still have valid data at the old EEPROM address and the old pointer will still point to that address.
If update of the pointer fails, you can still use the old pointer and the old data. You lose at most the most recently written data.
See here for more details.
 
Top