# HELP!!! Problem with ADC sample interval timer

Hi,

I want to create an ADC using the arduino. I am setting the reference voltage to 0.5V to have a 10 bit resolution for a line-in audio signal. The signal will be coming into an analog pin that reads the value and stores it into an array. The time at which that sample was taken will also be stored into a different array. These values will be processed in pure data. All the arrays and setups have been completed before the adc function is called.

Heres my problem...

I know how to use a for loop, and reading values from the input into an array (I'm an intermediate C programmer). My sampling frequency is 40KHz which means the sample interval will be in the microseconds region. How can I go about writing an adc function that samples the time and amplitude values with a 25us interval? I'm assuming that there will need to be a delay between the analogRead() and storing operations.

Thanks for any help in advanced.

The minimum analog reference value is 1.0V. Not sure what it does if you try to use 0.5V.

You can't get 40,000 10-bit samples per second. To get 10-bit samples you have to keep the ADC clock below 200 KHz which will get you less than 16000 samples per second (13.5 cycles per sample). If you push faster than that the low-order bits will not be accurate.

The available clock divisors are 128, 64, 32, 16, 8, 4, and 2. These give the following clock speeds on a 16MHz Arduino: 128 -> 125 KHz -> 9,259 FULL 10-bit samples per second 64 -> 250 KHz -> 18,518 short samples per second 32 -> 500 KHz -> 37,037 short samples per second 16 -> 1 MHz -> 74,074 short samples per second 8 -> 2 MHz -> Not supported 4 -> 4 MHz -> Not supported 2 -> 8 MHz -> Not supported

johnwasser: The minimum analog reference value is 1.0V. Not sure what it does if you try to use 0.5V.

You can't get 40,000 10-bit samples per second. To get 10-bit samples you have to keep the ADC clock below 200 KHz which will get you less than 16000 samples per second (13.5 cycles per sample). If you push faster than that the low-order bits will not be accurate.

The available clock divisors are 128, 64, 32, 16, 8, 4, and 2. These give the following clock speeds on a 16MHz Arduino: 128 -> 125 KHz -> 9,259 FULL 10-bit samples per second 64 -> 250 KHz -> 18,518 short samples per second 32 -> 500 KHz -> 37,037 short samples per second 16 -> 1 MHz -> 74,074 short samples per second 8 -> 2 MHz -> Not supported 4 -> 4 MHz -> Not supported 2 -> 8 MHz -> Not supported

Ah thanks for the help. I guess I don't understand ADCs as much as I thought I did. How did you arrive at 9259 full 10-bit samples per second. Sorry to sound like a bit of a noob.

lukuss1: How did you arrive at 9259 full 10-bit samples per second. Sorry to sound like a bit of a noob.

To get 10-bit samples you have to use an ADC clock slower than 200 KHz. When the system clock is 16 MHz (like on the Arduino) the only way to get the ADC clock below 200 KHz is to use the "divide by 128" pre-scaler. To determine the sample rate you divide the ADC clock rate by 13.5: the number of cycles per sample in 'free running' mode where it takes successive samples as quickly as it can.

16,000,000 / 128 = 125,000 / 13.5 = 9259.259259...