pyboard ADC bug?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

pyboard ADC bug?

Post by shaoziyang » Thu Jul 26, 2018 4:19 am

I used PA0 to read a analog signal, when I read it once a time, it works correctly.

Code: Select all

>>> from pyb import ADC, Pin
>>> Vso = ADC(Pin('A0'))
>>> Vso.read()
1943
>>> Vso.read()
1955
>>> Vso.read()
1935
But when I read it continued, only first time convert is correctly.

Code: Select all

paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== from pyb import ADC, Pin
=== 
=== Vso = ADC(Pin('A0'))
=== 
=== while 1:
===   Vso.read()
===   pyb.delay(200)
1983
703
732
715
695
714

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: pyboard ADC bug?

Post by pythoncoder » Thu Jul 26, 2018 4:23 am

What is connected to the pin? If it is unconnected it will "float" causing this type of effect. It is an inevitable consequence of high impedance inputs.

Pyboard ADC's have been used extensively by many people so a bug is improbable.
Peter Hinch
Index to my micropython libraries.

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: pyboard ADC bug?

Post by shaoziyang » Thu Jul 26, 2018 5:06 am

pythoncoder wrote:
Thu Jul 26, 2018 4:23 am
What is connected to the pin? If it is unconnected it will "float" causing this type of effect. It is an inevitable consequence of high impedance inputs.

Pyboard ADC's have been used extensively by many people so a bug is improbable.
I connect it to a analog signal, about 1.65 voltage.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

This works here...

Post by pythoncoder » Thu Jul 26, 2018 5:51 am

Well, this works here (link pins X1 and X5):

Code: Select all

import pyb
dac = pyb.DAC(1)
dac.write(128)
Vso = pyb.ADC(pyb.Pin('A0'))
while 1:
    Vso.read()
    pyb.delay(200)
Produces

Code: Select all

2047
2045
2046
2043
2046
2045
2047
2045
2047
2046
2049
2038
2048
So either something is wrong with your setup or you have a dmaged board. It is behaving exactly like a floating input.
Peter Hinch
Index to my micropython libraries.

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: This works here...

Post by shaoziyang » Thu Jul 26, 2018 6:37 am

pythoncoder wrote:
Thu Jul 26, 2018 5:51 am
Well, this works here (link pins X1 and X5):

Code: Select all

import pyb
dac = pyb.DAC(1)
dac.write(128)
Vso = pyb.ADC(pyb.Pin('A0'))
while 1:
    Vso.read()
    pyb.delay(200)
Produces

Code: Select all

2047
2045
2046
2043
2046
2045
2047
2045
2047
2046
2049
2038
2048
So either something is wrong with your setup or you have a dmaged board. It is behaving exactly like a floating input.
Thank you. But the problem is still unsolved. I use firmware 1.9.4.

And when I remove pyb.delay(), the result is getting correctly.

Code: Select all

paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== from pyb import ADC, Pin
=== 
=== Vso = ADC(Pin('A0'))
=== 
=== 
=== for i in range(10):
===   Vso.read()
1942
1987
1979
1995
2019
2003
1995
1999
1944
2087
>>> 

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: pyboard ADC bug?

Post by shaoziyang » Thu Jul 26, 2018 6:49 am

When I not using pyb.delay() or time.sleep(), ADC is working.

Code: Select all

paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== from pyb import ADC, Pin
=== 
=== def _delay(num):
===   while num>0:
===     num-=1
=== 
=== Vso = ADC(Pin('A0'))
=== 
=== for i in range(1000):
===     Vso.read()
===     _delay(100000)
1979
2019
2035
2027
2019
2019
2030
2042
2015

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: pyboard ADC bug?

Post by dhylands » Thu Jul 26, 2018 3:32 pm

You wouldn't by chance be using a PYBLITE ? Is has the pins A0/A1 swapped with A2/A3 relative to the pyboard,

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: pyboard ADC bug?

Post by shaoziyang » Fri Jul 27, 2018 2:27 am

dhylands wrote:
Thu Jul 26, 2018 3:32 pm
You wouldn't by chance be using a PYBLITE ? Is has the pins A0/A1 swapped with A2/A3 relative to the pyboard,
I have using a board like pybv10, not PYBLITE. I have not meat this problem before, when I using pyb.delay() it will made ADC convert inaccurate. I will try old version firmware.

Post Reply