cancel
Showing results for 
Search instead for 
Did you mean: 

Hi I am working on stm32f051c8tx in adc part , below is the code I am using, the issue is, there is a variation of 30 millivolt from the multimeter to the voltage read by the controller.

NJP.1
Associate III

static void MX_ADC_Init(void)

{

 /* USER CODE BEGIN ADC_Init 0 */

 /* USER CODE END ADC_Init 0 */

 ADC_ChannelConfTypeDef sConfig = {0};

 /* USER CODE BEGIN ADC_Init 1 */

 /* USER CODE END ADC_Init 1 */

 /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 

 */

 hadc.Instance = ADC1;

 hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;

 hadc.Init.Resolution = ADC_RESOLUTION_12B;

 hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;

 hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;

 hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

 hadc.Init.LowPowerAutoWait = DISABLE;

 hadc.Init.LowPowerAutoPowerOff = DISABLE;

 hadc.Init.ContinuousConvMode = ENABLE;

 hadc.Init.DiscontinuousConvMode = DISABLE;

 hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;

 hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

 hadc.Init.DMAContinuousRequests = DISABLE;

 hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;

 if (HAL_ADC_Init(&hadc) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure for the selected ADC regular channel to be converted. 

 */

 sConfig.Channel = ADC_CHANNEL_1;

 sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

 sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;

 if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN ADC_Init 2 */

 /* USER CODE END ADC_Init 2 */

}

HAL_ADC_PollForConversion(adc, 500);

raw_value= HAL_ADC_GetValue(adc);

voltage=(raw_value*3.37/4095;

HAL_ADC_Stop(adc);

4 REPLIES 4

Try to increase sampling time. If this helped, the impedance of your signal source is too high for given sampling time.

JW

TDK
Guru

> raw_value*3.37/4095

Did your multimeter read 3.370V? when measuring the rail?

If you feel a post has answered your question, please click "Accept as Solution".

thankyou i will try this and reply here soon.

NJP.1
Associate III

thankyou yes it shows 3.7v in the multimeter.