cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to read ADC properly using STM32L073VZI6

JMart.28
Associate II

Hello,

I am using STM32L073VZI6 in a custom board, trying to read ADC values from a potentiometer connected to PA6. The microcontroller and the potentiometer are powered with 3.3 V.

The issue is that I get 4095 when the voltage input is less than 2 V. From 2 V to 3.3 V still I get 4095. Below are the configuration and the code. I have tried already many combinations without success.

0693W00000WHjfLQAT.png0693W00000WHjffQAD.png 

0693W00000WHjfzQAD.png 

Any help will be much appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
VREF+ needs to be connected to a voltage reference. Usually it is connected to VDDA.
If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

7 REPLIES 7
TDK
Guru

The ADC needs to be calibrated before you use it on the L0 series. Are you doing that? It's not done in the code you posted.

What is your VREF+ and how is it powered/connected?

How much impedance does your signal have? (i.e. what is the potentiometer resistance)

1.5 cycle sampling time isn't much. Probably not the issue, but increasing that for accuracy is probably smart.

If you feel a post has answered your question, please click "Accept as Solution".
JMart.28
Associate II

Hi TDK,

Thanks for your reply.

I am already using "while(HAL_ADCEx_Calibration_Start(&hadc,ADC_SINGLE_ENDED) != HAL_OK);" before reading the adc.

VREF is connected in this way

0693W00000WHrGYQA1.pngThe potentiometer resistance is 5 kohms

1.5 cycle is the last value I tested, but I tried other values.

Thank you

VREF+ needs to be connected to a voltage reference. Usually it is connected to VDDA.
If you feel a post has answered your question, please click "Accept as Solution".
JMart.28
Associate II

I thought it was optional, probably I misunderstood the datasheet. I will test it with the modification in a few days (unfortunately) and let you know.

Many thanks

SSher.3
Associate III

For precise measurements it's also recommended to source Vdda from Vdd through ferrite bead (smd ones do just fine). I never do though, but in my area 10-20% tolerance is fine. Or separate LDO.

Read the AN4467.

JMart.28
Associate II

Thank you all, connecting VREF+ to Vdd fixed it.