2017-07-20 03:26 AM
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
2017-07-20 03:34 AM
Could you please show how did you initialize / get ADC values?
also what libraries are you using ?
2017-07-20 04:22 AM
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
2017-07-20 04:28 AM
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); }}2017-07-20 04:39 AM
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)
2017-07-20 05:20 AM
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.
2017-07-20 06:21 AM
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.
2017-07-20 06:30 AM
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.
2017-07-20 06:46 AM
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.
2017-07-20 07:42 AM
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.