CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Programming speed 25LC1024 EEPROM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Jody



Joined: 08 Sep 2006
Posts: 182

View user's profile Send private message Send e-mail

Programming speed 25LC1024 EEPROM
PostPosted: Fri Nov 11, 2011 4:36 am     Reply with quote

Hello,

I have made the following:
A system, PIC18F8722 running at 40MHz, what get's it's data through a serial port(115200,8,n,1) and write the data to an EEPROM(25LC1024).
The data is 4byte at a time.
This all works... I wright the data to the EEPROM and can check if it's there(which is).

But I am sending 4096 times 4 byte= 16kbytes...

And this is going really slow (or I am inpatience).. it takes up 39 minutes to send this....

Included the EEPROM code.... I think that there iss something taking up time I can't figure out what.......

Functoin which is writing to the EEPROM:
Code:

 void write_ext_eeprom(EEPROM_ADDRESS address, BYTE data) {
    BYTE cmd[5];
    BYTE i;
    BYTE wren;
    wren=0x06;
    cmd[0]=data;
    cmd[1]=address;
    cmd[2]=(address>>8);
    cmd[3]=(address>>16);
    cmd[4]=0x02;
    // Wait until the eeprom is done with a previous write
    while(!ext_eeprom_ready());

    output_low(EEPROM_SELECT);
    for(i=0; i<8; ++i)
    {
       output_bit(EEPROM_DI, shift_left(&wren,1,0));
       output_high(EEPROM_CLK);
       output_low(EEPROM_CLK);
    }
    output_high(EEPROM_SELECT);
    output_low(EEPROM_SELECT);
    for(i=0; i<40; ++i)
    {
       output_bit(EEPROM_DI, shift_left(cmd,5,0));
       output_high(EEPROM_CLK);
       output_low(EEPROM_CLK);
    }
    output_high(EEPROM_SELECT);
 }

 BOOLEAN ext_eeprom_ready() {
    BYTE cmd[1], i, data;

    cmd[0] = 0x05;                  //rdsr opcode

    output_low(EEPROM_SELECT);

    for(i=1; i<=8; ++i) {
       output_bit(EEPROM_DI, shift_left(cmd,1,0));
       output_high(EEPROM_CLK);   //data latches
       output_low(EEPROM_CLK);      //back to idle
    }

    for(i=1; i<=8; ++i) {
         output_high(EEPROM_CLK);   //data latches
         shift_left(&data,1,input(EEPROM_DO));
         output_low(EEPROM_CLK);  //back to idle
    }
      output_high(EEPROM_SELECT);
      return !bit_test(data, 0);
 }
 


Function which is getting the data out the string:
Code:


    if(tabelnummer > 0) // Tabelnummer groter dan '0' dus we gaan een tabel vullen
    {
      int8 eeprom_data_8_1,eeprom_data_8_2,eeprom_data_8_3,eeprom_data_8_4;
      int8 data_eeprom;

          eeprom_data1[0]    = string[0];
         eeprom_data1[1]    = string[1];
         eeprom_data1[2]    = 0x0D;
         eeprom_data_8_1   = atoi(eeprom_data1);
         write_ext_eeprom(address_eeprom,eeprom_data_8_1);
         address_eeprom++;

         eeprom_data2[0]    = string[2];
         eeprom_data2[1]    = string[3];
         eeprom_data2[2]    = 0x0D;
         eeprom_data_8_2   = atoi(eeprom_data2);
         write_ext_eeprom(address_eeprom,eeprom_data_8_2);
         address_eeprom++;

         eeprom_data3[0]    = string[4];
         eeprom_data3[1]    = string[5];
         eeprom_data3[2]    = 0x0D;
         eeprom_data_8_3   = atoi(eeprom_data3);
         write_ext_eeprom(address_eeprom,eeprom_data_8_3);
         address_eeprom++;

         eeprom_data4[0]    = string[6];
         eeprom_data4[1]    = string[7];
         eeprom_data4[2]    = 0x0D;
         eeprom_data_8_4   = atoi(eeprom_data4);
         write_ext_eeprom(address_eeprom,eeprom_data_8_4);
         address_eeprom++;

         printf("ACK"); // Send next data packet
   }


Anybody an idea where I am going wrong???
Or isn't it possible to go faster????

Regards,
Jody
Ttelmah



Joined: 11 Mar 2010
Posts: 19477

View user's profile Send private message

PostPosted: Fri Nov 11, 2011 4:50 am     Reply with quote

Page writes.

Key thing is that it takes as long to write one byte, as the entire page.
You need to have a 256byte buffer. Write data to this, and once it is full, perform a page write, rather than the single byte write. You drop CS, and send the write instruction, then the address for the start of a page (256byte boundary in the chip), then 256bytes of data, and only then raise the CS. Assuming you have the MicroChip data sheet, figure 2-3.
It takes 6mSec to write a byte, or 6mSec to write a whole page....

Also, use the internal SPI routines. Preferably hardware, but otherwise you the software routines. They will be significantly faster than your bit-banging code.

Best Wishes


Last edited by Ttelmah on Fri Nov 11, 2011 4:53 am; edited 1 time in total
Jody



Joined: 08 Sep 2006
Posts: 182

View user's profile Send private message Send e-mail

PostPosted: Fri Nov 11, 2011 4:53 am     Reply with quote

Oke that must speed up things 256 times....

I go and rewrite the code...

Thanks,

Keep you informed

Jody
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Nov 11, 2011 7:22 am     Reply with quote

In addition to using page write, you can slightly increase the interface speed by using hardware SPI, if the dedicated IO pins are available in your design.
Jody



Joined: 08 Sep 2006
Posts: 182

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 14, 2011 10:35 am     Reply with quote

Oke what I have done...
Remove the bitbanging and use the spi_xfer routines.
Write page inserted in my code.
But still it is going really slow....
4500 lines sending to the pic which is writing it to the EEPROM takes 30 minutes.
I am doing some string copy and atoi routines in my code. Is that why this is running so slow???

Any idea's are welcome.

regards,
Jody
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Sun Nov 20, 2011 7:42 am     Reply with quote

try a FRAM.
they are more expensive, but very fast.

Solder one that fits in your pad layout and try it.
http://www.mouser.com/Semiconductors/Memory/_/N-488qu?Keyword=FRAM&FS=True

http://www.ramtron.com/files/datasheets/FM24W256_ds.pdf
Ttelmah



Joined: 11 Mar 2010
Posts: 19477

View user's profile Send private message

PostPosted: Sun Nov 20, 2011 8:00 am     Reply with quote

The other comment (I too like FRAM's...), is "are you sure something else isn't limiting the speed". You talk at one point about this data coming from serial. Is it possible the problem is here, possibly in the interpretation of the data?.
Do a really basic test, and write a fixed pattern like AA55, to your write code, without all the other routines. What happens to the speed?.
Plenty of people here have used EEPROM's, and though slow compared to FRAM, they are not _this_ bad...

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Nov 20, 2011 4:06 pm     Reply with quote

30 minutes is way too long.
16kbytes / 256 page size = 64 page writes.
5ms per page write --> total write time should be just over:
64 x 5ms = 0,32 seconds.

About 5000 times faster than you are experiencing.

The slowest thing in your process should be the downloading of the data, 16kbyte over 115200 baud takes about 1.4 seconds.

I suggest you try to determine the cause of your slowness again. Replace the EEPROM write routine by a dummy stub and measure timing again.

If it turns out to be the slow EEPROM writing, then post your latest software, including the SPI setup functions.

About the FRAM suggestions. If you still can change the hardware design and data is to be updated often then this is a recommendation I support as well. No delays, no pages, and can be rewritten limitless times (EEPROM is dead after 100k writes on average).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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