Skip to main content
JMart.28
Associate
November 8, 2022
Solved

Unable to read ADC properly using STM32L073VZI6

  • November 8, 2022
  • 7 replies
  • 5513 views

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.

This topic has been closed for replies.
Best answer by TDK
VREF+ needs to be connected to a voltage reference. Usually it is connected to VDDA.

7 replies

TDK
November 8, 2022

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
JMart.28Author
Associate
November 9, 2022

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

TDK
TDKBest answer
November 9, 2022
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
JMart.28Author
Associate
November 9, 2022

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

Piranha
Principal III
November 11, 2022

Read the AN4467.

SSher.3
Associate II
November 9, 2022

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.

JMart.28
JMart.28Author
Associate
November 14, 2022

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