newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Thu Jul 28, 2005 9:23 am |
|
|
The page system is not that hard to grasp.
Imagine a book with 500 pages. Imagine that you are dictating to a person who is actually typing the book for you. This rather gifted person can listen and retain one page worth of text before they start typing. Let me also add that no words get lost either. However, if you try to dictate more than one page worth of text, the extra "spills over" or "loops back" onto the beginning of the page.
That's sort of like the page system with external EEPROMs. For instance, I'm presently using a 24LC32, a 32k serial eeprom. This particular one can accept 32 bytes for storage, at most, before actually writing the data all at once. In this case, 32 bytes is the page size. Note that you can't overflow one page when doing a page write. In the case of the 24LC32, I can do a page write to address 0x0000, then again at address 0x0020 (32), and so on. I can start a page write at address 0x0014, but the data being written will start at address 0x14, then "roll over" at address 0x1f back to address 0x00.
I should also mention that the 24LC32 is a 32 kbit EEPROM, which means you can store 32/8 = 4 kbytes. You can store one byte/address, in addresses from 0x0000 - 0x0fff.
The datasheet for your EEPROM will tell you how big a page is.
As for storing data, that's up to you how you'd like to handle it. Since it sounds like you're storing only two things, V & I, I'll use that as a basis for the explanation.
First you should note that serial EEPROMs are usually 8 bit. That is, they are capable of storing 8 bits in every address. If you have a variable, such as voltage, which goes up to 1023, you'll need a 16 bit variable to store it. That means that you'll need to break up this variable into a low and a high byte, and store those individually in the EEPROM. When you read voltages from the EEPROM, you'll need to reassemble the 16 bit variable yourself based on the low and high bytes you read from memory.
Note that you should always put the low & high bytes of 16 bit variables right next to each other in memory (i.e. address = high byte, address + 1 = low byte, or vice-versa).
For instance,
Code: | int16 voltage, address;
int8 high_byte, low_byte;
// for write, break apart the 16 bit variable
low_byte = voltage;
high_byte = voltage >> 8;
// do writes here
// for read
high_byte = read_from_memory(address);
low_byte = read_from_memory(address + 1);
voltage = (0x100 * high_byte) + low_byte; // reassemble the 16 bit variable |
Since you are storing V & I readings, what I'd do is group them together. I'll assume that the I is also a 16 bit variable. This requires the storage of 4 bytes total, 2 for voltage, 2 for current. If you have a 16 bit variable called address which contains the address where you store these things in the EEPROM, then you could do something like this:
Code: | int16 address = 0, resistance = 10;
int8 i;
for (i = 0; i < 100; i++) {
voltage = read_adc(); // read voltage
current = voltage / resistance; // calculate current
save_value(voltage, address); // store voltage in EEPROM
save_value(current, address + 2); // store current in EEPROM, right next to the voltage
address = address + 4; // add 4 to address so that the next time through the loop the next values will be stored next to the previous ones
} |
I hope this helps to clear some of it up for you. |
|