Go Down

Topic: How rate of Reading SD-CARD works ? (Read 1 time) previous topic - next topic

cruj

Hello guys,

I'm using a SD-CARD with an arduino nano and uno to send images for an e-ink display.

I have to change images with high rate, and I saw that for differents images, I have differents rate of open an image from SD-CARD.

I saw that if the file is in the root of SD, I get one rate, if was in some folder I have another rate (sometimes better others worst)
The name of file is something that changes a lot the rate of function SD.open().

I tried to debug and understand why the rate changes so much. sometimes takes 100ms and others 1200ms.

Anyone can help me how to increase that rate ?  the amount of files is about 600, and is a xbm image (2kb).

That is something that I can change on functions of SD librarys to change that ?  ( I already set FULL_SPEEDY for the SPI)

Thankyou ,

Leonardo




PaulS

Quote
I already set FULL_SPEEDY for the SPI

FULL_SPEEDY? That's a new one on me.

I'm pretty sure that your use of rate in your post is inaccurate, since it appears to mean duration instead.

Posting some code would be useful.

cruj

Sorry about my english !

For rate I mean the duration of function SD.open()

Code: [Select]

File current_image;
File next_image;

void set_spi_for_sdcard(void) {
// SPI.end();
SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV128);
}

void abre_imagem(const char *nome){
 
       current_image.close();
       current_image = next_image;
       next_image = SD.open(nome);
}


and the char "nome" is something like "1.144", "2.144", "3.144", etc...

I used the funciont millis() to get the duration of functin SD.open() and for each image, takes different time !

I have to increase that function !

fat16lib

The time to open a file is hard to predict.  FAT directories are not ordered so open must do a linear search.  Unused directory entries are scattered in the directory. 

There is no simple way with SD.h to open files fast when you have 600 or more in a directory.

I would create a large contiguous file and place all the images in this file with each image in a fixed size record.  I would then read the records using the raw SD read functions in SD fat. 

Here is how raw read/write works.  http://forum.arduino.cc/index.php?topic=234981.msg1694261#msg1694261.

SdFat has a function to create a contiguous file.
Quote

bool SdBaseFile::createContiguous    (    SdBaseFile *     dirFile,
      const char *     path,
      uint32_t     size
   )       

Create and open a new contiguous file of a specified size.

Parameters:
    [in]   dirFile   The directory where the file will be created.
    [in]   path   A path with a valid DOS 8.3 file name.
    [in]   size   The desired file size.


There is also a function to find the location to the file.
Quote
bool SdBaseFile::contiguousRange    (    uint32_t *     bgnBlock,
      uint32_t *     endBlock
   )       

Check for contiguous file and return its raw block range.

Parameters:
    [out]   bgnBlock   the first block address for the file.
    [out]   endBlock   the last block address for the file.

Go Up