ADC pin to GND, doesn't show full zero #16558
-
Hello! Is it normal ,that when I connect ADC pin to GND IDE doesn't show full zero? ADC Value: 272, Voltage: 0.01 V, Raspberry Pi Pico with RP2040 import machine
import time
adc = machine.ADC(26)
vref = 3.3
conversion_factor = vref / 65535
while True:
raw_value = adc.read_u16()
voltage = raw_value * conversion_factor
print(f"ADC Value: {raw_value}, Voltage: {voltage:.3f} V")
time.sleep(0.1) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
ADCs in general purpose MCUs like the RP2340 usually lack precision. Especially at the end of the range they show greater non-linearity, and the effective resolution is smaller than the claimed bit width. The ADC of the RP2040 has more issues. See e.g. https://forums.raspberrypi.com/viewtopic.php?f=144&t=299904 and https://forums.raspberrypi.com/viewtopic.php?f=144&t=299904&p=1833277#p1833277 |
Beta Was this translation helpful? Give feedback.
-
@oldschoolmountainbike Just to beat this topic to death a bit, it is worth noting that the rp2040 manual very correctly points out that the best way to get a/d results is to use two channels. You permanently ground one channel, and use the other for your measurements, and use the difference as the returned value. This corrects for the input offset voltage drift in the sample-and-hold amplifier. Depending on the design of the amplifier, this can be quite temperature sensitive, and therefore it can shift as your CPU utilization shifts, or as the ambient temperature shifts, both of which will change the die temperature. Doing this can result in nearly order-of-magnitude improvements in the behavior for voltage near the bottom of the a/d range. As you initially observed, you were getting something like 7 mV offset. By using the nulling against a second input, this can be close to a single count. Note that most of the offset comes from the input amplifier, not the multiplexer, so shifting from one input to the next doesn't change that offset. |
Beta Was this translation helpful? Give feedback.
ADCs in general purpose MCUs like the RP2340 usually lack precision. Especially at the end of the range they show greater non-linearity, and the effective resolution is smaller than the claimed bit width. The ADC of the RP2040 has more issues. See e.g. https://forums.raspberrypi.com/viewtopic.php?f=144&t=299904 and https://forums.raspberrypi.com/viewtopic.php?f=144&t=299904&p=1833277#p1833277
If you need a precise ADC, use external devices designed for dealing with analog values, like for instance the ADS1115 of analog devices.