|
|
View previous topic :: View next topic |
Author |
Message |
sorasit46
Joined: 07 May 2007 Posts: 69
|
Question about eeprom in 16F886 ? |
Posted: Sat Feb 21, 2009 7:20 pm |
|
|
Hi!
Code: | #Separate
#include <16F886.h>
#device ADC=10
#define CLOCK_SP 4000000
#fuses hs,NOLVP,WDT,NOPROTECT
#fuses NOPUT,NOCPD,NOWRT,NODEBUG
#use delay (clock=CLOCK_SP)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#byte port_b=6
#byte OSCCON = 0x08F
.
.
int16 Read2eeprom(int AddressRead) // Adress read
{
int16 DataRead; // Data read
DataRead=(int16)read_eeprom(AddressRead)+((int16)(read_eeprom(AddressRead+1))<<8);
if(DataRead<1) DataRead=0;
if(DataRead>5000)DataRead=0;
return(DataRead);
}
#Separate
void Write2eeprom(int AddressWrite,int16 DataWrite)
{
write_eeprom(AddressWrite, (int)(DataWrite&0x00ff));
write_eeprom(AddressWrite+1,(int)((DataWrite&0xff00)>>8));
}
.
.
Void main()
{
.
.
Write2eeprom(0,mem0);
Write2eeprom(1,mem1);
Write2eeprom(2,mem2);
.
.
mem0=Read2eeprom(0);
mem1=Read2eeprom(1);
mem2=Read2eeprom(2);
.
.
|
1.How many address can use?
2.Why sometime can not write to eeprom?Because when I repower on ,it show old value.
regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 21, 2009 11:04 pm |
|
|
Quote: | 1. How many address can use? |
The 16F886 has 256 bytes of eeprom, so you can use addresses from
0x00 to 0xFF for the eeprom.
Quote: | 2.Why sometime can not write to eeprom? Because when I repower on, it show old value. |
If you write to the same eeprom address too many times (in a loop), you
can burn out the eeprom. It can burn out in 100K write operations.
You didn't show all your code. It's possible that you have a loop for
that calls write_eeprom() continuously, and the eeprom is partially
burned out.
Here is a test program that saves data to eeprom and then reads it
again when the PIC has power re-applied. Try it:
http://www.ccsinfo.com/forum/viewtopic.php?t=22109&start=17 |
|
|
sorasit46
Joined: 07 May 2007 Posts: 69
|
|
Posted: Sat Feb 21, 2009 11:39 pm |
|
|
Thanks alot.
Yes I write to the same eeprom address continuous. |
|
|
Ttelmah Guest
|
|
Posted: Sun Feb 22, 2009 10:34 am |
|
|
You need to 'rethink' how you are working then.
Multiple approaches:
1) Only actually write the data when power is turned off. This is surprisingly 'easy'. All you do, is add circuitry that detects the incoming supply falling, and ensure that the capacitance on the PIC power rail is sufficient to run the chip for the time needed to write all the data when the incoming supply reaches this point. Then have an interrupt when the power fail is detected, and write the data in this.
2) Only write the data at quite long intervals. For example, on a 'position' controller, which accepts keyboard movement commands, I will detect when a change is initiated, and only write the data, when it has changed, and then stayed the same for 30 seconds. When people are adjusting the system, issuing dozens of movements, no 'write' occurs. Only when they are happy, and leave the value alone, is this recorded.
3) Use another storage medium, like FRAM, that does not have this limitation.
While '100K' cycles, sounds a lot, if you write once a second, it only takes just under 28 hours to destroy the chip. Write faster, and the time is less....
The EEPROM, is not designed for 'dynamic' data, but for storing configuration data that changes infrequently.
Best Wishes |
|
|
sorasit46
Joined: 07 May 2007 Posts: 69
|
|
Posted: Mon Feb 23, 2009 11:43 pm |
|
|
Ohh! Thanks. Now I see.
Really I'm destroy the chip in 1 day, because I write as dynamic data.
Now I must detect falling supply before power sufficient to run the chip.
This is new problem.
regards |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
toasting EEPROM another way my 2 cents |
Posted: Tue Feb 24, 2009 9:23 pm |
|
|
I recently toasted the eeprom in an f887 after as few as 50 or so erase cycles to reprogram the part. I had noted that erase ( on my programmer anyway)
erases the user EEPROM too. no problem.
On the part I wrecked - the symptom was that an int16 checksum stored after last byte in EEPROM kept failing with a rock solid known good code library.
As soon as I uploaded the same hex file into a new F887 - problem solved EEPROM worked like supposed to
The odd thing was if I erased the bad '887 some more - it would work for a while - but then in a day or so - be right back to the no go mode
where I update the eeprom content
and on next power UP - it get the failed checksum message on the data put there. spooky
TX PCM for your input |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|