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.
-
1If you have an oscilloscope or frequency counter, toggle a pin at each conversion and measure the frequency with your 'scope (and multiply by two).Spehro 'speff' Pefhany– Spehro 'speff' Pefhany01/18/2017 22:07:43Commented Jan 18, 2017 at 22:07
-
Hi! Why I must multiply it by two?Augusto Bonelli Toro– Augusto Bonelli Toro01/19/2017 14:00:45Commented 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.Spehro 'speff' Pefhany– Spehro 'speff' Pefhany01/19/2017 14:05:12Commented Jan 19, 2017 at 14:05
2 Answers 2
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:
- Set up an interrupt vector for the ADC peripheral (in this case support for ID37).
- Setup ADC registers (res, clock etc)
- Set up a timer to time the conversion.
- Create Active flag and Timer variables for processing inbound timer values.
- Start timer and ADC conversion.
- 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
- Waiting for Interrupt.
- In peripheral ISR, read and store timer value, reset timer, set active flag
- 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.Dave Tweed– Dave Tweed01/13/2017 05:04:35Commented Jan 13, 2017 at 5:04