|
|
View previous topic :: View next topic |
Author |
Message |
respected
Joined: 16 May 2006 Posts: 95
|
External EEPROM and datalogger |
Posted: Wed Oct 08, 2014 3:32 pm |
|
|
Hi everybody;
I want to create datalogger with external EEprom. But i need how is write eeprom repeatedly.
For example i have 100 bytes eeprom. First record 40 bytes, second record 40 bytes and third record 30 bytes. In this case i have to erase first record 10 bytes.
How should I write a formula?
Code: |
first adress first record
0 40
second adress second record
40 40
third adress third record
80 30 (overflow) |
Thanks |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Wed Oct 08, 2014 7:46 pm |
|
|
You have two problems with your scheme - the first, you need to keep track of where the next record to write is going to go. The second is with your storage. You can't simply "erase" 10 bytes from the first record so you are under 100 used. How would you link the first part of the third record to the chunk that has to be written into the first 10 bytes you erased? It is possible to erase some data and move the rest forward, but that results in needless time and wear and tear on the eeprom (they are only rated for a certain number of write cycles - you don't indicate how often you would be writing to the eeprom. You would be better off seeing if you could pack the data so you could put your 3 records or whatever in the memory. The other question I see is you refer to a "datalogger" - typically, 3 records is not going to be anywhere near enough for any datalogger type application. For any amount of memory though, you need to have a method to determine where the next record is going to be stored (and storing that pointer that gets changed each time you write to eeprom in a single eeprom location is not a good idea due to the number of rated write cycles (see the data sheet for your chosen PIC processor).
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Oct 09, 2014 1:17 am |
|
|
He says 'external EEPROM', so needs to looks at it's data sheet.
However I'd say 'look at FRAM'. Faster, and doesn't have a write life (infinite!...).
Be logical, and consider using (say) a 64 byte record for everything. Much simpler, also allows for expansion. |
|
|
respected
Joined: 16 May 2006 Posts: 95
|
|
Posted: Thu Oct 09, 2014 1:30 am |
|
|
Thanks Ttelmah, but i have circuit with external eeprom. It has 64Kbytes memory. I got example (100 bytes). I want to learn how is write repeatedly. I think I use 50 times recording. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Oct 09, 2014 2:05 am |
|
|
There are FRAM's that are pin compatible for many EEPROM's.
Thing is that EEPROM both has limited life, and is _slow_.
As gpsmikey says you need to keep track of where you are working, and if you store this in the EEPROM, then the cells holding this become used much more... :(
If you use a 64byte cell, then assuming your EEPROM is one that erases to 0xFF in the cell (most normal chips), use this as the flag to say 'cell empty'. So you have the first word (not part of your record, as 0xFFFF saying 'not used'. Then you can look through the EEPROM, just looking at every 64th word, and if this is 0xFFFF then this is a record available for use. Use values below this as a 'record number'. So when you write the record, change this to 0000 for the first record, then 0001 for the next etc.. Use the next byte as a 'type' marker, to say whether this is a 40byte #1 record, 40byte #2 record, or 30byte record.
So have a structure as (say):
Code: |
struct {
unsigned int16 record_number; //65535 = empty
int8 type; 0,1,2 = your three record types
int8 dummy; //use as required - remember PIC24/32 likes 16bit alignment
unsigned int32 time_stamp; //work out a way of coding time in this
char data[56]; //area to store your actual data
} record;
|
Now assuming the EEPROM is not larger than 2097152 bytes, when you boot, look through the chip for the highest record number less than 65536. The record after this with 0xFFFF, is the next place to write.
You just write whatever record you want to the next block, with the next record number. Keep going till you have to loop back to the start. When you do, erase one block of the EEPROM, and carry on from the beginning. Each time you find the next record to write does not have the 0xFFFF marker you should be on an EEPROM page boundary (EEPROM's use erase pages that are binary in size, so 1024 bytes etc..), and can just erase the next page.
You'll have to 'wrap' the record number at 32768.
Put your actual data to write into the array 'record.data', and set the flag 'type' according to how big the actual record is. This way you know what 'type' of record this is when reading. |
|
|
respected
Joined: 16 May 2006 Posts: 95
|
|
Posted: Thu Oct 09, 2014 1:11 pm |
|
|
Thanks again Ttelmah;
I found different solution. I used internal eeprom. I encoded start time after that i wrote internal eeprom.
I sorted for encoded data (starting time, index number, record count, record address).
I erased the oldest data.
p.s: encoded data is recorded internal eeprom.
temp data is recorded external eeprom.
I think it will be good idea for me.
Thanks a lot |
|
|
|
|
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
|