Arduino Uno R3_Sampling of Analog Input

Pls explain how to get the sampled values of a sine or any analog signal of particular frequency using Arduino Uno R3 board with ATMEGA 328P PDIP. I want to sample a sine wave of amplitude 500mV and frequency 40Khz. However Analogread() doesn't give the expected results.How to get the precise mV amplitude values?

Also if I have to use the ADC in free running mode and configure the registers,then how do I read the values of ADC Data registers.Pls help me.I'm Stuck

Someone pls suggest me an external arduino ADC module so that I can sample at 80 Khz

There's a code example for direct memory access of the A/D here: FHTExample - Open Music Labs Wiki

Sampling a 40 kHz signal with an Atmega328 is pushing beyond the design limits of the device, so you might consider going with a more capable microcontroller like one of the ARM M3 boards (e.g. Due). There is information on the effects of pushing the Atmega328 sampling rates as high as you apparently need here: ATmega ADC tutorial | Open Music Labs

If you describe the nature of your project (I'm guessing ultrasonic sampling) you might get better advice.

Thanks Mark for the information.I was able to hack received signal from HCSR04 Ultrasonic sensor.The received signal is at 40Khz with varying amplitude as shown in the image.I would like to sample this data.Pls help.I want to know as to how such a wave can be sampled.Thanks a lot for your response.

hcsr04 sensors_received waveform.png

Also if I use array of sensors,how can I process all the data at the same time.Sample from all the ADC channels simultaneously. Pls help

You can not sample all inputs at the same time when using a 328 micro-controller. There is a multiplexer in front of the ADC.

Arya123:
I want to sample a sine wave of amplitude 500mV and frequency 40Khz.

The max ADC sample rate for an Atmega 328 is 15,000 per second at max resolution and 76,000 at lower resolution - and that assumes that there is no requirement to change channels.

I can't see those sample rates being suitable for your needs. You could consider a faster external ADC chip. But you should also keep in mind the very limited amount of SRAM on an Arduino where sample data can be stored.

...R

I don't think the Uno R3 is appropriate for what you're proposing.

  1. I'm currently building an audio four receive channel phased array using an STM32 board which has a two 1 megasample/s A/Ds and a DMA controller. The latter is important to get uniform sampling at these sorts of sample rates. There is some Arduino support for these boards, but to use these peripherals at speed will require some challenging low level configuration that is well beyond "analogread()".

  2. The last amplifier stage of an HC-SR04, if that's what you're using, is typically driven to saturation (i.e. logic levels 0 and 1) and can be sampled with a Uno R3 digital input. Think of it as an array of 1 bit A/D converters. With direct register manipulation you can simultaneously sample multiple inputs on a single port and can do so at a very high rate relative to 40 kHz. That should be sufficient to do some level of channel relative phase against a sufficiently strong transmitter. I did this sort of thing a while back while experimenting with phase or frequency modulated ultrasonic data transmission.

Thanks Mark for the information.However I don't understand the second part of your explanation.

It reads like this ................"can be sampled with a Uno R3 digital input. Think of it as an array of 1 bit A/D converters. With direct register manipulation you can simultaneously sample multiple inputs on a single port and can do so at a very high rate relative to 40 kHz."

Pls explain how to sample the echo signal or saturated amp o/p(Rx-d Signal)from HCSR04 using arduino.
Thanks a lot :slight_smile:

Also pls suggest some high speed external ADC with sufficient memory to sample and store the data.

Thanks a lot :slight_smile:

The following link has a schematic and signal capture for a typical HC-SR04 (there are a couple variants): https://uglyduck.ath.cx/ep/archive/2014/01/Making_a_better_HC_SR04_Echo_Locator.html

The received signal as presented to the microcontroller on the HC-SR04 is identified on the schematic as "Signal".

With modest soldering skills, it's possible to add a wire to the "Signal" net of the circuit (e.g. pin 10 of the OTP microcontroller) and read it using an Arduino digital input pin with an Arduino "digitalRead()". "digitalRead()" on an Uno takes about 4 microseconds, so this can be done at something approaching 250,000 samples/second. It can be done even quicker by using direct port manipulations rather than the "digitalRead()" functino.