Go Down

Topic: Log an analog pin at 100,000 sample/sec (Read 3419 times) previous topic - next topic

fat16lib

I have posted a sketch that can log data from the internal Arduino ADC at very high sample rates using an ISR to capture ADC values.

The sketch is posted as AnalogIsrLogger20120810.zip here http://code.google.com/p/beta-lib/downloads/list.

The sketch can log 8-bit ADC values at 100,000 samples per second.  The estimated accuracy is 7.3 ENOB.

The sketch  can also log 10-bit ADC values at over 30,000 samples per second with a reasonable accuracy (Estimated ENOB 9.3).  It can log 10-bit data at up to 60,000 samples per second with an estimated accuracy of 8.5 ENOB.

Very high quality SD cards with low write latency are required to achieve these rates.  Three SanDisk cards that work are shown in a photo included with the sketch.

Here is the readme file:
Quote

The AnalogIsrLogger.ino program demonstrates techniques for logging data to
an SD card at high rates by capturing data in a timer driven interrupt routine.

I have been able to log data at up to 100,000 samples per second using
AnalogIsrLogger.ino.  This requires an excellent SD card. See SD_CARDS.JPG
for photos of cards that have worked at 100,000 8-bit samples per second.

Example data is shown in DATA.PNG and it's FFT is in FFT.PNG.  See ExcelFFT.pdf
in the ADCdocs folder.

The accuracy of the ADC samples depends on the ADC clock rate.  See the
ADC_ENOB.PNG file for a plot of accuracy vs ADC clock frequency.

See files in ADCdocs folder for more information on ADC accuracy.

To modify this program you will need a good knowledge of the Arduino
ADC, timer1 and C++ programming.  This is not for the newbie.

You may need to increase the time between samples if your card has higher
latency.  Using a Mega Arduino can help since it has more buffering.

I have an LED and resistor connected to pin 3 to signal data overruns.
You can disable this feature by setting the pin number negative:

// led to indicate overrun occurred, set to -1 if no led.
const int8_t RED_LED_PIN = 3;

These programs must be used with a recent version of SdFat.  The program
was developed using sdfatlib20120719.zip from:

http://code.google.com/p/sdfatlib/downloads/list

You also need to install the included BufferedWriter library.  It provides
fast text formatting.

Place these three folders in your sketchbook libraries folder.

Place the AnalogIsrLogger folder in your sketchbook.

The program has four commands:

c to check for overruns
d to dump data to Serial
r to record ADC data
t to convert file to text

All commands can be terminated by entering a character from the serial monitor.

The r command will record ADC data to a binary file.  It will terminate
when a character is entered on the serial monitor or the the maximum file
block count has been reached.

The d command converts the binary file to text and displays it on the serial
monitor.  Entering a character on the serial monitor terminates the command.

The t command converts the binary file to a text file.  Entering a character
on the serial monitor terminates the command.

The c commands checks the binary file for overruns.  Data overruns happen when
data samples are lost due to long write latency of the SD.

A number of program options can be set by changing constants at the beginning
of the program.  Key settings include:

// set RECORD_EIGHT_BITS nonzero to only record high 8-bits
#define RECORD_EIGHT_BITS 1

// Sample rate in samples per second.
const uint32_t SAMPLE_RATE = 100000;

// Analog pin number
const uint8_t ANALOG_PIN = 0;

// digital pin to indicate overrun, set to -1 if not used
const int8_t RED_LED_PIN = 3;

// SD chip select pin
const uint8_t chipSelect = SS;

// max file size in blocks
const uint32_t FILE_BLOCK_COUNT = 256000;

// log file name
#define FILE_NAME "LOGFILE.BIN"

// Reference voltage
uint8_t const ADC_REF_AVCC = (1 << REFS0);






CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Wow, this is really tremendous!  I started my first arduino project and first coding since 1988.  I've been learning tons from the forums and building on BG's achievements using your latest analog logger and just tried out this new speed demon sketch and it is working beautifully! 


The interface is much appreciated as closing and reopening the serial window was tolerable, minor nuisance.  Also, the ability to not record a data set is really smooth.

Thanks!!

m_ri

seeing your high level of expertise,i've a theoretical question: when i transfer data from/to  arduino,where is a fast way to transfer data using SD card mode(with only one data line,because arduino doesn't support parallelization), or it could have only the maximum speed of SPI mode?
thank you for your time  :)

Hello;

My very first comment (no original posts yet) on arduino forums, so obviouslly a little new to arduino.

I have a question regarding this, did you use a datalogging shield, would it be the ladyaga shield?

thank you in advance

Jon


I obviouslly mean the LadyaDa shield!  :)

PaulS

Quote
I obviouslly mean the LadyaDa shield!

I'm pretty sure you don't, I'm relatively certain you mean the LadyAda shield. A google search for exactly who Lady Ada was would prevent you from ever making that mistake again.

Thanks Paul, really helpful...

If anyone knows which shield was used, or I should think of using in this project, would be really grateful to know.



Tbowboy3


Thanks Paul, really helpful...

If anyone knows which shield was used, or I should think of using in this project, would be really grateful to know.





jonergeno, I think 'fat16lib' developed most of this stuff using the AdaFruit (Lady Ada) Wave Shield ( http://www.adafruit.com/products/94 ).  However, (like you) I'm currently working with his sketch on the Adafruit Data Logger Shield ( http://www.adafruit.com/products/243 ) and its working great (using a "SanDisk Ultra SDHC" for my SD card, available at radio shack http://www.radioshack.com/product/index.jsp?productId=3353509 )

GoForSmoke


sbecause arduino doesn't support parallelization


Are you including direct port manipulation and excluding Mega's and internally clocked 328's?

You can do 6 bit parallel on a stock UNO. But you can do clock/8 per byte SPI *bus* that many chips and devices can share.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Go Up