ADC conversion error of more than 20%
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-15 3:06 AM - edited ‎2024-03-15 3: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.
- Labels:
-
STM32G4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-15 5: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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-15 3:45 AM - edited ‎2024-03-15 3: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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-15 5: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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-15 6:22 AM - edited ‎2024-03-15 8: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-15 6:49 AM
Have you tried HAL_ADCEx_Calibration_Start() at the end of init functions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-15 6:57 AM
HAL_ADCEx_Calibration_Start() is called for each ADC in the init function (of SEQ_SequencerController.c file attached above)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-15 7: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-15 7:58 AM
Could you please share the solution? what was the formula?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-15 8:23 AM - edited ‎2024-03-15 8: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
