New sketch logs 40,000 samples/sec

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
fat16lib
 
Posts: 595
Joined: Wed Dec 24, 2008 1:54 pm

New sketch logs 40,000 samples/sec

Post by fat16lib »

I have posted several new programs to log data at high speed http://code.google.com/p/beta-lib/downloads/list.

The file is fastLoggerBeta20110623.zip. It includes the following programs:

binaryLogger.pde - Read from a 12-bit MCP3201 ADC and log the data to a binary file.

fastLogger.pde - Read from analog pin zero and log the data to a text file.

mcpLogger.pde - Read from a 12-bit MCP3201 ADC and log the data to a text file.

The fastest logger, binaryLogger.pde, can log 40,000 samples per second with high quality SD cards.

I have been using the new 4GB SanDisk Extreme 30MB/sec HD Video cards.

frankstrudel
 
Posts: 2
Joined: Fri Jul 08, 2011 8:28 am

Re: New sketch logs 40,000 samples/sec

Post by frankstrudel »

Hi. Is it the separate ADC you've used that has allowed the 40kS/s rate? Without the ADC, just logging from analog pins, is 2kS/s the highest it can go?

I'm hoping to get at least 4kS/s from three analog inputs to an SD card in the adafruit datalogger shield, so I'm just wondering whether I could do that straight from analog pins or whether I need to find some other ADC's?

Thanks!

User avatar
fat16lib
 
Posts: 595
Joined: Wed Dec 24, 2008 1:54 pm

Re: New sketch logs 40,000 samples/sec

Post by fat16lib »

There are two factors, the ADC and the SD card.

The Arduino ADC takes about 110 microseconds to do a conversion and the MCP3201 takes 9 microseconds.

The SD card must have low write latency or samples will be dropped.

I mostly use 4 GB SanDisk Extreme 30 MB/sec cards with binaryLogger.pde. These cards are optimized for the multiple block raw write commands that I use in binaryLogger.pde.

For ordinary file I/O operations, the SanDisk Extreme cards are slower than cheaper cards. They are not optimized for the single block write mode that SdFat uses for file I/O operations.

I can get 4,000 - 5,000 samples per second using analogRead in the fastLogger.pde sketch with a cheaper SanDisk card. fastLogger.pde uses ordinary file I/O.

This is with the 20110705 version http://code.google.com/p/beta-lib/downloads/list.

binaryLogger.pde will not work well with the slow Arduino analogRead.

A MCP3204 would be a good choice since it has four inputs. You should be able to log 4,000 samples/sec with three 12-bit channels in each sample.

frankstrudel
 
Posts: 2
Joined: Fri Jul 08, 2011 8:28 am

Re: New sketch logs 40,000 samples/sec

Post by frankstrudel »

Great! Thanks for your help and recommendations!

User avatar
fat16lib
 
Posts: 595
Joined: Wed Dec 24, 2008 1:54 pm

Re: New sketch logs 40,000 samples/sec

Post by fat16lib »

Here is an update with information from people using binaryLogger.pde.

With a Mega you can use cheaper SD cards. I allocate 12 buffers on the Mega which allows an occasional write latency of about 70 milliseconds. This assumes two byte samples at 40,000 samples/sec.

I rejected the cheaper cards because the have a few very long write latencies when they are new. It appears this is due to remapping bad blocks. Guess they are not "burned in". They actually get better with use.

I have been able to use these cards successfully on the Mega after they have been used for a while:

The label on my card is more yellow.
http://www.amazon.com/Transcend-Class-S ... 982&sr=1-3

http://www.amazon.com/AmazonBasics-Clas ... 136&sr=1-1

Both cards a re-branded generic cards so there is no guarantee they will be the same internally in the future.

So:

The SanDisk 30MB/sec cards work on 328 Arduinos. This requires write latency to always be less than six milliseconds. Even these cards seem better after use.

Cheaper cards often work on Mega Arduinos. Cards can have an occasional write latency of 70 milliseconds. Cheap cards must be "burned in".

If cost doesn't matter, use a Mega with the 30MB/sec SanDisk card. This will be the most reliable combination.

abshafique
 
Posts: 3
Joined: Wed Mar 26, 2014 3:01 am

Re: New sketch logs 40,000 samples/sec

Post by abshafique »

Hi fat16lib,
I was wondering, could things be made better by the use of a DUE? I have a very specific situation where I want to control a quadrotor using an LQG type controller that I would like to design in MATLAB. Additionally I want the IMU readings and control commands to be saved on the datalogger for later analysis. Since the DUE boasts a DMA do you think that could be utilized to make sure the write delay of 70ms doesn't kill my loop that is running at a sample time of 5ms?

Any help would be much appreciated.

User avatar
golinaveenkumar
 
Posts: 4
Joined: Fri Aug 15, 2014 9:01 am

Re: New sketch logs 40,000 samples/sec

Post by golinaveenkumar »

Hi fat16lib,
I want to read the data from one channel and write to SDcard .Iam using Arduino UNO + Adafruit Data Logger Shield. I tried the basic datalogger, but the samples are only 75-80 samples per second. But i need in kHz for vibration recording. By searching in the internet, i came to know 40 khz is possible with arduino.I downloaded the Fat16 lib and copied in arduino programfiles library. When i opened and compiled the example program of fastLogger (i.e, fat16Analoglogger), it is showing Error in compiling like i showed below.
Can you suggest a solution


C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp: In constructor 'RobotControl::RobotControl()':
C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'LCD_CS' was not declared in this scope
C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'DC_LCD' was not declared in this scope
C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'RST_LCD' was not declared in this scope
C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp: In member function 'void RobotControl::begin()':
C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXA' was not declared in this scope
C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXB' was not declared in this scope
C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXC' was not declared in this scope
C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXD' was not declared in this scope
C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:19: error: 'MUX_IN' was not declared in this scope
C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:22: error: 'BUZZ' was not declared in this scope
C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:25: error: 'Serial1' was not declared in this scope

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: New sketch logs 40,000 samples/sec

Post by adafruit_support_bill »

C:\Program Files\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:
This is a known problem with Arduino release 1.0.5. It tries to use the Robot_Control libraries when it should not. There are 2 remedies:
1 - Use 1.0.4.
or -
2 - Delete the Robot_Control folder from your Arduino install.

User avatar
golinaveenkumar
 
Posts: 4
Joined: Fri Aug 15, 2014 9:01 am

Re: New sketch logs 40,000 samples/sec

Post by golinaveenkumar »

Thanks for quick reply
I deleted robot control folders and compiled. No errors this time.
Bu it was not logging.
But in the serial monitor it is showing SD error 2. What is the problem and what is the solution?


Type any character to start
error: card.init
SD error: 2

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: New sketch logs 40,000 samples/sec

Post by adafruit_support_bill »

Run the 'cardinfo' sketch. It has more diagnostic information.

User avatar
golinaveenkumar
 
Posts: 4
Joined: Fri Aug 15, 2014 9:01 am

Re: New sketch logs 40,000 samples/sec

Post by golinaveenkumar »

Thank you,
iam using Sandisk 4GB SDHC card. It is in FAT32. When i tried the cardinfo program in SD library,its working fine. But when i run fat16info in fat16 library it was showing an error as mentioned in last post. I searched and found out that SD card should be in FAT16 and the maximum allowable size for it is up to 2GB only. Then i partitioned it with some other software(Partition wizard free partition manager software.) and checked in computer, it is showing FAT. Even then when i uploaded the fat16info, in the serial monitor it is showing the same error like this

Fat16 version: 20111205
FreeRam: 1261

type any character to start
card.init failed
SD error
errorCode: 2
errorData: 1

type any character to start


Kindly suggest the suitable solution. Thank you.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: New sketch logs 40,000 samples/sec

Post by adafruit_support_bill »

Don't partition the card. You want a straight FAT16 format using the SD Association fomatter: https://www.sdcard.org/downloads/formatter_4/

User avatar
golinaveenkumar
 
Posts: 4
Joined: Fri Aug 15, 2014 9:01 am

Re: New sketch logs 40,000 samples/sec

Post by golinaveenkumar »

I formatted the SDHC card with formatter_4 as you specified. But it is showing the same card error.
I have some questions. Plz answer it

1. Does File system must be in FAT16 if i want to use fat16lib? or it can be in FAT32.
2. Is there any size limitation?
3. I downloaded the fat16lib20111205 file from internet and copied Fat16 folder(inside fat16lib20111205) in c/programfiles/arduino/libraries. Is this the correct way?
4. Do i need to change any code elements specific to my requirement,(like chip select etc)

Kindly answer these questions. I am in urgent need to complete this project.
Thank you

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: New sketch logs 40,000 samples/sec

Post by adafruit_support_bill »

Please read through the posts by fat16lib above. This is experimental code and has some limitations regarding card compatibility.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”