Page 1 of 1

How to optimize the write speed of a SD card?

Posted: Thu Feb 14, 2013 11:06 am
by Mathy
Hello,

Im trying to write on a SDCARD, data from different sensors.
In a perfect world, I would like to setup an interrupt macro who read the different sensors and store them into a file created on my SDCARD 100 times by second.

Today, it's impossible. I try with only two different sdcard. One Kingston 4Go class 4 and one Samsung 32Go class 10.
I have a better result with the samsung but it is not enough significant.
The problem is writing a single character with the "append_string_to_file" macro is done in 25.40ms !
Writing 15 character is not more longer. The simple fact to write something take a very long time.

I would like to know if there is a technique to increase speed when writing something in my sdcard ?

Im using a 18LF25k22 running at 32 Mhz ( 64 Mhz don't work and I don't know why yet ).
Im using the hardware SPI with a prescaler of 4 ( the fastest ).

Do you have any idea ?

Thank you for your help :)

Re: How to optimize the write speed of a SD card?

Posted: Thu Feb 14, 2013 12:46 pm
by Benj
Hello,

The append string to file macro is very inefficient and is only included as it makes the write process very simple. Download a copy of the main Flowcode examples pack from our learning center and in there is a example of a much more efficient write method which consists of writing entire sectors.

http://www.matrixmultimedia.com/lc_index.php?p=18

The file is located here.
Flowcode v5 Examples\Components\FAT\6. Data_Logger_Sector_Fast.fcf

Re: How to optimize the write speed of a SD card?

Posted: Thu Feb 14, 2013 12:47 pm
by Mathy
Hi again,

I found in your example, the function write to buffer who seems to write much faster.
I tried to write the character "A" ( 0x41 ) to the 512 sector available and then, I wrote the complete buffer to the SDCARD.
This last macro return me a 0 so it is a success but the data on my SDCARD are broken.

I have a file created of 2167 Ko but with nothing inside.

I tried in fat 16 and fat 32 file format with the same result.

Do you have any idea ?

Re: How to optimize the write speed of a SD card?

Posted: Thu Feb 14, 2013 12:49 pm
by Benj
Have a look at the example until you understand how it is working. Then try to apply to your own program.

Re: How to optimize the write speed of a SD card?

Posted: Thu Feb 14, 2013 1:00 pm
by Mathy
Hi Benj,

I already tried your example program. We post at the same time !

I made a very simple program but I have the same result each time I test.
Can you tell me what i'm doing wrong ?

Thank you.

Re: How to optimize the write speed of a SD card?

Posted: Thu Feb 14, 2013 6:27 pm
by Mathy
Re,

I modded your example to search what I'm doing wrong but with no success.
I erase all the LCD instance because I don't have one.

I have a created file "log2.txt" of 2167 Ko and empty (opened with notepad++) that is exactly what I had with my own little program.

I tried at different frequency with two different SDCARD with the same result.
The same board give me good result with the "append_string_to_file" macro.

Thank you for your help.

Re: How to optimize the write speed of a SD card?

Posted: Fri Feb 15, 2013 6:22 pm
by Mathy
Hello Benj,

I made some test today...but without any result.

I read this topic : http://www.matrixmultimedia.com/mmforum ... 5&start=50
I saw that Jordy101091 had a similar problem. He can create file but when he want to read the file with a computer, it say the card need to be formatted and the file is empty.
He have this problem with the append to string macro.

I have exactly the same problem but with the write to buffer macro.
My computer don't tell me that the card need to be formatted all the time. Only one or two per 10.

I tested with the last flowcode release for PIC ( 5.5 ). I also tried with the FAT16.c file in the topic I spoke about.
I also tried to reduce the spi speed %a_SPI_Set_Prescaler(2); instead of %a_SPI_Set_Prescaler(0);

But without any result. I tried in fat 32 and fat 16.
but no way, the file is always empty ( but Windows says that the file is about 162Ko when testing in fat 16 and 2167ko in fat 32 )<-- not sure about the exact size.

Do you have any idea ?

Re: How to optimize the write speed of a SD card?

Posted: Sun Feb 17, 2013 5:14 pm
by Mathy
Hi,

I worked with a friend this weekend who have a Flowcode for DsPIC V5.5
He use this DEVboard ( http://www.mikroe.com/mikromedia/dspic33/ ) and we tried my program and your's to test the write to buffer macro.

After a little problem with the fuses, It works very well at the first time on the DsPIC but impossible to make it work with the 18F.
We tried of course with the same SDCARD.

We only tried at 80 Mhz and software SPI in FAT16 with the DsPIC.

If you can have a look to solve this issue...

Bon courage

Re: How to optimize the write speed of a SD card?

Posted: Tue Feb 19, 2013 2:42 pm
by Mathy
Hello Benj,

Have you had time to look at my problem ?

Thank you,

Mathy

Re: How to optimize the write speed of a SD card?

Posted: Tue Feb 19, 2013 5:58 pm
by Mathy
Hi,

To be sure that is not a problem with the k22 family, I tried today with a 18F26k20 in software SPI mode and I have the same problem.