cancel
Showing results for 
Search instead for 
Did you mean: 

300 LSB error ADc reading in STM32H743BI controller

ykn
Senior
static void MX_ADC1_Init(void)
{
 
  ADC_MultiModeTypeDef multimode;
  ADC_ChannelConfTypeDef sConfig;
 
    /**Common config 
    */
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  hadc1.Init.Resolution = ADC_RESOLUTION_16B;
  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc1.Init.LowPowerAutoWait = DISABLE;
  hadc1.Init.ContinuousConvMode = DISABLE;
  hadc1.Init.NbrOfConversion = 1;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.NbrOfDiscConversion = 1;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
  hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
  hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
  //hadc1.Init.BoostMode = ENABLE;
  hadc1.Init.OversamplingMode = DISABLE;
 
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
    /**Configure the ADC multi-mode 
    */
  multimode.Mode = ADC_MODE_INDEPENDENT;
  if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
    /**Configure Regular Channel 
    */
  sConfig.Channel = ADC_CHANNEL_6;
  sConfig.Rank = 1;
  sConfig.SamplingTime = ADC_SAMPLETIME_8CYCLES_5;
  sConfig.SingleDiff = ADC_SINGLE_ENDED;
  sConfig.OffsetNumber = ADC_OFFSET_NONE;
  sConfig.Offset = 0;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
  if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
   {
     /* Calibration Error */
     Error_Handler();
   }
}
 
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
{
    HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_5);
 
    HAL_ADC_Start(&hadc1);
 
	 	   if( HAL_ADC_PollForConversion(&hadc1, 10)==HAL_OK)
	 	   {
	 		  val[count] = HAL_ADC_GetValue(&hadc1);
	 	   }
	 	  // HAL_ADC_Stop(&hadc1);
           val_1 = 0;
           val_2 = val[count];
           //for(uint8_t i=0;i<100;i++)
           //{val_1 = val_1 + ADC_avg[i];}
           //val_2 = val_1/100;
            //val_2 = ((2500*val_2)/16384);
           	//val_2 = val_2 -1270;
            //val_2 = val_2*(7450/111);
 
	 	         data[0]=val_2/10000+48;
	 	  		 val_2 = val_2%10000;
	 	  		 data[1]=val_2/1000+48;
	 	  		 val_2 = val_2%1000;
	 	  		 data[2]=val_2/100+48;
	 	  		 val_2 = val_2%100;
	 	  		 data[3]=val_2/10+48;
	 	  		 data[4] = val_2%10+48;
 
	  HAL_UART_Transmit (&huart1, data, sizeof (data), 10);
	  count++;
	  if(count>99)count=0;
	 // HAL_Delay(250);
}

an I am readin ADC reading 1Msec timer interrupt.

33511 

36384 

36061 

35409 

35257 

34727 

35394 

34640 

35340 

34260 

34733 

35579 

35584 

36690 

36544 

35984 

35657 

36693 

35741 

35833 

35988 

32656 

35830 

36678 

36192 

35046 

35792 

35907 

35598 

35086 

35662 

34863 

35016 

35740 

36156 

36456 

35032 

33232 

33094 

36205 

36197 

34147 

35943 

35677 

33348 

34615 

35111 

36476 

34910 

35049 

35280 

36514 

35041 

36246 

35828 

35552 

this result Iam getting for 1.382 with reference voltage 2.5 volt.

why I am getting so much of fluctuation in reading.

thanking you.

2 REPLIES 2
TDK
Guru

Here are tips to improve accuracy:

https://www.st.com/resource/en/application_note/cd00211314-how-to-get-the-best-adc-accuracy-in-stm32-microcontrollers-stmicroelectronics.pdf

The sampling time in particular plays a huge role.

Is this on a custom board or known good hardware? Is the 1.382V signal high impedance?

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

0693W00000GZ0i2QAD.pngyes, this is a custom board. the signal input we take at point VDC+4 and VDC-4 point, like battery or any source and the ADC4 point connected to controller ADC pin.

thanking you for reply