News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Contiguous EEPROM corruption

Started by shantanu@india, Feb 01, 2025, 06:55 AM

Previous topic - Next topic

shantanu@india

Hi,
Faced a strange issue today. A particular EEPROM address is getting cleared after power recycling.

Some snippets would give an idea....
'Pin definitions
Symbol OpenWrite  PORTA.4
Symbol CloseWrite PORTA.3
'.......................
'EEPROM record address
OpenLimSave EData Word 6450
SetValveSave EData Word 0
CloseLimSave EData Word 3212
'.............................
'Loading the values at initialization
OpenWritten=0
CloseWritten=0
OpenLim = ERead OpenLimSave
CloseLim = ERead CloseLimSave
...............................
'The values are written only once. To rewrite power have to be recycled
record:
    If OpenWrite=1 And OpenWritten=0 Then
       OpenLim=ADCValAvg
       INTCON.7=0
       EWrite OpenLimSave ,[ADCValAvg]   
       INTCON.7=1
       OpenWritten=1
    EndIf
   
    If CloseWrite=1 And CloseWritten=0 Then
       CloseLim=ADCValAvg
       INTCON.7=0
       EWrite CloseLimSave ,[ADCValAvg]   
       INTCON.7=1
       CloseWritten=1
    EndIf
    Return

In the above code structure if I put OpenLimitSave & CloseLimitSave at consecutive EEPROM locations then after power recycling the CloseLimitSave invariably becomes zero. Only way seems to interpose a redundant SetValveSave between the two.
Regards
Shantanu

trastikata

Hello shantanu,

just for the test instead of writing a Word to the EEPROM, try writing the Word as two Bytes with a delay of 7ms between EEPROM writes.