Hi Gabriel,
The link you posted is very old and all the issues have been already
solved almost two years ago. I guess that most of your questions may be
answered by looking here:
https://github.com/arduino/Arduino/issues/1418
Atmel has changed the datasheet. I'm 100% sure that the maximum rated
frequency was 20MHz.
I'm not sure what to think now: the new SAM3X chip may run ADC at 22Mhz?
or maybe Atmel did more tests and discovered that 22Mhz was good also
for the old chips? or maybe is just an error in the datasheet?
> ADC_STARTUP_NORM is 40. This doesn't make sense at all. Pg. 1334 shows
> valid values are 0 through 15 (0 through F in Hex for that nibble, bits
> 16-19, in the REG_ADC_MR)
The adc_init() function writes the correct value into the register,
according to the datasheet conversion table.
This is the fix I've applied at the times
https://github.com/arduino/Arduino/commit/40dce96f1173dfba5f667b0c289687ac3d92506b
> ADC_STARTUP_FAST is 12. How is this fast at all??? Per datasheet pg.
> 1334, 12 --> 768 pds of ADCClock, which is 1/21MHz x 768 = 36.57us. That
> is one of the slowest startup options available. Shouldn't we use
> something more like 2 for the startup value instead?
>
> Why such a long startup?
Because it's needed for the ADC to work properly (see the github's issue
above for details...)
> With startup of 12, the first link above, by djerickson, says each
> analogRead() in a tight loop takes ~39us. 36.57us of that is the ADC
> startup time. If we change ADC_STARTUP_FAST to 2 we'd get each sample
> down to ~4us, which is much much better.
The good news (that is not written on the djerickson website) is that if
the ADC is kept enabled the startup time is applied only to the first
conversion and all the subsequent conversion are much faster
(approaching 1Msps, but the 84MHz clock of the Due's setup allows only
700Ksps maximum, again see the issue linked at the beginning to
understand why).
At the time when djerickson wrote his article, the analogRead() function
used to enable and disable ADC every time, so the startup time was
applied at every conversion. The correct fix is to leave the startup
time as is and keep the ADC enabled in analogRead(), and this is the fix
we applied on the Due.
Just reducing the startup time as suggested in djerickson's article may
lead to ADC not working properly.
C
--
Cristian Maglie <
c.ma...@arduino.cc>