

The clock frequency is selected in ADCSRA and is set at ÷16 in this example. In this case the internal 1.1 volt reference voltage and the analog input channel ADC3 is selected with ADMUX. A detailed description of these registers can be found in the ATMEGA328 datasheet.
Arduino analog to digital converter free#
To setup the free running mode three registers must be configured: ADMUX, ADCSRA and ADCSRB. Every time a conversion is finished an interrupt is generated that calls the interrupt routine ISR(ADC_vect) wherein the ADC-result can be read and processed. In this mode the ADC conversion starts automatically after the previous one. The ATMEGA328 can be configured into a free running mode. When a signal must be sampled continuously, it's a good idea to set this up with interrupts. And this means polling the flag in a loop, and is not different than the Arduino does. Because before the ADC can be started, first the ADC-ready flag has to be checked. There is not much to gain advantage when this is done by other means.

Single shot samplingĪ single shot sampling is in fact what the Arduino does when calling the analogRead() function. Because there are no default functions to setup an analog conversion with interrupts, the registers associated with the ADC must be manipulated manually. This can be done more sophisticated by using interrupts. Especially when a signal must be sampled continuously. Since the ATMEGA328 doesn't use the CPU-core for the acquisition of the analog signals it's a waste of processing capabilities.
Arduino analog to digital converter code#
As described above, the Arduino can't execute other code while executing the analogRead() function.
