The ADC conversion for the UNO takes 13 ADC cycles, but the sampling phase, when the voltage is acquired by the ADC, takes only 1.5 cycles.
I am going to use pin A0 mostly as a digital output and to switch it periodically to the analog input state for the shortest possible time. Can I set the interrupt ADC conversion and keep the analog input state of A0 just for 1.5 cycles (for the 16 MHz clock and the 125 kHz ADC frequency, it will be 18 us)?
I mean a sequence like that in the loop():
Switch A0 to input.
Set ADC for the interrupt conversion.
Start the conversion.
Wait for 18 us.
Switch A0 to digital output.
Continue the loop sequence.
I presume, in my interrupt handler, I will be able to read the correct voltage value at the moment of step 3. Am I correct?
The pin controls the battery power in order to turn it off programmatically, so normally it stays HIGH. It is connected to the controlled circuit via a diode, followed by a grounded resistor and capacitor in parallel, and a switching MOSFET.
Also a voltage divider is connected to the same pin, which divides the battery voltage by 10, and the result is converted by ADC in order to know the battery voltage. Since the latter is not required often, I am going to check it periodically with very low duty cycle, so the drop of voltage in the control circuit is consumed by the capacitor.
Are you sure that there is S/H circuit inside the analog section to hold analog input until the conversion is completed, and the time is bout 104 us. After conversion, there must be an option to discharge the S/H circuit to make it ready for the next sample.