Skip to content

Commit

Permalink
stm32/adc: Increase sample time for internal sensors on L4 MCUs.
Browse files Browse the repository at this point in the history
They need time (around 4us for VREFINT) to obtain accurate results.

Fixes issue #4022.
  • Loading branch information
dpgeorge committed Sep 20, 2018
1 parent 3220ced commit cb3c66e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ports/stm32/adc.c
Expand Up @@ -304,7 +304,13 @@ STATIC void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel)
sConfig.OffsetRightShift = DISABLE;
sConfig.OffsetSignedSaturation = DISABLE;
#elif defined(STM32L4)
sConfig.SamplingTime = ADC_SAMPLETIME_12CYCLES_5;
if (channel == ADC_CHANNEL_VREFINT
|| channel == ADC_CHANNEL_TEMPSENSOR
|| channel == ADC_CHANNEL_VBAT) {
sConfig.SamplingTime = ADC_SAMPLETIME_247CYCLES_5;
} else {
sConfig.SamplingTime = ADC_SAMPLETIME_12CYCLES_5;
}
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
Expand Down

0 comments on commit cb3c66e

Please sign in to comment.