cancel
Showing results for 
Search instead for 
Did you mean: 

how to filter noise in adc input stm32?

Cnnon.1
Associate

hello, i am working with a stm32f407 discovery and a current sensor acs712 / 20A , the adc of the card hold input from 0 to 3.3v and the sensor presents an output from 0 to 5v so i have added a voltage divider with two resistors of 2.2k and 3.3k, when measuring what the sensor delivers to current 0, this delivers a voltage of approximately 1. 5v (measured with multimeter), but the adc delivers a conversion with too much noise, not equivalent with the sensor datasheet, I have 4 of these sensors and I test with all of them to make sure that this was not the problem, I am making the measurement continuously and I have tried with several adc configurations, I am not an expert in the subject of sensors so I do not know the type of treatment I should give to the input signal to obtain reliable values (since the measurement errors in the ADC present variations of up to +-50) or if the problem is with the configuration of the ADC. i leave the typical adc configuration that i have been using and i hope someone can help me with this issue. Greetings.

static void MX_ADC1_Init(void)

{

 ADC_ChannelConfTypeDef sConfig = {0};

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

 */

 hadc1.Instance = ADC1;

 hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV8;

 hadc1.Init.Resolution = ADC_RESOLUTION_10B;

 hadc1.Init.ScanConvMode = DISABLE;

 hadc1.Init.ContinuousConvMode = ENABLE;

 hadc1.Init.DiscontinuousConvMode = DISABLE;

 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

 hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;

 hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;

 hadc1.Init.NbrOfConversion = 1;

 hadc1.Init.DMAContinuousRequests = DISABLE;

 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

 if (HAL_ADC_Init(&hadc1) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 

 */

 sConfig.Channel = ADC_CHANNEL_1;

 sConfig.Rank = 1;

 sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;

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

 {

  Error_Handler();

 }

}

2 REPLIES 2
Uwe Bonnes
Principal II

Read the application notes about ADC.

prain
Senior III

According to your application, you can use low pass filter at adc input, increase adc sampling time, isolate analog tracks on PCB from noisy signals, calibrate adc at startup, use digital filtering (DSP), ...