Skip to content

Commit 7f36a36

Browse files
committed
delay 100us for analog voltage to stabilize
.. otherwise, depending on the prior state of the pin as a digital input, the value read could be 20% low.
1 parent 09f6919 commit 7f36a36

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

ports/raspberrypi/common-hal/analogio/AnalogIn.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "common-hal/analogio/AnalogIn.h"
2828
#include "shared-bindings/analogio/AnalogIn.h"
29+
#include "shared-bindings/microcontroller/__init__.h"
2930
#include "shared-bindings/microcontroller/Pin.h"
3031
#include "py/runtime.h"
3132
#include "supervisor/shared/translate/translate.h"
@@ -81,6 +82,7 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
8182
uint32_t old_ctrl = iobank0_hw->io[self->pin->number].ctrl;
8283
adc_gpio_init(self->pin->number);
8384
adc_select_input(self->pin->number - ADC_FIRST_PIN_NUMBER);
85+
common_hal_mcu_delay_us(100);
8486
value = adc_read();
8587
gpio_init(self->pin->number);
8688
padsbank0_hw->io[self->pin->number] = old_pad;

0 commit comments

Comments
 (0)