I know that the ADC on the Arduino Due has a clock speed from 1 MHz to 20 MHz. I have two questions: 1. What is the default clock speed when I run a sketch, and 2. How can I change it? (I am using Arduino 1.6.4.)
The reason why I want to slow down the ADC as much as possible is to obtain the maximum source impedance. Is this logic correct? (i.e., if I slow down the ADC in the arduino code to kHz values, then the source impedance will reach MΩ values?) enter image description here
2 Answers 2
You can change the prescaler (ADCSR
register). Lowest scaler is 2, so it can never run at 20mHz. Also Atmel recommends a max ADC clock of 1MHz.
Arduino sets the ADC clock to 125 KHz (prescaler of 128)
So to match Arduino, you should select a prescaler of 8 ( set bits ADPS1
and ADPS0
)
-
Interesting. Where may I find the ADCSR register? Also, what's the highest prescaler possible? The reason why I want to slow down the ADC as much as possible is to obtain the maximum source impedance. Is this logic correct? (i.e., if I slow down the ADC in the arduino code to kHz values, then the source impedance will reach MΩ values?)David Roberts– David Roberts06/17/2015 20:55:58Commented Jun 17, 2015 at 20:55
-
1@Gerben Are you sure that holds true for the Due (ARM) or just for an Uno/Mega/Leonardo (AVR) as
ADCSR
sounds suspiciously like an AVR register name and not like an ARM one.Tom Carpenter– Tom Carpenter06/17/2015 22:45:30Commented Jun 17, 2015 at 22:45 -
@David Look for
system\libsam\include\adc.h
,system\libsam\include\adc.c
, andvariants\arduino_due_x\variant.cpp
in the IDE directory. I am not sure of the exact paths as I have 1.5.1, not 1.6.1 and they've probably changed since then. But the first two have all the access routines for the ARM ADCs. The final one shows how they have initialised it. You will notice they initialise it toADC_FREQ_MAX
which is defined in adc.h to be 20MHz.Tom Carpenter– Tom Carpenter06/17/2015 22:57:02Commented Jun 17, 2015 at 22:57 -
@TomCarpenter you are right. This doesn't work on the Due. ATMega only.Gerben– Gerben06/18/2015 15:23:59Commented Jun 18, 2015 at 15:23
The atod clock is set in the mode register. The clock is 42MHz/(PRESCAL#+1). One way of setting it is the use ADC->ADCMR = ADC_MR_PRESCAL(PRESCAL#), where PRESCAL# is some integer. These symbols are defined in component_adc.h in the Arduino source code. In the AVR data sheet, the recommended clock is MIN=1MHz, MAX=20 MHZ, corresponding to numbers between 41 and 1. Look in the data sheet, section 43.
-
I cannot find where the PRESCAL value is defined by the Arduino framework, do you have the link somewhere? :)Zorglub29– Zorglub2910/07/2020 09:07:59Commented Oct 7, 2020 at 9:07
-
Sorry, think I found it: #define ADC_MR_PRESCAL(value) ((ADC_MR_PRESCAL_Msk & ((value) << ADC_MR_PRESCAL_Pos))) available here: android.googlesource.com/platform/external/arduino-ide/+/… . But not very sure how this should be understood.Zorglub29– Zorglub2910/07/2020 09:10:01Commented Oct 7, 2020 at 9:10