8000 ADC reading incorrectly when others are created in RP2 port · Issue #6833 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

ADC reading incorrectly when others are created in RP2 port #6833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
benevpi opened this issue Feb 2, 2021 · 3 comments
Closed

ADC reading incorrectly when others are created in RP2 port #6833

benevpi opened this issue Feb 2, 2021 · 3 comments
Labels

Comments

@benevpi
Copy link
benevpi commented Feb 2, 2021

In the below code, whether or not you created ADC3 affects the reading of ADC4. With the line commented out, I get a reading of about 17 degrees. With it there I get a reading of about 80.

import machine
import time

sensor_temp = machine.ADC(4)
blah = machine.ADC(3) # comment or uncomment this line to trigger / untrigger


conversion_factor = 3.3 / 65535

min_temp = 0
max_temp = 30

while True:
    reading = sensor_temp.read_u16() * conversion_factor
    temperature = 27 - (reading - 0.706)/0.001721
    print(temperature)
    time.sleep(0.5)
@lurch
Copy link
Contributor
lurch commented Feb 2, 2021

Just out of curiosity, I tried having a look at https://github.com/micropython/micropython/blob/master/ports/rp2/machine_adc.c but it seems to be using channel in confusing ways to refer to both the ADC channel and the GPIO number, so I couldn't really follow what it was doing 😕

dpgeorge added a commit to dpgeorge/micropython that referenced this issue Feb 3, 2021
Otherwise it resets the ADC peripheral each time a new ADC object is
constructed, which can reset other state that has already been set up.

See issue micropython#6833.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge
Copy link
Member
dpgeorge commented Feb 3, 2021

Thanks for the report, I can confirm the issue. It's because adc_init() is being called each time an ADC object is constructed, which turns off the temperature sensor switch.

Should be fixed by #6834.

dpgeorge added a commit to dpgeorge/micropython that referenced this issue Feb 3, 2021
Otherwise it resets the ADC peripheral each time a new ADC object is
constructed, which can reset other state that has already been set up.

See issue micropython#6833.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge
Copy link
Member
dpgeorge commented Feb 4, 2021

Fixed by 7f7b4f2

@dpgeorge dpgeorge closed this as completed Feb 4, 2021
Wind-stormger pushed a commit to BPI-STEAM/micropython that referenced this issue Sep 8, 2022
Fix typos and grammar in design_guide
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
0