Go Down

Topic: Fast sampling ADC (Read 5 times) previous topic - next topic


Jun 28, 2011, 07:35 pm Last Edit: Jun 28, 2011, 07:37 pm by bastukee Reason: 1
I'm currently trying to use the Arduino's ADC to sample a waveform that will be between 0V-5V and transmit the samples over serial so that it can be recreated on a PC running some plotting software. I would like to know how fast can I sample a waveform (1ms? 1us?) and be able if possible, to transmit this data real time. Another option would be to store about 8 seconds worth of sampling and transmitting such samples. How fast could I sample? I'm willing to use the fastest baud-rate possible to achieve this and if there is a better option than using the Arduino.

I could also use many Arduinos to do it too.
No trees were harmed by the transmission of this message. However a few million electrons were temporarily inconvenienced.

Coding Badly

I'm willing to use the fastest baud-rate possible to achieve this and if there is a better option than using the Arduino.


I would like to know how fast can I sample a waveform (1ms? 1us?)

Test to find out...

Code: [Select]
unsigned long Start;
unsigned short Count;

void setup( void )
  Serial.begin( 115200 );
  Start = millis();

void loop( void )
  if ( millis() - Start < 1000 )
    analogRead( 0 );
    Serial.println( Count );
    Count = 0;
    Start = millis();


The fastest you can sample is limited by the ADC clock, which can be as fast as the main clock frequency divided by 2, or 8 MHz. Now, at that sampling frequency your results will not be accurate! In addition, the datasheet says the ADC clock should not exceed 1 MHz (I'm guessing results will just be ridiculously wrong beyond that point). The "recommended" ADC clock frequency to meet datasheet parameters is 200 kHz or less (many of the ADC parameters are specified at 200 kHz). Another parameter of note is the "input bandwidth", which has a typical specification of 38.5 kHz so (according to Nyquist's theorem) there's no information beyond 77 kHz of sampling (though it is beneficial to sample faster than that if your signal truly does have spectral content up to 38.5 kHz).

OK, so with that out of the way, let's say you settle on 200 kHz, that means you are sampling data every 5 microseconds. That's way too fast for serial. At the 230.4 kbps baud rate and 8 bits per sample (throwing away the 2 LSB's of the 10-bit sample) you could transmit 23040 samples per second (10 bits per 8-bit data packet over serial) if your code was 100% efficient. So there's no need to even think about the 200 kHz sampling frequency number.

Storing data has a similar tradeoff. Assuming you use an Arduino Mega with 8K of RAM, set aside 1k for the C stack and other stuff, you could store (7*1024)/200,000 = 35.8 milliseconds worth of data at 200 kHz sampling rate.  If you want to store 8 seconds using 7k of RAM you will have to sample at 896 Hz.

Just some numbers to get you thinking.

The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected


I been using Microchip ADCs to sample signals and store the data on SD cards.

I have been able to record 12-bit data at 40,000 samples per second using a MPC3201 ADC.  A version of this sketch is here http://code.google.com/p/beta-lib/downloads/list in the file fastLoggerBeta20110623.zip.

I have used a MPC3001 to record 8-bit data at 80,000 samples per second and will post that sketch soon.

I have used the Arduino ADC to record 8-bit audio at 44,100 samples per second in this library http://code.google.com/p/waverp/.

It's not real-time but you can record data for long periods.


Jun 29, 2011, 07:22 pm Last Edit: Jul 01, 2011, 03:14 pm by robtillaart Reason: 1
With respect to the baudrate, the Arduino serial monitor can do 115200, but the arduino can do much faster. I have done some test with 230400 and 345600 baud (using putty.exe to capture the output on windows 7.  A dozen tests worked well for approx 24 hours per test without loss of data. -

@ 345600 you can send approx 15000 (2byte) samples per second!  - Give it a try

See also - http://arduino.cc/forum/index.php/topic,61381.msg444421.html#msg444421 -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up