ADC input impedance

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
User avatar
jcf
Posts: 60
Joined: Wed Mar 03, 2021 11:14 am

ADC input impedance

Post by jcf » Wed Mar 03, 2021 11:26 am

Hi,
With the Raspi Pico I had a strange experience:
the input impedance was so low that I measured only about 30% of the real voltage, with a 47k resistor in series to the input.
Strange as the datasheet says the impedance should be rather high.
I investigated further and found that the problem was gone when I initialized the concerned pin as input at the beginning.
I thought this was done automatically by the ADC initialization code.

My working code is now like this:

Code: Select all

from machine import Pin, ADC
import time

adc = Pin(26, Pin.IN)                  # this is needed to turn input to high impedance       
adc = ADC(0)        

while True:
    v = adc.read_u16() / 65535 * 3.26     
    print(v)
    time.sleep(0.5)

cebersp
Posts: 30
Joined: Mon Feb 08, 2021 12:07 pm

Re: ADC input impedance

Post by cebersp » Wed Mar 03, 2021 2:15 pm

Yes, it is mentioned in the rp2040 datasheet, that you have to switch off the inputs.
Pullup is active elsewise.
If you want to see, what is going on, you can have a look at the registers with regPeek().
Christof

Code: Select all

# regpeek.py
from machine import *

@micropython.asm_thumb
def regPeek(r0): # Address
    mov(r1,r0)
    ldr(r0,[r1,0])

@micropython.asm_thumb
def regPoke(r0, r1): # Address, Data
    str(r1,[r0,0])
    mov(r0,r1)
    
def regSet(adress, mask):
    regPoke(adress, regPeek(adress) | mask)


rGPIO26= 0x4001c000+0x6c # see rp2040 datasheet page 312-314
print(hex(regPeek(rGPIO26)), "{0:b}".format(regPeek(rGPIO26)))
#regPoke( rGPIO26, 1<<7 ) # switch off ADC0 input and output
adc = Pin(26, Pin.IN)
print(hex(regPeek(rGPIO26)), "{0:b}".format(regPeek(rGPIO26)))

User avatar
jcf
Posts: 60
Joined: Wed Mar 03, 2021 11:14 am

Re: ADC input impedance

Post by jcf » Wed Mar 03, 2021 3:52 pm

Oh, thanks, I did not know at all this debugging method.
Is there more info somewhere?

And is my method of doing it OK? (I think so, as it works)

Wouldn't it be logic that the command

Code: Select all

 adc = ADC(0)   
would automatically switch off the pullup?

And, if there is a pullup the measured voltage should be higher than real, in my case it is lower so something pulls it down!
Strange!

cebersp
Posts: 30
Joined: Mon Feb 08, 2021 12:07 pm

Re: ADC input impedance

Post by cebersp » Wed Mar 10, 2021 11:16 am

Hi,
did you solve the problem with these methods?
(Setting only bit 7 in the pad control register is described here too: https://www.raspberrypi.org/forums/view ... p?t=304915)

I am now using a different Pico and have the same very heavy issue on ADC0. I have 4k7 before the input, which is meant to protect the input. On it's side of the input pin, the signal is distorted very much as I can see on the input values and also, if I put the probe of my oscilloscope there. Before the resistor, the signal is OK and as expected.

jbeale
Posts: 2
Joined: Tue Mar 16, 2021 8:31 pm

Re: ADC input impedance

Post by jbeale » Tue Mar 16, 2021 8:35 pm

I also came across an article by "Characterizing the Raspberry Pi Pico ADC" by Mark Omo with some detailed measurements, if of interest.

davef
Posts: 813
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: ADC input impedance

Post by davef » Tue Mar 16, 2021 11:49 pm

If you see a distorted waveform on the ADC input pin you are probably looking at the ADC sampling waveform. Try putting a 100nF cap to ground.

All input pins will have a max current spec which is there to protect any substrate diodes used to clamp the input to just above the ADC supply voltage. If you have access to the actual ADC supply voltage you could use another external diode, ie a 1N4148 and then you could use a smaller series resistor. Confirm that the max input voltage can go 0.6 to 1V above the supply voltage. IE, not above ADC_AVDD

Caution recommended.

There is another configuration using two diodes, the 2nd one to clamp any accidental negative on your input.

Post Reply