Trying to get up to speed on Mega-0 ADC operation. One of the key elements is management of the input port pin.
The ADC documentation explicitly says:
I/O Lines and Connections
The I/O pins AINx and VREF are configured by the port - I/O Pin Controller.
The digital input buffer should be disabled on the pin used as input for the ADC to disconnect the digital domain from the analog domain to obtain the best possible ADC results. This is configured by the PORT peripheral.
It took a while to trace down the place to control this. It seems to be in the PINCTRL register for the pin in question. While the caution, quoted above does not say so, it appears that the pull-up resistor is unaffected by the digital input buffer control so that it, also, needs to be turned off. It defaults off on bootup so normally, one would not have to do something except, maybe for "just being safe". That is also managed by one of the bits in the PINCTRL register so both disable of the digital input buffer and turn-off of the pull-up can be done in a single config write to PINCTRLn.
That is what I have found, so far. BUT (always a "BUT") the block diagram of the port structure shows an "Input Disable Override" signal that would appear to have precedence over the signal that disconnects the digital input block. It is not at all clear what the origin of this signal is, or if it even needs to be taken into account. Does anyone have any knowledge about this? After all, code CAN be actively executed while the ADC is running and if that code does something that causes the Input Disable to be overridden, the reading could be faulty!