cancel
Showing results for 
Search instead for 
Did you mean: 

ADC reading are not constant

rishavnath satapathy
Associate II
Posted on July 20, 2017 at 12:26

Hello There,

I am using STM3F4 discovery board. I am able to print the ADC value on display. I am using PA0 as ADC i/p. The value is constant 4095 if I connect to 3V from board. If I connect PA0(ADC i/p) to my external circuit which is a rail potentiometer the ADC reading is not constant. The last 2 digit are toggling continuously from 822 to 830. Anybody has faced same problem. Any suggestion how to fix the toggling of last 2 digit is welcome.

Video - 

https://www.youtube.com/watch?v=Lodb4PKB_R0&feature=em-upload_owner

 
10 REPLIES 10
George Eliozov
Associate II
Posted on July 20, 2017 at 12:34

Could you please show how did you initialize / get ADC values?

also what libraries are you using ?

Posted on July 20, 2017 at 13:22

Hello!

ADC_Voltage= ADC_reading / 4095 * VDDA    when you use 12 bit. VDDA is  the voltage at your VDDA pin (In your board  is connected to VCC)

so when connect ADC_IN to VCC the reading is 4095

It seems that you use 12 bit  ADC  conversion

Decade Value 830 , means about 0.6v  and this margin is about 2~3 millivolt

It seems  to me like normal.

Do you use the same VCC- GND  rail to produce this voltage you try to measure? 

Take a look at this document AN2834

https://my.st.com/content/ccc/resource/technical/document/application_note/group0/3f/4c/a4/82/bd/63/4e/92/CD00211314/files/CD00211314.pdf/jcr:content/translations/en.CD00211314.pdf

 
rishavnath satapathy
Associate II
Posted on July 20, 2017 at 13:28

I am using code and lib from here - 

https://github.com/MaJerle/stm32f429

 

To be specific most of code I have taken from here - 

https://github.com/MaJerle/stm32f429/blob/master/06-STM32F429_ADC/User/main.c

 

My code looks this-

int main(void) {

char str[15];

/* Initialize system */

SystemInit();

/* Initialize Delay library */

TM_DELAY_Init();

/* Initialize LCD */

TM_ILI9341_Init();

TM_ILI9341_Rotate(TM_ILI9341_Orientation_Landscape_1);

/* Print something on LCD */

TM_ILI9341_Puts(10, 10, '___soil Doctor___', &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_GREEN2);

/* Initialize ADC1 on channel 0, this is pin PA0 */

TM_ADC_Init(ADC1, ADC_Channel_0);

while (1) {

      /* Read ADC1 Channel0 */

      sprintf(str, '%4d: %4d\n\r', TM_ADC_Read(ADC1, ADC_Channel_0);

      TM_ILI9341_Puts(20, 30, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_GREEN2);

}

}
Posted on July 20, 2017 at 13:39

Hello again .

In  your case a good solution not to have ths toggling 

is to take the average value of n  samples.. You may experiment with n.. (there is acost in time delay when n is big)

Mark Shoe
Senior
Posted on July 20, 2017 at 14:20

It took me a few hours to discover how to use the stored calibration value. The HAL manual does not warn to do this, only tells it is possible. The cube generated software does not calibrate the adc at the init. You need to call HAL_ADCEx_Calibration_Start(&hadc); at startup. It should be practical if cubemx includes this in the adc init.

Mark Shoe
Senior
Posted on July 20, 2017 at 15:21

You are right this function is found in the M0 cpu's (stm32f0xx_hal_adc_ex) The calibration was needed because my calculated values where 10-50 counts different of what i calculated. After calibration much better. It seems the adc functions of the M4 are totally different.

Posted on July 20, 2017 at 13:30

It seems  to me like normal.

In fact, it is.

To expect more from an internal ADC on a general-purpose evaluation board would be inordinate.

There is a shottky diode in the VDD/VDDA path to protect against transverse currents from different supply terminals, making the reference voltage drifting with supply current and temperature.

For better results, a proper board and a MCU with separate VDDA is recommended.

Posted on July 20, 2017 at 13:46

Hi,

Yes you are correct. I am sourcing  Vcc - Gnd  from same STM32f board. Even reference voltage also internal.

The document really nice and helped a lot.

thanks.

Posted on July 20, 2017 at 14:42

Hello!

You mean the Internal reference voltage calibration values  and how to use?

It is for callibrate the VREF INTERNAL.

In none of my  stm32f4xx_hal_...... modules there is not such function

Write us more details.