ArduinoCore-avr icon indicating copy to clipboard operation
ArduinoCore-avr copied to clipboard

AnalogRead and the DIDR register

Open rtek1000 opened this issue 2 years ago • 0 comments

Hello,

I was researching the best ADC performance of the ATmega328, and found this reference below:

Don’t forget to DIDR!

the DIDR (Data Input Disable Register) disconnects the digital inputs from which ever ADC channels you are using. This is important for 2 reasons. First off, an analog input will be floating all over the place, and causing the digital input to constantly toggle high and low. This creates excessive noise near the ADC, and burns extra power. Secondly, the digital input and associated DIDR switch have a capacitance associated with them which will slow down your input signal if you’re sampling a highly resistive load.

Unfortunately, Arduino doesn’t do this for you automatically. But it’s as easy as adding the line DIDR0 = 0×01; to your setup() section to use ADC0. If you’re using ADC1 you set bit 1, if ADC2 you set bit 2, and so on.

Would it be possible to embed this register in the pinMode( ) function?

http://www.openmusiclabs.com/learning/digital/atmega-adc/index.html

rtek1000 avatar Jun 16 '22 05:06 rtek1000