cancel
Showing results for 
Search instead for 
Did you mean: 

ADC accuracy (offset and gain big errors)

Luis Ber
Associate II

Hi,

I'm using the STM32L451VC microcontroller. I'm trying to measure the analog input with an internal ADC (12 bits resolution). The value is compensated with the vrefint (1.21V) of the microcontroller, following the next formula:

Vchannel = (3 V · (VREFINT_CAL) · (ADC channel read value)) / ((Vrefint read value) · 4095)

The analog reference voltage is 2.7V, isolated from the digital one with a ferrite and decoupling capacitors. The clock configuration and samplingTime is configured in the following way:

adcInit.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;

adcConfig.SamplingTime = ADC_SAMPLETIME_6CYCLES_5;

I think that all of these procedures are well done. However I'm obtaining very big errors (of 75 LSBs). My test is connect a DC voltage to the ADC input in the range of 0-2.7V and check the ADC captured value and measure the error. The file "errors" show the accuracy of the ADC and it is very bad.

I have attached also a graph that represents the ADC voltage read in function of the real value. In this way, we can see the gain (0,0408) and offset problem (-0,0545).

Where is the problem? Errors are very high. This could be noise? Which improvement can I do? There is a way to compensate these errors? (in different PCBs is suitable?)

Any help will be appreciated very much. Thank you in advance.

Luis

4 REPLIES 4

Do you perform calibration as outlined in the ADC chapter in RM, before the first conversion?

Is the input signal impedance low enough for the chosen sampling time?

JW

Hi waclawek.jan,

thank you for your fast answer.

Is it necessary to perform a calibration before each conversion? Is it done automatically? I haven't see any function in the HALs of the Adc (provided by Cube software).

The input of the signal is the parallel of 499Kohms resistor with 10nF capacitor. Is it properly selected? I have increased the sampling time but no improvement has been achieved.

Thank you again!

Piranha
Chief II

HAL calibration function is HAL_ADCEx_Calibration_Start() in file stm32l4xx_hal_adc_ex.c.

"The internal analog calibration is kept if the ADC is disabled (ADEN=0). However, if the ADC 

is disabled for extended periods, then it is recommended that a new calibration cycle is run 

before re-enabling the ADC."

For more information read RM0394 section 16.4.8.

[EDIT] I've just now noticed that Piranha has already answered the question, below... [/EDIT]

> Is it necessary to perform a calibration before each conversion?

No, only after the first conversion, and then upon significant environmental change (supply voltage, temperature).

> I haven't see any function in the HALs

I don't use Cube/HAL.

Read the ADC chapter in RM, focus on Calibration (ADCAL, ADCALDIF, ADC_CALFACT) subchapter. You then may want to look at Cube/HAL sources to find out which of the functions fulfills the functionality described in that subchapter. I'd expect a function with "calibration" in its name.

> The input of the signal is the parallel of 499Kohms resistor with 10nF capacitor. Is it properly selected?

> I have increased the sampling time but no improvement has been achieved.

This sounds as an unusual combination of very high input resistance possibly compensated with a very high input capacitor. The input signal is DC, I presume. If increasing sampling time does not produce results, it should be OK, but in future, you should be careful with such input resistances. At least for the initial testing, I'd go for something which has lower resistance.

JW