2023-03-12 12:44 PM
I am using STM32F407 and STM32F767ZI on Nucleo and other boards. My configuration is a simple potentiometer as voltage divider (200K or 1K) to generate the analog input voltage.
Even with stable voltage on the ADC input (verified with my fluke 117 & Picoscope 5000, 2,000V, delta < 5mV), the values read on the ADC vary over ranges of about 100mV (0,117mV).
My question:
1) What is a typical accuracy one can expect on such a simple configuration.
2) What is the major contributor to this inaccuracy, and what can be done about it.
Note:
Detailed analysis added as an attachement.
Solved! Go to Solution.
2023-04-09 02:29 AM
Changing from PA0 to PA3 on the Nucleo board solved my problem. This confirms the noise hypothesis as indicated in the previous posts. Standard deviation went from 0.0025 (10 times better than before). This makes sense as the PA3 (A0) CN9 on the Nucleoboard is a pin that is used on the Arduino as analog input, and routed appropriately and the PA0 as CN11 P28 is probably not.
2023-03-12 04:37 PM
If I understand your detailed analysis, it looks like you tried digitizing the reference voltage and got pretty decent results: 5 mV of noise. You may want to try disconnecting your input signal and just grounding the input right on the board and see what you get. If that gives a low noise result you may want to think about how your input signal is referenced to the ADC input.
Do you have your voltage divider connected across the VDD of the Nucleo board? If so, where does VDD come from? A USB connector from your PC? That's probably a pretty noise signal. A quick and easy thing to try is connect the ground side of your voltage divider to whatever the ADC is using for its ground reference just in case the Nucleo board designer didn't. You'll have to check the schematic.
Here are some basic things you might want to check.
Good luck.
2023-03-12 09:04 PM
What is the single sample time in clock cycles ?
2023-03-23 12:50 PM
@raptorhal2 the frequency of the board is 16 Mhz, my sampling code waits until the ADC has completed its cycle:
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
int raw = HAL_ADC_GetValue(&hadc1);
APB clock sits at 8 Mhz, well below 14 Mhz.
So the exact sample time in clock cycles I do not know, but I think it should be sufficient.
2023-03-23 12:59 PM
@magene ,
Much appreciation for your reply to my post. I am working on a detailed answer with statistical analysis of the measurements. I am also in the process of purchasing a lab DMM so I can measure the signals and the stability of the power supply signal. Once I have the data I will get back to you.
On top of this I have been reading about true 12 bits. One of the topics in the article is that one needs to separate the digital from the analog part in order to get real 12 bits accuracy if one has a SAR ADC.
So I wonder what the effect of the integration of the 12 bits ADC in the microcontroller is?
2023-03-23 03:42 PM
Since the signal source is a high impedance, best accuracy requires adequate time for the sample and hold capacitor in the ADC to charge up after switching to that channel and before conversion starts on that channel. For each channel rank configuration, there is a sample time setting in clock cycles and ST's examples usually set it to 1.5 cycles, too low for a pot signal. If you setting is low, try substantially increasing it.
2023-03-24 12:57 AM
for reading a high impedance source like a pot with these kind of adc , simply need to have a big enough cap with low impedance (ceramic cap) direct at input to GND. then you will see, how good these adc can be. and set sampling time to 7.5 or so, not the absolute minimum.
so solder a 100nF cer.cap (X7R) to the input and then tell us...
2023-03-24 01:46 AM
Ok, thanks for the tip of the cycle time, I will take it along in my tests. It is in line with my observation that smaller pot gives better results. Connecting input to ground is also interesting in the same line (as you proposed). For the rest I will use my lab power supply and not a potmeter. I checked the voltage dip during sampling on the input with my scope, but indeed, could be that the capacitor of the ADC is not charged correctly and this voltage cannot be observed measuring the input. Nice!
2023-04-03 12:28 PM
@magene @AScha.3
I took many of Your advices into account and made a detailed case note attached to this post.
Overall conclusion:
1) Used caps at supply side of voltage divider and between GND and AI => no solution.
2) Grounded analog input of AI => still > 25 mV of std deviation?
3) Changed digitizing speeds (ADC_SAMPLETIME_480CYCLES vs ADC_SAMPLETIME_3CYCLES) => no difference.
4) Used Arduino Mega2560 to check hardware: 2.5 mV std deviation <> 37 mV for the STM32H767Zi Nucleo (F407VET6 has the same or very similar results).
5) I did not find the option to set my ADC bipolar, possibly it is not supported by my MCU, differential support I also did not come across?
The difference between the STM (12 bits) and the ATMEL (10 bits) measurements is still very large?
I do believe I missed something but what?
2023-04-03 01:18 PM
just for fun- i made some simple read adc tests, on H743 : get without oversampling about 0...20 digits error, at 16 bit , asym. in, and 3v3 and 40cm line at input -> about 0,5mV noise/error . not that bad. :)
next: try with symm input and short+soldered connections.