Skip to main content
Yves Bmnt
Associate III
March 15, 2024
Solved

ADC conversion error of more than 20%

  • March 15, 2024
  • 4 replies
  • 3389 views

Hello,

I'm having problems with the adc conversions on my STM32G491.

There is an error of 23-26% higher than measured with scope or multimeter.

I'm using ADC1 & 2 in dual mode with DMA, I have an input signal coming from an opamp voltage follower.

I'll attach the adc file, the signal I used to compare ADC1 & 2 results is DETECT_PAM.

Kind regards,

Yves

Best answer by mƎALLEm

Hello,

Not clear .. Could you please provide the reading section of the ADC and how to convert the digital value to the voltage value?

The voltage result needs to be = (Digital reading x Vref)/Digital full scale.

For more details about how to optimize the ADC accuracy, you can refer to the AN2834 "How to optimize the ADC accuracy in the STM32 MCUs"

4 replies

Yves Bmnt
Yves BmntAuthor
Associate III
March 15, 2024

Something I don't understand, maybe because I didn't write the code here, and the person who did is not available, the ADC conversion callback already gives a voltage in mV, not a digital value that I have to convert, and I can't find the calculation factors anywhere. Is that usual with stm32?

mƎALLEm
mƎALLEmAnswer
Technical Moderator
March 15, 2024

Hello,

Not clear .. Could you please provide the reading section of the ADC and how to convert the digital value to the voltage value?

The voltage result needs to be = (Digital reading x Vref)/Digital full scale.

For more details about how to optimize the ADC accuracy, you can refer to the AN2834 "How to optimize the ADC accuracy in the STM32 MCUs"

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Yves Bmnt
Yves BmntAuthor
Associate III
March 15, 2024

Hello,

"The voltage result needs to be = (Digital reading x Vref)/Digital full scale" -> yes, this is what is usually done

"Could you please provide the reading section of the ADC and how to convert the digital value to the voltage value?" -> this is what I cannot find out:

In the attached file, you can find call for HAL_ADCEx_MultiModeStart_DMA and definition of the HAL_ADC_ConvCpltCallback.

The mAdcChannelResult[] array is where the DMA is asked to store the results for the conversions, and this value is directly sent by the callback. This value appears to be already in milliVolts, but with an error of close to +25% of the value measured with external instrument.

rtl
Associate II
March 15, 2024

Have you tried HAL_ADCEx_Calibration_Start() at the end of init functions?

Yves Bmnt
Yves BmntAuthor
Associate III
March 15, 2024

HAL_ADCEx_Calibration_Start() is called for each ADC in the init function (of SEQ_SequencerController.c file attached above)

Yves Bmnt
Yves BmntAuthor
Associate III
March 15, 2024

OK, I found out the conversion formula is simply missing from this code, if I add it then everything is perfectly fine :grinning_face_with_sweat::beaming_face_with_smiling_eyes:

Thank you for the support

mƎALLEm
Technical Moderator
March 15, 2024

Could you please share the solution? what was the formula?

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Yves Bmnt
Yves BmntAuthor
Associate III
March 15, 2024

There was simply no conversion formula and the raw ADC value was used for calculations instead of the actual voltage. So I added the usual conversion formula -> ADC value * Vref / Max ADC value