Skip to main content
MCivo
Associate
October 1, 2018
Solved

ADC error in reading voltage

  • October 1, 2018
  • 2 replies
  • 2628 views

Hi everyone,

I'm having troubles with the internal ADC (STM32F072CBTX): a significant offset is present in the values provided by the converter. I performed a set of test measurments on the ADC: the results are shown in Table1.jpg.

Where:

  • Vmis is the voltage measured with a voltage meter at the ADC input pin (voltage drop on a resistor, in a voltage divider).
  • ADC is the value produced by the converter.
  • Vcalc is the correspondent voltage value with 12 bits resolution: Vcalc = Vmis * ADC / 4096
  • Err = Vmis - Vcalc

The values reported in the table of which above have been obtained with the following conditions:

  • VDDA = 3.3V
  • VSSA = 0V
  • No autocalibration

I tried autocalibration as well, by calling HAL_ADCEx_Calibration_Start before starting conversions: strangely, with autocalibration, things get even worse, as shown in Table2.jpg.

Does anyone have any idea on what is going on?

Am I doing something wrong?

Any help is appreciated.

Thanks.

Marco

This topic has been closed for replies.
Best answer by AvaTar

What about the code, especially the sampling time you are setting ?

If this time is short (too short), and you have a high input impedance, conversion results will apear too low.

It is useful to understand the basics of an SAR - ADC to configure it properly.

2 replies

AvaTar
AvaTarBest answer
Senior III
October 1, 2018

What about the code, especially the sampling time you are setting ?

If this time is short (too short), and you have a high input impedance, conversion results will apear too low.

It is useful to understand the basics of an SAR - ADC to configure it properly.

MCivo
MCivoAuthor
Associate
October 2, 2018

Dear Frank,

you are right: it was my fault. Basically I forgot to set up the ADC parameters in Cube.

I was sampling with 12 bits resolution with a sampling time of 1.5 cycles, which is the default value. Obviously, 1.5 cycles is way too short for the SAR, as at least 12.5 cycles are requested with 12 bits, according with STM.

Since I don't have strict constraints in terms of sampling time, I set up the period at 28.5 cycles: now the precision is more than acceptable, and as expected, with autocalibration, the ADC gives its best.

Thanks for your help.

Regards.

Marco