2020-12-28 11:05 PM
Dear friends,
I'm setting a differential ADC input for my application.
The Positive voltage connects to ADC1_IN1 and the Negative connects to ADC1_IN2.
When I reading the 0V, the result I get is 1583 values of ADC (It is the raw data, I did not convert to voltage).
Do I forget something when setting the ADC? or I did something wrong in the config below?
My setup as below:
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED;
sConfig.SamplingTime = ADC_SAMPLETIME_4CYCLES_5;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
2020-12-29 12:59 AM
You forgot to tell what your VREF is. With VDDA/VREF=3.3V and VDD = 2.5v VDD measures as 2.5/3.3*2048 = 1551.5 That looks similar to your result.
2020-12-29 06:09 PM
Hi Uwe Bonnes,
The 1583 is the ADC value at the 0V differential voltage ADC input, and I didn't set the VREF. VDD is 3.3V.
I used a small package of STM32F303, so have no VREF pin.
And I read the Vref by ADC then the value is 1409, with the CALFACT_S value is 62.
The VREFINT_CAL (@ 0x1ffff7ba) is 1523; VREFINT_DATA (@ADC1->DR) is 1346