Merge pull request #6426 from PaintYourDragon/main

Analog in scaling fix for #4794
This commit is contained in:
Scott Shawcroft 2022-05-24 10:49:19 -07:00 committed by GitHub
commit 3694b5c1e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 10 deletions

View File

@ -123,8 +123,8 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
adc_sync_read_channel(&adc, self->channel, ((uint8_t *)&value), 2); adc_sync_read_channel(&adc, self->channel, ((uint8_t *)&value), 2);
adc_sync_deinit(&adc); adc_sync_deinit(&adc);
// Shift the value to be 16 bit. // Stretch 12-bit ADC reading to 16-bit range
return value << 4; return (value << 4) | (value >> 8);
} }
float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) { float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) {

View File

@ -81,8 +81,10 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
} }
// Shift the value to be 16 bit uint16_t value = ADC_GetChannelConversionValue(self->pin->adc, ADC_CHANNEL_GROUP);
return ADC_GetChannelConversionValue(self->pin->adc, ADC_CHANNEL_GROUP) << 4;
// Stretch 12-bit ADC reading to 16-bit range
return (value << 4) | (value >> 8);
} }
float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) { float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) {

View File

@ -125,8 +125,8 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
value = 0; value = 0;
} }
// Map value to from 14 to 16 bits // Stretch 14-bit ADC reading to 16-bit range
return value << 2; return (value << 2) | (value >> 12);
} }
float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) { float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) {

View File

@ -65,8 +65,8 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
adc_select_input(self->pin->number - ADC_FIRST_PIN_NUMBER); adc_select_input(self->pin->number - ADC_FIRST_PIN_NUMBER);
uint16_t value = adc_read(); uint16_t value = adc_read();
// Map value to from 12 to 16 bits // Stretch 12-bit ADC reading to 16-bit range
return value << 4; return (value << 4) | (value >> 8);
} }
float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) { float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) {

View File

@ -204,8 +204,8 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
uint16_t value = (uint16_t)HAL_ADC_GetValue(&AdcHandle); uint16_t value = (uint16_t)HAL_ADC_GetValue(&AdcHandle);
HAL_ADC_Stop(&AdcHandle); HAL_ADC_Stop(&AdcHandle);
// // Shift the value to be 16 bit. // Stretch 12-bit ADC reading to 16-bit range
return value << 4; return (value << 4) | (value >> 8);
} }
float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) { float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) {