Skip to content

Commit

Permalink
stm32/machine_adc: Handle ADC resolution less than 8 bits on all MCUs.
Browse files Browse the repository at this point in the history
All MCUs can have 6-bit resolution; see adc_cr_to_bits_table.

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Jun 15, 2023
1 parent 92d2de8 commit f7f8332
Showing 1 changed file with 0 additions and 2 deletions.
2 changes: 0 additions & 2 deletions ports/stm32/machine_adc.c
Expand Up @@ -374,12 +374,10 @@ uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint32_t sa

// Scale raw reading to 16 bit value using a Taylor expansion (for bits <= 16).
uint32_t bits = adc_get_bits(adc);
#if defined(STM32H7)
if (bits < 8) {
// For 6 and 7 bits
return raw << (16 - bits) | raw << (16 - 2 * bits) | raw >> (3 * bits - 16);
}
#endif
return raw << (16 - bits) | raw >> (2 * bits - 16);
}

Expand Down

0 comments on commit f7f8332

Please sign in to comment.