2024-03-15 03:06 AM - edited 2024-03-15 03:35 AM
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
Solved! Go to Solution.
2024-03-15 05:06 AM
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"
2024-03-15 03:45 AM - edited 2024-03-15 03:49 AM
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?
2024-03-15 05:06 AM
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"
2024-03-15 06:22 AM - edited 2024-03-15 08:45 AM
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.
2024-03-15 06:49 AM
Have you tried HAL_ADCEx_Calibration_Start() at the end of init functions?
2024-03-15 06:57 AM
HAL_ADCEx_Calibration_Start() is called for each ADC in the init function (of SEQ_SequencerController.c file attached above)
2024-03-15 07:29 AM
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
2024-03-15 07:58 AM
Could you please share the solution? what was the formula?
2024-03-15 08:23 AM - edited 2024-03-15 08:24 AM
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