Here is an example of a hardware setup to measure the voltage on a Lithium battery with a voltage divider on nRF52. The Lithium battery typically has a voltage range of 2.7 - 4.2 V and we (Nordic) recommend that you divide the battery voltage with two resistors and possibly a capacitor (more on that later)
To reduce the leakage current through the voltage divider to the minimum, we want the total resistance to be as high as possible. Therefore, we choose R1 to be 800 KΩ. This is the maximum source resistance we can have if we use an acquisition time of 40 us, see here.
We also want R2 to be large. R2 should be chosen such that the input voltage does not exceed Vdd when the battery is full (4.2 V). In this example Vdd is 3.3 V, so we choose R2 to be 2 MΩ which will give 3 V at AIN when battery is 4.2 V. With a gain of 1/5 we can use the internal reference at 0.6 V.
The leakage current with this configuration will be:
4.2 V / 2.8 MΩ = 1.5 uA
If you are using lower Vdd, R2 will have to be smaller and the leakage current will increase.
Usable ADC resolution
If we assume that the voltage range of the Lithium battery is 2.7 V - 4.2 V, i.e. 2.7 V when empty and 4.2 V when fully charged, then the voltage range on the ADC AIN input pin is:
Using a capacitor has several advantages over a pure resistive divider. The input will be more resistant to noise, you can use higher values on the voltage divider which will lead to less leakage current and you can set down the acquisition time.
Choosing the capacitor value
At the start of the sampling (when TACQ switch closes) there will be a voltage drop. The capacitor value should be high enough such that this voltage drop is small. The SAADC voltage the moment the sampling starts is about:
Vsaadc = Vain * (Cext – Csample) / Cext
We can say that we want the voltage drop to be equal to the voltage corresponding to 1LSB. If we use 12 bit resolution Cext can be calculated like this:
Vsaadc / Vain = 1 – 1 / 2^12
1 - 1 / 2^12 = (Cext – Csample) / Cext
Cext - 2^-12 * Cext = Cext - Csample
Cext = Csample * 2^12
If we say that Csample is 2.5pF (maximum according to Product Specification), then Cext will be:
Cext = 2.5 pF * 2^12 ~= 10nF
With this large external capacitor, we can also set down the acquisition time since the sampling capacitor (Csample) takes less time to charge up. Acquisition time can be set to the minimum, 3us. This will in addition reduce the current consumption as the SAADC spends less time sampling.
Choosing the sampling frequency
Over time the SAADC input can be seen as a resistor with the value 1/(f*C). The sampling frequency should be chosen such that the saadc input impedance is much larger than the resistor values in the voltage divider. The saadc input impedance is:
Rinput = 1 / (fsample * Csample)
If we choose a sampling frequency of say 1 second, the input impendance will be:
Rinput = 1 / (1 * 2.5*10^-12) = 400GOhm
Based on these calculations we can for example use these values: R1 = 4MOhm, R2 = 10MOhm, Cext = 10nF. Then the leakage current will maximum be:
4.2V / (10MOhm + 4MOhm) = 300nA
Post updated with capacitor value calculations
Since the battery voltage is over the operating voltage of the chip (3.6V) there have to be a regulator between the battery and the chip. Therefore, VDD will not vary with the battery voltage.
Ole, what is an advantage of your method versus "VDD as input" like this:
nrf_saadc_channel_config_t config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);
I've found that code in ble_app_proximity example.
Thank you Ole, looking forward to those updated calculations and equations for nRF52.