Fast sampling ADC

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.

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

Teensy...
http://www.pjrc.com/teensy/

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

Test to find out...

unsigned long Start;
unsigned short Count;

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

void loop( void )
{
  if ( millis() - Start < 1000 )
  {
    analogRead( 0 );
    ++Count;
  }
  else
  {
    Serial.println( Count );
    Count = 0;
    Start = millis();
  }
}
1 Like

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

1 Like

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 Google Code Archive - Long-term storage for Google Code Project Hosting. 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 Google Code Archive - Long-term storage for Google Code Project Hosting..

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

1 Like

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 - Fast communication to PC with low Arduino footprint - #12 by robtillaart - Networking, Protocols, and Devices - Arduino Forum -

If you need 10 bit resolution, the Arduino ADC is a key limit. For full resolution on a 16 MHz CPU, the maximum ADC clock is 125 kHz. It take 13 cycle for a conversion so you are limited to about 9,600 conversions per second.

It will be much less than that if you include Serial overhead.

RuggedCircuits:
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.

There seems some confusion here - the ADC does not sample at the ADC clock rate. It takes something like 13 ADC clock cycles to convert one sample (one clock for each result bit and some setup-overhead). An ADC clock of 200kHz means max sample rate around 13kHz. The default arduino setting is ADC clock = 125kHz, so about 100us per conversion. This is about 100kbit/s, just beyond the capability of serial with baud rate of 115200.

The datasheet suggests using an ADC clock of 50kHz to 200kHz for good results.

This is about 100kbit/s, just beyond the capability of serial with baud rate of 115200.

As stated above baudrate can go 3x higher, but that still leaves a gap of a factor 3-4. So you should investigate if the signal can be compressed if you want to send it over serial.

If the signal does not change fast or often runlength encoding can be interesting. Note with the help of a local buffer "peaks" of fast changes can be handled too.

If signal does change often but not by a big amount consider sending the delta in one signed byte. Keep one value free for "here comes a new 16 bits value" flag

Thank you all for the information provided!

I have to say I will need to attack this on a different approach than I initially intended. This is what I'm trying to do...

A signal comes in, which will be between 0V and 5V. The signal is between 1ms and 5ms long. I would be sampling this as fast as possible, storing the values and later sending them over a wireless serial radio. So the main thing then would be a way to store as many samples as possible during that short amount of time. If the Arduino could simply store those samples in it's memory then great! But I think it is beyond it's memory capacity, but I could use external EEPROM to store the information and send it after the signal has finished. How fast could I sample then if I don't have to worry about the baud rate, only storing on EEPROM ?

I see you guys mention how fast the ADC on the Arduino samples, I was not aware that you could manipulate the sampling rate of the ADC on the Arduino, any light on this?
I also like the idea of a faster baurdrate to help do most of this on a real time basis, I might end up doing this on a separate project for signal detection.

EEPROM is slow - store it in much faster SRAM instead, then transfer to EEPROM at your leisure if you want to keep it long term.

http://ww1.microchip.com/downloads/en/DeviceDoc/22127a.pdf as an example

Digikey has a bunch

You'll have to do some level shifting due to 3.6V, I think 74AC125 like on a SD card interface can handle that for you.

@Crossroads

That SRAM chip might just do it for me!

After I get some SRAM, I could just do some simple code to read and write over SPI as fast as possible for say 5ms and see how many times it does it. I wonder how you guys manipulate the sampling rate of the Arduino's ADC? If this even helps...?

"I wonder how you guys manipulate the sampling rate of the Arduino's ADC? If this even helps...?"
Did you take a look at link in reply #3? Bet there are some answers there.

Sample Rate (from the Prescaler) can be up to the Maximum, but with loss of Resolution Bits

  • No damage done of course ... somebody posted this ridiculous statement/question somewhere.

__ADC_Freq_ResolutionBitErrors_Test1_Graph.jpg

ARDUINO ADC Speeds (with 16MHz Clock) :

 Speed: PreScaler: Time: Freq: ActFrq: BitsRes:
 
 120KHz 128 116us 9.6ksps 9.6ksps 10b
 240KHz 64 60us 19ksps 19ksps 10b
 500KHz 32 36us 38ksps 38ksps 10b
 1MHz 16 20us 77ksps 50ksps 9b
 2MHz 8 13us 154ksps 77ksps 8b
 4MHz 4 9us 308ksps 111ksps 6b
 8MHz 2 7us 615ksps ? ?


ARDUINO ADC Speeds (with 20MHz Clock) :

 Speed: PreScaler: Time: Freq: ActFrq: BitsRes:
 
 1MHz 16 90ksps 9b
 2MHz 8 170ksps 8b
 4MHz 4 350ksps 6b
 8MHz 2 615ksps ?


ARDUINO ADC Speeds (with 32MHz Clock) :

 Speed: PreScaler: Time: Freq: ActFrq: BitsRes:
 
 1MHz 16 150ksps 9b
 2MHz 8 300ksps 8b
 4MHz 4 600ksps 6b
 8MHz 2 1.2Msps ?

Good explaination here:

5Msps (yes 5Mega) using Ca3306 with Arduino:

References (great High Speed ADC directions for AVR/Arduino) :

http://www.microsmart.co.za/technical/2014/03/01/advanced-arduino-adc/
http://frenki.net/2013/10/fast-analogread-with-arduino-due/

__ADC_Freq_ResolutionBitErrors_Test1_Graph.jpg

Check the dates on posts jlsilicon - this topic is >5 years old.

CrossRoads:
Check the dates on posts jlsilicon - this topic is >5 years old.

Yes, but, there are still fools like me who hit on these [via a search] and find them useful. It's not just about the OP :wink:

1 Like