STM32l073 Adc Vrefint and adc_channel0 not working second measurement
Hi i 'm using nucleo board. Ihave a simple program that measure Vref int ( Vdda voltage ) then measure ADC channel 0. it works fine the first time. I'm using HAL function. Setiing of ADC NOT CONTINOUS MODE, Config Channel Adc Start , PollFor conversion Get result Vrefint , Stop ADC. Now second step, Config Channel Adc Start , PollFor conversion Get result ADC0 , Stop ADC. then i loop, ANd here tthis second loop give a bad value on Vrefint ( 1500 lsb first loop, 980 second iteration). If i don(t select channel0 it continusly measure properly, it seems that select adc0 channel between two Vrefint conversion corrupt the measurement.
Is it something special to do in between? shoul i not stop adc in between and use sequence mode to make acquisition of the two channel in one shoot ?
Here my adc config
hadc.Instance = ADC1;
hadc.Init.OversamplingMode = DISABLE;
hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; //dif
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.SamplingTime = ADC_SAMPLETIME_160CYCLES_5; //estimate for 0.5lsb error @4mhz, Rsource= 60kohm
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.DiscontinuousConvMode = ENABLE;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START; //not defined
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED; //not defined
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerFrequencyMode = ENABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;Here the code
if (HAL_ADC_Init(&hadc) != HAL_OK)
{
}
if(HAL_ADCEx_Calibration_Start(&hadc, ADC_SINGLE_ENDED) != HAL_OK){
}
//******************************MESURE TENSION REFERENCE INTERN *************************************************
sConfig.Channel = ADC_CHANNEL_VREFINT;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) { }
if(HAL_ADC_Start(&hadc) != HAL_OK){ }
HAL_ADC_PollForConversion(&hadc, 3000);
if ((HAL_ADC_GetState(&hadc) & HAL_ADC_STATE_REG_EOC) == HAL_ADC_STATE_REG_EOC) {
uint32_t uwADCxConvertedValue = HAL_ADC_GetValue(&hadc);
codeADC_VDDA = uwADCxConvertedValue;
Vdda = 3*( (float)*VREFINT_CAL / (float)uwADCxConvertedValue);
}
HAL_ADC_Stop(&hadc);
//******************************MESURE TENSION BATTERIE *************************************************
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_0;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) { }
if (HAL_ADC_Start(&hadc) != HAL_OK) { }
HAL_ADC_PollForConversion(&hadc, 3000);
if ((HAL_ADC_GetState(&hadc) & HAL_ADC_STATE_REG_EOC) == HAL_ADC_STATE_REG_EOC) {
uint32_t uwADCxConvertedValue = HAL_ADC_GetValue(&hadc);
codeADC_VBAT = uwADCxConvertedValue;
BatteryVoltage = ((float) uwADCxConvertedValue / 4095) * 3.3 * 2.5; //2.5: R11,R12 resistor bridge ratio
}
HAL_ADC_Stop(&hadc);