Main Site Documentation

Slow SD card


#1

Hi

I’m using FEZ Spider and a SD card reader along with GPS and temperature modules. The attached camera takes 320x240 bitmaps and I wish to save these images to the SD card as often as possible. At the moment, I have set it to save two images per minute.

The problem is that it’s super slow. The function

 takes about 6 to 10 seconds to complete on a class 6 Transcend SD HC SD card. These cards are meant to write atleast at 6 MB/s. So it shouldn't take very long to write the 226KB .bmp file to disk.

Here is the relavent code:

        
```cs
// ================================================================
        // writes camera picture to SD card. File names are incremented
        // to ensure no duplicates over-write existing pictures
        void writeImage(GT.Picture picture)
        {
            GT.StorageDevice SDCARD = sdCard.GetStorageDevice(); 
            int imageNumber = SDCARD.ListFiles(Constants.DATA_DIRECTORY).Length;
            string pathFileName = Constants.DATA_DIRECTORY +  
                "img" + (imageNumber++).ToString() + " " +
                g_data[(int)Constants.titles.TIME] + ".bmp";

            if (sdCard.IsCardMounted)
            {
                Debug.Print("Write image to SD card...");
                SDCARD.WriteFile(pathFileName, picture.PictureData);
                Debug.Print("Finished writing.");
            }
            else
            {
                Debug.Print("SD Card is not mounted. Could not save image.");
                sdCard.MountSDCard();
            }

            Debug.Print("Done.\n");
        }

Is there anyway to speed up the write time of the bitmaps? Is this typical performance of the FEZ Spider?? I’m pretty sure it’s not a hardware problem because of the minimum write speed of the card.

Thank you in advance :slight_smile:


#2

have you timed the relevant portions of your code to see if the byte write is the long part ? String ops and directory ops will all take a non-trivial amount of time, but at the end of the day these devices are somewhat restricted in data throughput rates - they are in no way optimised for the kind of data rates needed for sustained rates of data with cameras, so maybe you’re just seeing the natural limit of the entire system.

What camera are you using too btw, you didn’t mention that ?


#3

Hi Brett,

I’m using the USB camera from GHI: https://www.ghielectronics.com/catalog/product/283

I used Debug.Print() and DateTime.Now to time different parts of the code. The string stuff is pretty quick, about 100 ms, and the writefile() method takes 6 to 10 seconds.


#4

Hi
I recently had a similar problem.
Sd card writing was very slow with G120 module, 1 Mb file writing time was ~60 sec. I use a custom pcb and found that sd card data line pull up resistors (10K) are too big, after trying 4.7K resistors, writing speed was ~10 sec, it was six times faster!
Soon I will try with 1K resistors and I think that writing speed will be much better.

So if you have a soldering station and you know how to solder then you can try to change resistors. Otherwise please, do not try this - you can even break your board


#5

Agreed, that says every sd card datashet.

But if you check card pin capacitance (typical is 10pF) and check capacitor resistance vs frequenc chart you see that if frequency is 10MHz, 10pF capacitor gives you a 5Kohm. So if you using 10Kohm pullup resistor and clock frequency is 10MHz then maximum pin logical voltage level is 1.1V assuming that sd card data pin input resistance is 1Mohm, higher frequency means lower impedance.

Now add pcb track capacitance or wire capacitance and you get even worst voltage levels and you can see voltage drop using ossiloscope with low capacitance probes

Now comes another question - does sd card internally has open collector or push-pull?
And processor side too, what technology is used?

If both cpu and sd card uses push-pulloutputs , then 10K pullup, even 100K pullup is ok, pullup resistor only prevents pin floating.

But if one side or both sides uses open collector connection then you are in trouble getting higher clock and data speeds because higher frequency needs higher current to drive logic signals propertly.

I think that open collector technology is used because lowering resistor resistance actually gives a faster writing and reading speed. 1Kohm resistor gives 3.3mA current and I don’t belive that 3.3mA can fry output mosfet, 10mA or 30mA current can cause some damage, but not a 3mA.

Maybe ssomeone can test and check my theory - and sorry for offtopic.


#6

If resistors are of influence on speed i would suspect that the software needs to do IO retries and that might influence the speed.


#7

As I just tested here on FEZ Cobra, it is 11 sec for 1000KB. It is still slow but it should not take 60 seconds for only 1MB. What kind of SD are you using?


#8

What equation are you using to determine the 5k Ohm resistance?


#9

Since it was mentioned; what technology do .netmf devices use for the SD interfaces? Open Collector or Push-Pull?


#10

One over tau omega c.

http://www.sengpielaudio.com/calculator-RC.htm

EDIT should be 1.5k not 5k


#11

I mostly use LRCF chart to check values but getting better values I use PSpice Student simulator.

And I can answer to my own question, sdcard module uses push-pull output type and simulation proves that open collector can not work.
I also checked processor registers and sdcard is configured to 4 bit mode, I think everything is correct but something makes is slow, maybe it is a filesystem? But this is software side not hardware, but different resisor values can affect speed. I even tried to remove all resistors and effect was terrible - writing speed drops drastically and G120 SOM has onboard pullups or uses cpu weak pullup resistors…
My first sdcard project was implemented with Pic24 (16bit, 24MHz , 4Kbytes ram) works with SPI mode (1bit) 4MHz sdcard clock has 100KB/sec writing speed, same as G120 module.

Next thing is check real communication between cpu and card, maybe this can give some explanation.
And guys, I don’t belive that netmf is so slow - at least framework internal modules can work pretty fast I think.


#12

Am I missing something. I don’t use pull up resistors at all on my G120 based board. The Cobra 2 doesn’t either according to the schematic. Am I doing something wrong?


#13

Same here, no resistors at all :wink:


#14

@ Ermo - Can you post the write code that you used that took 60 seconds to write to the SD card so I can try a few experiments here? If you do not want to post it publicly, you can post it to me directly. Also, what firmware version were you using if it was not previously mentioned?