Skip to content

Commit eefba16

Browse files
Correctly scale analog reading per issue #4794
1 parent 500083e commit eefba16

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ports/atmel-samd/common-hal/analogio/AnalogIn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
123123
adc_sync_read_channel(&adc, self->channel, ((uint8_t *)&value), 2);
124124

125125
adc_sync_deinit(&adc);
126-
// Shift the value to be 16 bit.
127-
return value << 4;
126+
// Stretch 12-bit ADC reading to 16-bit range
127+
return (value << 4) | (value >> 8);
128128
}
129129

130130
float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) {

0 commit comments

Comments
 (0)