# Measuring ADC sample rate - Arduino DUE

I want to measure the conversion rate of an arduino DUE. I know I could just take it from the datasheet but I need to measure it because I am running the ADC in free running mode. Hints are welcome, I really don't know where to start.

• If you have an oscilloscope or frequency counter, toggle a pin at each conversion and measure the frequency with your 'scope (and multiply by two). Jan 18, 2017 at 22:07
• Hi! Why I must multiply it by two? Jan 19, 2017 at 14:00
• Because toggling will give you one change- one 'edge'- per conversion and you need two edges to make a complete cycle, so the toggling acts as a divide-by-two flip-flop. Jan 19, 2017 at 14:05

I think using an interrupt controlled measurement might provide the best results for you.

Note: you might get more complete feedback using the Arduino forum.

In general the process would look like this:

1. Set up an interrupt vector for the ADC peripheral (in this case support for ID37).
2. Setup ADC registers (res, clock etc)
3. Set up a timer to time the conversion.
4. Create Active flag and Timer variables for processing inbound timer values.
5. Start timer and ADC conversion.
6. Loop waiting for active flag to set (it gets set in the ISR), when detected do average or store timer values, then clear active flag.

This methodology times each individual conversion using a high speed timer, which could mean a lot of values to process. You could equally not time each conversion, but simply set up say a 1 second timer, and count the total number of conversions in 1 second for your particular ADC configuration.

Peripheral ISR

1. Waiting for Interrupt.
2. In peripheral ISR, read and store timer value, reset timer, set active flag
3. Return from ISR

To expand on Jack Creasey's answer, timestamping the samples as they are taken is the most direct way to do it. If you have a block of N samples, the average sample period is simply

$$\frac{Time_{last} - Time_{first}}{N - 1}$$

(Note that there are N-1 time intervals between N samples.)

If you want the sample rate, just invert the expression:

$$\frac{N - 1}{Time_{last} - Time_{first}}$$

However, you can also infer the sample rate from a known signal. For example, you can feed a tone signal into the ADC and count the number of samples between some well-defined feature of the waveform, such as rising zero crossings. If you count N samples, then the sample rate is N times the tone frequency. Averaging over multiple cycles of the tone will give you a more precise measurement.

• Apparently MathJax is not enabled here. Jan 13, 2017 at 5:04