cancel
Showing results for 
Search instead for 
Did you mean: 

High variance in ADC readings

edwin8
Associate II

On a NUCLEO-H743ZI board, I am using ADC3 configured like so:

  • 16-bit mode
  • 6 MHz ADC clock
  • 8.5 cycles sampling time
  • Triggered by TIM3 to scan 4 channels every 10us
  • BDMA puts the results into a memory buffer

The problem I have is that for a given voltage, I can't get a stable reading. The lower 7-8 bits of the ADC values vary from one reading to the next. Using 12-bit mode also result in readings that can vary by up to 8 bits. I've tried slowing things down: setting TIM3 to trigger ADC every 5ms with 1.125 MHZ ADC clock and 32.5 cycles sampling time, but the readings still vary a lot. 

The ADC init code is below. Am I doing anything wrong? Thanks for any help.

hadc3.Instance = ADC3;
hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV6;
hadc3.Init.Resolution = ADC_RESOLUTION_16B;
hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc3.Init.EOCSelection = ADC_EOC_SEQ_CONV;
hadc3.Init.LowPowerAutoWait = DISABLE;
hadc3.Init.ContinuousConvMode = DISABLE;
hadc3.Init.NbrOfConversion = 4;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T3_TRGO;
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;
hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc3.Init.BoostMode = DISABLE;
hadc3.Init.OversamplingMode = DISABLE;
HAL_ADC_Init(&hadc3);
 
// Do this for 4 channels
sConfig.Channel = ADC_CHANNEL_X;
sConfig.Rank = ADC_REGULAR_RANK_X;
sConfig.SamplingTime = ADC_SAMPLETIME_32CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
HAL_ADC_ConfigChannel(&hadc3, &sConfig)
 
uint32_t adcresults[4];
HAL_ADCEx_Calibration_Start(&hadc3, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
HAL_ADC_Start_DMA(&hadc3, adcresults, 4);

4 REPLIES 4
MDief.12
Associate II

Hello Edwin,

I had similar problems with the ADC of the STM32H7 and at least one other person too.

See this discussion for more information:

https://community.st.com/s/question/0D50X00009sV2JSSA0/fluctuations-in-adc-value-of-stm32h743-mcu

Unfortunatetly I did not find a solution for the problem yet.

Ozone
Lead

I don't know the H7xx in particular, but getting strange/incorrect ADC reading is generally "easy".

Have you checked the input impedance / S&H capacitor / sampling time relation ?

As a quick test, you could increase the sampling time drastically.

Hello Ozone,

your points are correct for general problems with ADCs and poor designed circuits.

However I think there exists a particular problem with the ADC STM32H7.

I have tried all the points (reducing input impedance, increasing input capacitor, increasing sampling time) and a lot of other points. I even tested on two development boards and on one custom board. The readings from the ADC still vary a lot. Please read the linked discussion for more details.

From the opening posting, I understand that Edwin also increased the sampling time from 8.5 * 1/6MHz = 1.4 µs to 32.5 * 1/1.125MHz = 28.9 µs and he still has the problems.

As said, I have no particular experience with the H7, which seems stricken by some design issues (as other posts here suggest).

Another option to try would be lowering the ADC clock, and/or the core clock.

In general, the H7 seems to be a bit more power-hungry, so the stability of power supply (VDD / VDDA) and Vref are more critical.