1
\$\begingroup\$

I'm using C18 compiler and 24LC256 EEPROM. I would like to know how to handle Rollover case in terms of large EEPROM write.I'm writing a Routine that writes 120 Bytes every half an hour and i would like to know how can i save/store my data easily as Page Write will take only 5 ms as equal to a single write operation.The Page size here is 64 Bytes.And i have to write for 10 hours making it 2.4 K space per day.

Well the problem i have is:

1.I want to use Page Write Efficiently and wants to prevent Roll over condition. page size starts from 0-63 , 64-127 ,128-191,192-255...up to 32 K. I want to Predict when is the Page Limit coming and wants the Page Write to shift accordingly.

eg: If i start with 0th address: 0-63 will occupy 64 bytes and 64-117 will occupy the next 56 Bytes. Then for the next Page Write i can only write 20 locations and have to write 64 and 20 in another two Page Write Operations.

Note:Dedicating starting Page Locations for each Page Write is not required.

Page write operations are limited to writing
bytes within a single physical page,
regardless of the number of bytes actually
being written. Physical page boundaries
start at addresses that are integer
multiples of the page buffer size (or ‘page
size’) and end at addresses that are
integer multiples of [page size - 1]. If a
Page Write command attempts to write
across a physical page boundary, the
result is that the data wraps around to the
beginning of the current page (overwriting
data previously stored there), instead of
being written to the next page, as might be
expected. It is, therefore, necessary for the
application software to prevent page write
operations that would attempt to cross a
page boundary

I have been trying to find an algorithm to do so. It would be extremely helpful if you sort out this issue or suggest your insights.

Regards

Arookie

\$\endgroup\$
6
  • \$\begingroup\$ Wouldn't it be much simpler to always write your 120 bytes to two pages? You don't seem to be size-constrained. \$\endgroup\$ Commented Jan 15, 2014 at 9:26
  • \$\begingroup\$ Well i'm pretty much size constrained here.I was just trying to get a method to find an apt method here to fix the problem. \$\endgroup\$
    – Rookie91
    Commented Jan 15, 2014 at 9:34
  • \$\begingroup\$ I don't see your problem. For every byte you write you increment a counter, when it reaches 64 you do a page write and set the counter to 0. \$\endgroup\$ Commented Jan 15, 2014 at 10:11
  • \$\begingroup\$ Thank you @Wouter van Ooijeb What if it crosses the page boundary.It can cause a problem right. \$\endgroup\$
    – Rookie91
    Commented Jan 15, 2014 at 10:33
  • \$\begingroup\$ When you cross the page boundary the address rolls over to the first location of the page and you overwrite the value there. \$\endgroup\$
    – alexan_e
    Commented Jan 15, 2014 at 10:36

1 Answer 1

1
\$\begingroup\$

What Wouter van Ooijen has suggested does perfect sense.

This should work

uint8_t page_counter=0;
uint8_t data_counter=0;
uint8_t last_used_address=0;


while(data_counter<120)  // we want to write 120 bytes
{
  send_eeprom_address(last_used_address);
  while((page_counter++)<64)  // while not end of page
  {
     write_eeprom_byte(y);         
     if (++data_counter==120) break; // exit the loop is 120 bytes have been written
  }
  last_used_address= last_used_address + page_counter;  // update last used location
  if(page_counter==64) page_counter=0;
}

The code is untested, and you obviously need to implement the correct eeprom functions.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ thank you @alexan_e.I am extremely grateful for your valuable time. \$\endgroup\$
    – Rookie91
    Commented Jan 15, 2014 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.