I was looking at my battery measurements and they seemed a little off, and that led to me checking the ADC. I picked a random analog pin (A3) and plugged an external power supply in, with the ground referenced to the Feather ground. I fiddled around, inputting various voltages between 0 and 3.3V, and verified it with a multimeter.
With a conventional 12 bit ADC, you'd expect the ADC gain to be 3.3V / 4095 = 0.000805 V/ADC count. However, with my measurements, I found that low voltages gave me an actual gain around 0.00084 V/ADC count, and higher voltages were about 0.00091 V/ADC count.
This has a pretty significant effect on the reading - I inputted 1.75V, and got 1989 counts, which by using the conventional 3.3/4095, would give me 1.60 V instead.
Has anyone else seen anything like this? Is there a way to mitigate it? Can I tell the nRF to take slower, more accurate readings or something? Does it maybe not have a full scale from 0-3.3V?
Feather nRF52 ADC Inaccuracy?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Feather nRF52 ADC Inaccuracy?
The nRF52's ADC can handle inputs between 0v and VCC, which in this case would be 3.3v
It's a successive-approximation ADC, which is mostly a DAC and a comparator. The logic adjusts the DAC up and down until it matches the input voltage, and the final DAC setting is the output value. Other microcontrollers use different ADC architectures, but there's no reason for an SA to be less accurate than any other kind.
I do see something interesting in the datasheet where it talks about the ADC's reference voltage though: apparently there's an internal 0.6v reference, and a scaling factor of 6, which puts the results on a 0v-3.6v scale. That matches the numbers you posted: 1989 * 3.6v / 4096 = 1.748v
It's a successive-approximation ADC, which is mostly a DAC and a comparator. The logic adjusts the DAC up and down until it matches the input voltage, and the final DAC setting is the output value. Other microcontrollers use different ADC architectures, but there's no reason for an SA to be less accurate than any other kind.
I do see something interesting in the datasheet where it talks about the ADC's reference voltage though: apparently there's an internal 0.6v reference, and a scaling factor of 6, which puts the results on a 0v-3.6v scale. That matches the numbers you posted: 1989 * 3.6v / 4096 = 1.748v
- ktownsend
- Posts: 1447
- Joined: Thu Nov 05, 2009 2:18 am
Re: Feather nRF52 ADC Inaccuracy?
The ADC input range can be adjusted, but the default is 0..3.6V and 10-bit.
You can see an ADC example here: https://github.com/adafruit/Adafruit_nR ... dc/adc.ino
And example of measuring the VBAT input can be seen here: https://github.com/adafruit/Adafruit_nR ... c_vbat.ino
You can see in the second example that we manually override the input range to be 0..3.0V and 12-bit data for better resolution:
Let me know if that helps or if you see anything out of the ordinary and I'll be happy to dig into this further!
You can see an ADC example here: https://github.com/adafruit/Adafruit_nR ... dc/adc.ino
And example of measuring the VBAT input can be seen here: https://github.com/adafruit/Adafruit_nR ... c_vbat.ino
You can see in the second example that we manually override the input range to be 0..3.0V and 12-bit data for better resolution:
Code: Select all
// Set the analog reference to 3.0V (default = 3.6V)
analogReference(AR_INTERNAL_3_0);
// Set the resolution to 12-bit (0..4095)
analogReadResolution(12); // Can be 8, 10, 12 or 14
- ktownsend
- Posts: 1447
- Joined: Thu Nov 05, 2009 2:18 am
Re: Feather nRF52 ADC Inaccuracy?
I just published a new page in the learning guide with some details on the ADC, please let me know if this helps: https://learn.adafruit.com/bluefruit-nr ... /nrf52-adc
- mydadisaplumber
- Posts: 83
- Joined: Thu Jun 08, 2017 11:15 pm
Re: Feather nRF52 ADC Inaccuracy?
Thank you so much Kevin, using 3.6V worked perfectly, and now I know how to scale it accordingly.
- mydadisaplumber
- Posts: 83
- Joined: Thu Jun 08, 2017 11:15 pm
Re: Feather nRF52 ADC Inaccuracy?
Hi Kevin,
One more quick question on this subject. This Nordic blog post: https://devzone.nordicsemi.com/blogs/94 ... ith-nrf52/ mentions changing the acquisition time somewhere between 3 and 40 us. Is that supported in the Arduino code? Thanks.
One more quick question on this subject. This Nordic blog post: https://devzone.nordicsemi.com/blogs/94 ... ith-nrf52/ mentions changing the acquisition time somewhere between 3 and 40 us. Is that supported in the Arduino code? Thanks.
Please be positive and constructive with your questions and comments.