Pages: [1]   Go Down
Author Topic: Log an analog pin at 100,000 sample/sec  (Read 3218 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1658
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);




Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27372
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Dang, cranking!
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
God Member
*****
Karma: 9
Posts: 550
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I obviouslly mean the LadyaDa shield!  smiley
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50452
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4816
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Pages: [1]   Go Up
Jump to: