Continue to Site

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.

  • 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

Status
Not open for further replies.

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?
 
Yes
 
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)...
 
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.
 
thanks now on to my code snippet that hopefully will work.
THEN inserting a much bigger program
 
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.
 
ran across an artical about using eeprom and it mentioned lifespan of writing to much. will reconsider
 
what got me to consider using the eeprom was in the tetris code from the diy electronics site by Graham Mitchell.
Maybe reconsider but??
 
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).
 
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.
 
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
 
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.
 
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.
 
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
 
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top