cancel
Showing results for 
Search instead for 
Did you mean: 

Help needed regarding STM32L476RG nucleo ADC

sharanya_ec
Associate II
Posted on March 19, 2016 at 13:21

I am working with AVRs for almost last 3 years and decided to buy a stm32 nucleo boards to have some fun with ARM and bought STM32L476RG nucleo board.I started to write code in Keil MDK-5 with the help of Hal drivers from STM32Cube MX.I coded for some Blinky and Usart successfully.But as i moved to ADC,i faced a strange problem.From the board schematics,i found that the MCU is using 3v3 external Vref.I measured with a multimeter and found 3.29v.I then coded  a program to display the ADC read value in single conversation mode via Usart.As the ADC of the STM32 is 12 bit,it should return 4095 while reading 3.3v.But whenever i am connecting PA0(Analog ADC pin 5) to 3.3v,it is returning value between 4025 to 4028.I tried to average of 100 results but got same output.Also i tried with different clock speeds but had no luck.

My question is if the error(typically 1.63% to 1.71%) is normal or if my adc unit is faulty or am i missing something????I found very little help about L476G as the controller is very new.Please reply guys...   

#stm32l476
3 REPLIES 3
re.wolff9
Senior
Posted on March 20, 2016 at 20:25

In my experience, the ADC is a lot more accurate than what you're seeing. I would recommend you do a few more measurements. Like what do you get if you set the pin to 0V? 0.1V? 1.5V? 

I personally suspect an offset error. This could be caused by a current flowing in some gound trace for example. 

sharanya_ec
Associate II
Posted on March 21, 2016 at 10:26

Thanks a lot for your reply.But as you suggested, I have already tried more than 5 different type of programs with (slower clock speeds also) but had no luck.

Whenever i connect the PA0 to ground,it is clearly showing 0.But whenever i connect it to 3.3v,it reads a value somewhere between 4025 to 4028.I can't have the clue if the ADC is erroneous or i am missing something.Please suggest what to do next.

sharanya_ec
Associate II
Posted on March 21, 2016 at 19:58

Though i found a solution,Please tell me if it is correct or not....

Every time,i run a calibration before any measurement and find the calibration factor and set the value and then start ADC like below.

uint32_t  Calibration_Factor;

HAL_ADCEx_Calibration_Start(&hadc1,ADC_SINGLE_ENDED);

Calibration_Factor=HAL_ADCEx_Calibration_GetValue(&hadc1,ADC_SINGLE_ENDED);

HAL_ADCEx_Calibration_SetValue(&hadc1,ADC_SINGLE_ENDED,Calibration_Factor); 

HAL_ADC_Start(&hadc1);

Now my ADC is returning stable value of 4095/4094 for reading of 3.3v.