Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : [MMBasic] How I destroyed my poor EEPROM
Author | Message | ||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1133 |
Hi all! I wanted just to know how many write cycles I can do with a AT24C32 (on my DS3231 RTC-modules). Atmel says in his datasheet we can expect 1 million writes: But I wanted to have the confirmation and I had some spare DS1307 modules with AT24C32 (32kBit) EEPROM. Therefore I wrote a little basic code to check ... and destroy my poor little EEPROM. It takes about 1.5 hours for 1 million cycles. All code without any warranty on your own risk! '********************************* ' ENDURANCE TEST ' WILL DESTROY YOUR EEPROM! ' MM-Basic 4.5 / Maximite/Duinomite ' by twofingers 21-08-2014 on TBS '********************************** Dim t(2) I2CADDR=&H50 `for 24C32 on DS1307 module from china dest=4000 K$=Chr$(255) t(0)=0 t(1)=255 Print Time$, Date$, "Destination:"dest Timer=0:av=0 For i = 1 To 10000000 av=Abs(av=0) Print @(0,12) i eeSaveFx(I2CADDR,dest,t(av)) Next i Print i,Time$,Timer 'eeDump End '********************************** ' Saves 4 identical bytes to AT24C32 ' TO DESTROY EEPROMS ONLY! ' address should be divisible ' by 4 without rest ' (page mode roll over trouble) '********************************** Sub eeSaveFx (i2caddr,address, v) 'Print i2caddr, address,v Local i,v1,MSB,LSB I2C open 100,100 'ENABLE I2C MSB=Int(address/256) 'MSB LSB=address Mod 256 'LSB I2C write I2CADDR, 0, 6, MSB,LSB,v,v,v,v If MM.I2C <>0 Then Print "Error(1)! 1=NAK 2=TIMEOUT"; MM.I2C: End Pause 1 'verify I2C write I2CADDR,0,2,MSB,LSB ' set read address For i=2 To 5 I2C read I2CADDR,0,1,v1 If MM.I2C <>0 Then Print "Error(2)! 1=NAK 2=TIMEOUT"; MM.I2C: End If v<>v1 Then Print "Verify error at"; address,i,v,v1,"timer"Timer:End Next i I2C close End Sub '********************************** ' Saves a floatingp. var to AT24C32 ' ' address should be divisible ' by 4 without rest ' (page mode roll over trouble) ' Plz obey mmbasic limits for ' floating point numbers otherwise ' U will get a serious memory error! '********************************** Sub eeSaveF4 (i2caddr,address, v) Local fill(6),i,v1 If address Mod 4 Then Print "Error: address should be divisible without rest" End EndIf I2C open 100,100 'ENABLE I2C fill(0)=Int(address/256) 'MSB fill(1)=address Mod 256 'LSB For i = 0 To 3: fill(i+2)=Peek(VAR v,i):Next i I2C write I2CADDR, 0, 6, fill(0) If MM.I2C <>0 Then Print "Error(1)! 1=NAK 2=TIMEOUT"; MM.I2C: End Pause 1 'verify I2C write I2CADDR,0,2,fill(0) ' set read address For i=2 To 5 I2C read I2CADDR,0,1,fill(i) If MM.I2C <>0 Then Print "Error(2)! 1=NAK 2=TIMEOUT"; MM.I2C: End Poke VAR v1,i-2, fill(i) Next i If v<>v1 Then Print "Verify error! at"; address,v,v1:End I2C close End Sub Results: I did this test 4 times at different addresses. After about 3.6 million cycles some bits (out of 32) could not be written correctly. 4008 - 3.6119e+06 4012 - 3.63517e+06 The code for eeSaveF4 is an improvement for my old EEPROM-LIB. Based on this testing, I think it's a good idea to check all bytes written. Seems more "professional". Conclusion: I think we can trust Atmels datasheet (1 Millon Write Cycles) ************************************************************ *********** I2C-Scanner: Sometimes we get some I2C modules without a manual or datasheet. To find out how the I2C-address for a unknown device is I use the following code (all public domain). It's primitive but working. In some cases, we will get two or more valid addresses, then we have to try. Its usefull not only for I2C-EEPROMs but also for all other I2C devises. '********************************** ' I2C-Scanner ' scans I2C-Bus for addresses ' MM-Basic 4.5 / Maximite/Duinomite ' by twofingers 21-08-2014 on TBS '********************************** found=0 Cls Print "I2C-Scanner from Adr. 8-119":Print:Print For i = &h08 To &h77 ' gueltige I2C-Adressen von 8-119 I2C open 100, 1000 ' i2c enable 100kHz, 1000ms timeout I2C read i, 0, 1, temp Print i;">"; MM.I2C " "; If MM.I2C = 0 Then Print:Print:Print "Found I2C-Address at "; i; " ("dec2hex$(i)+")" found=1 EndIf I2C close ' i2c disable Next i If found = 0 Then Print:Print:Print "NO I2C-Addresse found!" End Function dec2hex$(number) dec2hex$ = "&H"+ Hex$(number) End Function In the next days there will be a new version of EEPROM lib. Michael |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2289 |
if you give the EEPROMs a good shake for 10 minutes, then leave them in a warm dry place (linen cupboard) overnight, you should be able to get a few hundred thousand more cycles out of them without any troubles. rob :-) |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1133 |
Thanks for the suggestion! I'm sure this would help! Michael |
||||
WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2794 |
Come on folks - why don't you start using FRAM? It has got virtually limitless write cycles, behaves like FLASH memory, and the only drawback is that it does cost a tad more than standard flash chips. For high frequency data logging they are brilliant. For everything Micromite visit micromite.org Direct Email: whitewizzard@micromite.o |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Hi @Twofingers, Just thought I'd give this a try on the E64 to see the results. Had no intention of running it for hours. Just want to look for a timing issue. Only changed the address of the AT24C32 & Print @(0,12) for compatibility. Took about half a dozen runs before it started, the got up to the 84th write before it errored out. Was no point in trying it on a 28 pin as all the other routines are running there fine. Phil. |
||||
mikeb Senior Member Joined: 10/04/2016 Location: AustraliaPosts: 173 |
ALL eeprom's have a SELF TIMED WRITE CYCLE. Ensure your code does not attempt to issue a 'write' command before this time has expired. For the device in question 'write cycle' time is 5 msecs. Who knows what a cheap chinese 'knockoff' is capable of. Take a look at 'Acknowledge Polling' at the bottom of page 10 of the datasheet. I am not familiar with the source code, of the I2C function, but presume it will flag an error. I should probably take a harder look at the excellent Error Glossary which Geoff, and Grogster, posted recently. Atmel Datasheet I'm with WW. Use FRAM. There are 10 kinds of people in the world. Those that understand binary and those that don't. |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Yeah I know that; The thing with the AT24C32 is that it's already there on almost all my MM's, so makes sense to just use it for applicable amounts of Variable saving. Will be interested to see how it's been implemented in the Energy Meter code. Guess they are using the same approach; We've already got it, so may as well use what's already there... Cheers Phil. |
||||
mikeb Senior Member Joined: 10/04/2016 Location: AustraliaPosts: 173 |
Yeah. Your right mate. If it's there, use it. I only through in the 'write cycle' time, as in my experience with digital electronics, timing (and datasheets ) is everything. I only use modules due to convenience in prototyping. I generally design my own hardware, and pcb's, so I'm not stuck with 'off the shelf' solutions. As they say 'Nobody knows everything about everything'. That's why forum's, such as this, are invaluable. Geoff, Peter and Rick (and others) have given us a good baseline to work off to learn new things. Hey, I'm just trying to ward off Alzheimers . I learn 'tips and tricks' off everyone on this forum. Thanks to you all. BTW The XOR function, with the DS18B20, is from my 8 bit micro experience. When I said "It works for me" I was referring to calculation using a 'Windows' calculator in 'Programmer' mode. I haven't actually done it in MMbasic. You should probably use TassyJim's method. I'm still not sure how to declare, and use, 8\16 bit variables in MMbasic. It was 'easy as' with PICbasicPro. But then it didn't handle 'floating point' variables. There are 10 kinds of people in the world. Those that understand binary and those that don't. |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5905 |
And it does actually work. Learning/doing something new at any age has been proven to help delay the onset. So has physical exercise but I find mind exercises more fun. For anyone interested, I highly recommend the Dementia courses offered (free and on line) by the Wicking Dementia Research and Education Centre, University of Tasmania. I will let you know if they worked for me in 20 years or so... (If I remember) Jim VK7JH MMedit  MMBasic Help |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9063 |
I do have to agree with WW here..... FRAM is brilliant stuff, and given the choice, I will always go for FRAM over EEPROM these days. Yes, it IS more expensive, but you don't need to worry about things like page-boundaries or write time delays. You fire the data at the FRAM where-ever you want to store it, whenever you want. No need to even THINK about where on what page it is, or if there is a need for a page-write delay, all you need to know is the address were you are writing or reading. EEPROM is still useful though, don't get me wrong, and it is cheaper then FRAM. I just love FRAM cos it is so simple to use, and for me, that is a big thing as it cuts down a lot of the programming hassle not having to worry about things like page boundaries, write delays and endurance testing etc. For ME, that warrants the extra cost to say nothing of the extra reliability you also get with FRAM over EEPROM. But I digress....... Smoke makes things work. When the smoke gets out, it stops! |
||||
mikeb Senior Member Joined: 10/04/2016 Location: AustraliaPosts: 173 |
@TassyJim Sorry mate. Forgot to acknowledge your contribution Just on the quiet, teach Geoff how to add a 'DONATE' button. There are 10 kinds of people in the world. Those that understand binary and those that don't. |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Yeah I've tried the XOR version in code and I think I have it working. One thing I'm still not getting right is a sensor reading error if it happens to be the case. As I mentioned in another thread, at present I can unplug a sensor & get what could be considered a valid reading in the right condition. IE -0.625°C, would have been totally legit at some point this morning. Phil. |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2289 |
one must remember: there are around 500,000 (half a million) minutes in a year. so if you write data every minute, your eeprom is guaranteed by atmel to last at least 2 years, and more likely 7 years based upon the above testing. if you write data every 10 minutes, that goes up to 70 years. if you use 100 locations in rotation (with a timestamp to determine the latest data) that goes up to 700 years (at one write a minute). so the trick is to use multiple locations in a circular queue to save your data, and try to not write more often than once a minute. after all, how much of a disaster is it if the odd 1 minute span of data is lost? cheers, rob :-) |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
For what I see it being used for; saving variables as opposed to long term data logging, which can be done to an SD card. Possibly 1/2 hour to hourly variables might be recorded. Life span should be sufficient in these cases. While I can get my head around Twofingers routines & understand saving to addresses & the significance of page boundaries, first time users probably won't, and would be much more comfortable with something along the lines of SAVE VAR. Cheers Phil. |
||||
Nathan Regular Member Joined: 10/01/2016 Location: GermanyPosts: 49 |
Hi, the EE-prom story is a little bit more complicated. There are several unexpected effects. Especially for data, which is written only once. for a nice explanation search for: http://mientki.ruho .. eeprom_problems.html The following application notes are very helpfull, too: Microchip AN537 and Microchip AN1019 Nathan |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 1985 |
...it is also fast (upto 40MHz SPI) and cheap now... 512Kx8 is just £7 on RS http://docs-europe.electrocomponents.com/webdocs/152f/0900766b8152fe01.pdf |
||||
Print this page |