• 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.

reading writing to eeprom

MrDEB

Well-Known Member
I am experimenting reading and writing to a pic eeprom using swordfish but my question is?
when you write to the eeprom then turn off the device will the pic retain the values that were written to the eeprom when the device is turned back on say 1 hour to several weeks?
 

Mickster

Well-Known Member
Most Helpful Member
Yes
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Safely... 10 years... I don't care as I'll be retired well before any of my devices start giving issues...

You just cant write to eeprom too frequently.... We blasted an eeprom for two weeks writing 20 times a second..

The locations did wear out, but even then the retention was over an hour..

(Don't ask!! We had an issue that needed solving.. An elderly developer programmed the device... the memory loss was devastating)...
 

Nigel Goodwin

Super Moderator
Most Helpful Member
I am experimenting reading and writing to a pic eeprom using swordfish but my question is?
when you write to the eeprom then turn off the device will the pic retain the values that were written to the eeprom when the device is turned back on say 1 hour to several weeks?
Yes, that's the whole point of EEPROM - I often use it for configuration settings (such as the LCD contrast setting).

Historically though, in televisions, there has been MASSIVE problems with EEPROM corruption - prior to EEPROM battery backed RAM was used, normally using NiCd batteries. Needless to say the batteries died, and all information was lost - but at least you could replace the battery (nice little earner :D) and reset everything.

So we all thought EEPROM would cure all the problems, but it was even worse - with corruption causing chaos on a wide variety of different makes and models - and unlike the battery backed ones, it's usually impossible to manually reset it. The EEPROM's were 24Cxx series 8 pin devices, so the trick was to build an EEPROM programmer, read the contents of a good set, and store it on your computer - them use that file to restore faulty ones.

As far as I'm aware the internal EEPROM is usually pretty good for reliability?, and you do have to execute a specific sequence to write to it, so that could be the reason why.
 

MrDEB

Well-Known Member
thanks now on to my code snippet that hopefully will work.
THEN inserting a much bigger program
 

Visitor

Active Member
MtDEB, do understand that EEPROM is intended to store information that doesn't change often, like calibration information and setup options. You can READ a EEPROM location as often as you like, but you can only WRITE to an EEPROM location a limited number of times. If you WRITE to a location in the main program loop, you'll rapidly destroy that location. If you WRITE to a location every time the micro is reset (i.e., as part of the program setup), what you're doing probably doesn't make sense.
 

MrDEB

Well-Known Member
ran across an artical about using eeprom and it mentioned lifespan of writing to much. will reconsider
 

MrDEB

Well-Known Member
what got me to consider using the eeprom was in the tetris code from the diy electronics site by Graham Mitchell.
Maybe reconsider but??
 

Nigel Goodwin

Super Moderator
Most Helpful Member
ran across an artical about using eeprom and it mentioned lifespan of writing to much. will reconsider
How often are you wanting to write?.

Assuming an I2C 'EEPROM' is OK you can get pin compatible much superior F-RAM devices, that don't have write limits and are much faster to write to (no write delays required).
 

Visitor

Active Member
what got me to consider using the eeprom was in the tetris code from the diy electronics site by Graham Mitchell.
Maybe reconsider but??
Please explain what you are trying to do – the end goal.

If you are not trying to save configuration info or some kind of calibration info, you're probably headed in the wrong direction at a rapid pace.
 

MrDEB

Well-Known Member
in this case low scores.

this is to be included in my switch/led matrix project but getting nowhere fast but researching how to write and read a value and displaying on an lcd.
here is the timer output that displays the elapsed time. code is work in progress and needs clean up.
Code:
Sub ET_time()
     Timer.Stop //stop timer
        s=DecToStr(ms/1000)+"."+DecToStr((ms Mod 1000)) //this result to be written to eeprom
          WriteAt(1,1,"reaction     ")
          WriteAt(2,1,"seconds   ",s,"     ")
          DelayMS(3000)
     'END SUB
    
          ms=0
          Cls
          DelayMS(1000)
          'repeat
         ' WriteAt(1,1,"press START")
          'WriteAt(2,1,"to play again")
          'until (getkey()=3)
          'DelayMS(2000)
          Cls
    'DelayMS(100)
    'wend       
  End Sub
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Obviously you need to compare the current time with the previous lowest, and only update it if it's lower than the previous one - so the number of writes will be nice and low. So there should be no issues writing to EEPROM that small number of times.
 

MrDEB

Well-Known Member
you win a chocolate cigar mr goodwin!
just trying out different code to get hopefully an idea of what does what.
using the help file and a sf example to try and grasp the workings and how to get the lcd to display from the eeprom the two scores (high and lowest..
am using a code section from the tetris code to hopefully display the ET
Code:
Sub ReadHighScore()//grab the desired score
    Dim tmpByte As Byte           
    Dim LastHighScore As Word
 
    EE.Read(0,tmpByte)
    If tmpByte = $77 Then
        EE.Read(1,LastHighScore)
        ShowScore(LastHighScore)
    Else       
        LastHighScore = 0
        EE.Write(0,$77,LastHighScore)
        ShowScore(LastHighScore)
    EndIf
End Sub
 
Sub WriteHighScore()                 //write desired score to eeprom and display it
    Dim LastHighScore As Word
 
    EE.Read(1,LastHighScore)
    If NumberOfLines > LastHighScore Then
        EE.Write(1,NumberOfLines)
    EndIf
End Sub
this is basically what I am deconstructing to see what the code does.
 

MrDEB

Well-Known Member
Well making very little progress, "three steps forward one step back"
attempting to get the previous score, compare to present score then display on lcd the lowest score to date. This code does not show what the previous score was/is
Code:
  //zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz                           
  Sub Present_Score()
    Dim LastLOWScore As Word
 
    EE.Read(1,LastLOWScore)              //read the eeprom
    If Prev_score < LastLOWscore Then   //COMPARE LOW AND PRESENT SCORE ON EEPROM
        EE.Write(1,Prev_score)
        cls         //write previous lowscore to eeprom
        writeat(1,1,"last score",Prev_score)   //susposed to show what Prev_score is (write to eeprom
        delayms(2000)
    EndIf
End Sub
//read eeprom for lastLOWscore
//if Prev_score is lower than lastLOWscore then Prev_score needs to become lastLOWscore written to eeprom

Sub ReadScore()
    Dim tmpByte As Byte
    Dim LastLOWScore As Word
 
    EE.Read(0,tmpByte)
    If tmpByte = $77 Then
        EE.Read(1,LastLOWScore)      //READ LASTLOWSCORE ON EEPROM
        cls
    WriteAt(1,1,"YOUR SCORE")
    WriteAt(2,1,"SECONDS  ",s,"     " )   //showscore(LastLOWScore)ON LCD
    delayms(2000)
    Else       
        LastlowScore = 0
        EE.Write(0,$77,LastLOWScore)
        WriteAt(1,1,"lOWEST SCORE")
        WriteAt(2,1,DecToStr(Prev_score))    //showscore(LastLOWScore)
    EndIf
End Sub
 

Visitor

Active Member
You forgot at least one thing.

Code:
writeat(1,1,"last score",Prev_score)   //susposed to show what Prev_score is
Should be

Code:
writeat(1,1,"last score",DecToStr(Prev_score))
Seems like a pretty basic thing to forget.
 

Latest threads

EE World Online Articles

Loading

 
Top