Pages: [1]   Go Down
Author Topic: Has anyone timed how long it takes to write 2 bytes using the SD library?  (Read 871 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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? 
Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1605
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 93
Posts: 3980
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did some timings, not two bytes, but this thread may be of interest:

http://arduino.cc/forum/index.php/topic,61662.msg445739.html#msg445739
Logged

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

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1605
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you open a file like in the above thread
Code:
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.
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could someone please specify the alternative which is faster? 
Of course it depends if you need to create the file first...
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1605
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2066
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

..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.
« Last Edit: October 20, 2011, 04:51:18 pm by pito » Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1605
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: October 20, 2011, 06:18:07 pm by fat16lib » Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2066
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

FM25H20
http://www.ramtron.com/products/nonvolatile-memory/serial.aspx
I am using it so I can confirm it works as advertised. P.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.)
Logged

Pages: [1]   Go Up
Jump to: