adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4k stars 1.18k forks source link

rp2040: every other reading on HCSR04 (pulsein) incorrect with simpletest #4839

Closed jerryneedell closed 3 years ago

jerryneedell commented 3 years ago

When I run the hcsr04_simpletest on a feather_rp2040, every other reading is very short. The ~40cm reading is correct. This works normally on a feather_m4_express

I am using the RCWL-1601 sensor


Adafruit CircuitPython 7.0.0-alpha.2-705-gc80e25307 on 2021-05-31; Adafruit Feather RP2040 with rp2040
>>> 
>>> import hcsr04_simpletest
(44.047,)
(1.411,)
(43.911,)
(1.326,)
(43.911,)
(1.071,)
(43.197,)
(1.768,)
(42.415,)
(1.7,)
(42.143,)
(1.479,)
(39.355,)
(1.445,)
(41.837,)
ladyada commented 3 years ago

i think pulsein isnt fully implemented on the rp2040?

tannewt commented 3 years ago

I suspect this is a core issue. Want to move this one or create a new one in the core?

tannewt commented 3 years ago

I think @DavePutz would know about the current PulseIn state.

DavePutz commented 3 years ago

Instrumentation shows that the issue is that occasionally the PIO input from the Pico is returning a zero bit in a result word when it should be a one. As a result, the code detects that as an edge change and returns the short value. The logic analyzer confirms that the pulse coming in from the HCSR04 does not have any drops in the signal. Changing pins and voltages does not have any effect on the issue. Will pursue what might be done to correct this.

jerryneedell commented 3 years ago

fixed by #4859