Skip to content

STM32L4 ADC Internal Channel : correct sampling time #6399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions targets/TARGET_STM/TARGET_STM32L4/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,16 @@ uint16_t adc_read(analogin_t *obj)
ADC_ChannelConfTypeDef sConfig = {0};

// Configure ADC channel
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_47CYCLES_5; // default value (1.5 us for 80MHz clock)
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;

switch (obj->channel) {
case 0:
sConfig.Channel = ADC_CHANNEL_VREFINT;
sConfig.SamplingTime = ADC_SAMPLETIME_247CYCLES_5; // Minimum ADC sampling time when reading the internal reference voltage is 4us
break;
case 1:
sConfig.Channel = ADC_CHANNEL_1;
Expand Down Expand Up @@ -159,20 +166,16 @@ uint16_t adc_read(analogin_t *obj)
break;
case 17:
sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
sConfig.SamplingTime = ADC_SAMPLETIME_247CYCLES_5; // Minimum ADC sampling time when reading the temperature is 5us
break;
case 18:
sConfig.Channel = ADC_CHANNEL_VBAT;
sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5; // Minimum ADC sampling time when reading the VBAT is 12us
break;
default:
return 0;
}

sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_47CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;

HAL_ADC_ConfigChannel(&obj->handle, &sConfig);

HAL_ADC_Start(&obj->handle); // Start conversion
Expand Down