Add analogReference function to switch between default VDD/4 reference and internal reference for ADC. #1876
+59
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The default analog reference for nRF52840-based boards (Xenon, Argon, Boron) uses VDD/4. This is fine for stable input voltage (usb), but super not great if you're running off a battery as the input voltage (and therefor reference voltage) decreases over time. The nRF52840 does have an internal 0.6v reference that would solve this problem, but the ability to use it is not currently implemented in the Particle OS. This is pretty annoying in a device that markets itself as a battery-based sensor node.
Solution
I've implented an Arduino-style AnalogReference function, that allows you to select the internal 0.6v reference instead of the default VDD/4 if desired.
Steps to Test
user/tests/hal/adc/test_adc.cpp
Example App
References
https://community.particle.io/t/internal-voltage-reference-for-accurate-voltage-calibration/6344
https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.0.0%2Fgroup__nrf__drv__saadc.html
https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/
Completeness