# DUE analog sequencer : how to know sample speed[UPDATED]

Hi.

I'm working in a version 2.0 on the analog sequencer of the arduino DUE. v2.0.

One of the last thing I want to do is to be able to print the frequency for each set of conversion. I tried to find it on the data sheet, but the only thing I can find is the ADC clock : MCK / 2(prescaler+1).
So ADC clock is between 164KHz and 48Mhz.

But I'm unable to find how many cycle it take for each conversion. Then I suppose that this time have to be multiply by the number of channel active...

example, if A0, A6 and A8 are active and it take each 50 cycle for a conversion, if ADC clock is 164KHz, it gave a total frequency of 164k/(3*50)= 1.093KHz...

Am I on the right way there ?????

Thank...

[EDIT --> UPDATe]

Ok, after further test, I put a micros() counter into the interrupt routine and find out:

a constant result seem to emerge: sample rate seem to be prescaler /2 * numbber of analog channel active in micro seconde... (weird timing... but seem fit... may be related y the fact that 84MHz is near 100... don't know...)

if prescaler is on 255, it need 128~usec for each channel.
64 usec at 128 prescacler, and 32usec at 64.

note that at prescaler 0, if all channel enable, it took 7usec per conversion but, even to ground, I was reading 24bits instead of 0... so very imprecise...

also at 0 prescaler, if only one channel enable, serial don't even work. I believe because ADC interrupt to often.

This is where I'm now... if some one have something to add to... please you're welcome.

[EDIT #2] More test have been done.

Fist I did not find another method to check the sample rate that use of micros(). At that speed, it have a not much precision but I still have some result to share.

First thing I have done was to check if the micros routine into the ISR have any effect into the measurement of the timing. To do that, I check, I try different ADC setup with 1, 2 and 3 identical micros() counter. I did not change the time by even a usec... so not significant.

Then, I opened a excell sheet and I start calculating number:

-I calculate what should be ADC_clock,

• then, for each channel, what is the period of each clock cycle.

Then I stard the arduino, start to note how much time it take for each ISR pass with different number of active channel and at step of 50it of prescaler.

In the excell sheet, I divide the result by the number of channel, to have the result by channel.

Then, I divide this time by the period of ADC_CLKs.

It result, with limit in precision: at very low prescaler (5 and bellow), 18 or 19 clock cycle per adc transfer.

But with higher prescaler, result are a bit more consistent, around 20.5 to 20.9 ADC_CLK.

So, with all the number in mind, the observation of the relation with the prescaler and the time for each transfer per channel is even more clear:

E.g.: At 200 prescaler, each conversion take approximately 100.286usec with 7 channel and 100.357usec with 14.

and this relation hold until 25 prescaler.

So in the library, I will add a function that give the approximated sample frequency by rounding at prescaler/2 the period of each transferred channel.

Not as perfect as I would have wished, but floating point calculation have also limit in precision at 32bit, so...

Assuming that timing is also good on micros() reading, in perfect world, with those number, the real frequency would be: 711Hz for 14 channel.

If I use the shortcut formula it gave : prescaler/2 numChannel : 1/(200/ 2 14) =714H

Seems close enough for an estimate...

Update library on github soon!

Regards!

Nitrof