Go Down

Topic: Has anyone timed how long it takes to write 2 bytes using the SD library? (Read 973 times) previous topic - next topic

Loudhvx

Just trying to determine if this will be fast enough for what i want to do. 
Up til now, I've been just writing to memory and serial-transferring to a laptop.  Obviously that means I can only log a small amount of data, then it has to stop while transferring the data to the laptop.  I end up with small, discrete chunks of data.

In order to get a large, continuous chunk of data, I've been considereing storage onto an SD card, but in all of my searches, I can't find any info on how long it would take to log 2 bytes of data. (Or even one byte.)

I assume SPI is faster than transferring at 9600 baud to the laptop.

Has anybody measured it? 

fat16lib

Doing a binary write of two byte can take as little as 40 microseconds or as long as 200 milliseconds.

It takes 40 microseconds if the data only needs to be moved to the buffer for the SD.

It can take 200 milliseconds if data is written to the SD and the SD needs to do a large flash erase or remap a bad spot.

Jack Christensen

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

fat16lib

If you open a file like in the above thread
Code: [Select]
logFile = SD.open("log.txt", FILE_WRITE);
writes will be incredibly slow.

You need to replace FILE_WRITE with other open flags.  FILE_WRITE causes 2048 bytes of I/O to the SD for each byte written by a print().

Search the forum for a description of other flags that you can or together.  These include O_WRITE, O_CREAT, O_TRUNC, and others.

sbright33

Could someone please specify the alternative which is faster? 
Of course it depends if you need to create the file first...
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

fat16lib

You can log 16-bit samples to an SD as fast as 40,000 samples per second.  This requires very special techniques, writing binary data to a contiguous file in raw mode.

You can log about 2,000 samples per second to an SD as text but this requires special buffering.

I have posted two demo sketches here http://code.google.com/p/beta-lib/downloads/list in the file fastLoggerBeta20110802.zip.

Several topics in this form discuss use of these sketches.

pito

..what is the total amount of data?? Kilobytes? Megabytes?
If ~kBytes you may consider an external fram (spi, 8pin, 256kBytes). You can write ~800KBytes/second, as a bonus it is nonvolatile.
P.

fat16lib

FRAM is great for data logging.  

Where do you find 256 KB (2 Mbit) SPI FRAM in an 8-pin package and what is the part number?

Mouser has 256 kbit parts in stock but this is only 32 KB. http://mouser.com/ProductDetail/Ramtron/FM25W256-G/?qs=sGAEpiMZZMtsPi73Z94q0IidxlBy6KhxDctIlbo1eg0%3d

When I log 16-bit data at 40,000 sps to a SD it uses 80 KB/sec.  I allocate 100 MB for a data-set which is 20 minutes.

pito


Loudhvx

Thanks for all of the replies.  So it looks like there are a lot of options with a wide range of speeds. 

My plan was to wire the card myself just using the resistor dividers as described.  As far as what library to use, I guess I'll just experiment with a few and see what I get. 

At least it seems one way or another, it should be able to do most of what I want.

Is there an inexpensive shield or other hardware that will make it significantly faster than just wiring the SD card directly to the Arduino?  Or is the resistor divider method about the same, as say, the Ethernet Shield?  (Using one of the common SD libraries.)

Go Up