The high series-resistance of the RAK5005 VBatt voltage divider (600kOhm) combined with the nRF52 SAADC input capacitance
(2.5pF typical) results in ~1.5 uS RC time-constant. Sample time must be at least 5 * RC time-constants for an accurate reading.
This PR sets the sampling time to 15uS, which 10x the RC time-constant.
(The default sampling time of 3 uS was allowing only ~2 RC time-constants, which results in a low reading, ~87% of VBatt.
Note that the SAADC sampling capacitor is on-chip and may vary from one part to the next; the longer sampling time
eliminates this source of error)
Increase oversampling to 32x to improve SNR of reading; this effective reads and averages 32 samples successively,
reducing impact of LSB jitter. This is optional, but results in very little extra time (480uS vs 15uS) per sample and
improves SNR. This can be extended to 256x oversampling.
Call analogCalibrateOffset() at setup() time to internally calibrate the SAADC offset voltage. Nordic TRM suggests calling this
periodically, especially when the temperature has changed significantly. In an application where readings are taken infrequently,
one might call this on every wake-up.
The high series-resistance of the RAK5005 VBatt voltage divider (600kOhm) combined with the nRF52 SAADC input capacitance (2.5pF typical) results in ~1.5 uS RC time-constant. Sample time must be at least 5 * RC time-constants for an accurate reading. This PR sets the sampling time to 15uS, which 10x the RC time-constant.
(The default sampling time of 3 uS was allowing only ~2 RC time-constants, which results in a low reading, ~87% of VBatt. Note that the SAADC sampling capacitor is on-chip and may vary from one part to the next; the longer sampling time eliminates this source of error)
Increase oversampling to 32x to improve SNR of reading; this effective reads and averages 32 samples successively, reducing impact of LSB jitter. This is optional, but results in very little extra time (480uS vs 15uS) per sample and improves SNR. This can be extended to 256x oversampling.
Call analogCalibrateOffset() at setup() time to internally calibrate the SAADC offset voltage. Nordic TRM suggests calling this periodically, especially when the temperature has changed significantly. In an application where readings are taken infrequently, one might call this on every wake-up.