Author Topic: STM32 huge ADC zero offset/funky values  (Read 13482 times)

0 Members and 1 Guest are viewing this topic.

Offline reyntjensmTopic starter

  • Regular Contributor
  • *
  • Posts: 122
  • Country: be
STM32 huge ADC zero offset/funky values
« on: March 09, 2020, 11:47:22 pm »
Hello,

I'm working on a project using an stm32F429zi, i'm trying to read the voltage from a voltage divider(10k resistor and LDR) with the ADC.
My code is working fine but the values are off, when the input is at 0V the ADC outputs 1023(12bit measurement)  whatever i do, i'm 100% sure the pin is at ground.
At around 300-400mV the ADC is already at it's max value(4095), this should happen at 3,3V.
I've been looking around and found out the VREFINT is the reference for the ADC, so i tried to read this out with the same ADC and the result was 4095 while the VREFINT should be around 1,2V. I'm not sure if i did this measurement correct? My analog ground an supply pins are good connected. So should my chip be broken?
I had the same issue with a previous chip but locked my self out by setting all unused pins to analog so i was unable to debug it again.... :palm:
After soldering in a new chip(took some effort for this 144LQFP chip), would i've abused it too much so it's broken?
What other things can i troubleshoot?
I hope for some feedback and thank you all!
 

Offline ifrenide

  • Regular Contributor
  • *
  • Posts: 57
  • Country: dz
Re: STM32 huge ADC zero offset/funky values
« Reply #1 on: March 10, 2020, 12:08:43 am »
Hello, double check polarity of voltage maybe you are sure about something but it is wrong,It seems that you reversed the polarity and the built in ADC invert results because you just think that it gives you a 1023 at 0v no, for sure it is 5v but you think that is 0v , use your multimeter and check be sure to use COM probe on the ground and Positive probe to the center of the pot .
best regards.
 

Offline reyntjensmTopic starter

  • Regular Contributor
  • *
  • Posts: 122
  • Country: be
Re: STM32 huge ADC zero offset/funky values
« Reply #2 on: March 10, 2020, 12:14:35 am »
Hello,

Thank you for your feedback.
I tested this setup first as a prototype with a nucleo and breadboard without any problems.
Now i'm using this on my own PCB and things are off.
I've measured the ADC input pin with a voltmeter and oscilloscope. Ground is 0V and the ADC result is 1023, i only have one ground for everything in my pcb. Could this be the problem? I'm using pwm all over the place. SPI and I2C are working fine on this chip...
 

Offline ifrenide

  • Regular Contributor
  • *
  • Posts: 57
  • Country: dz
Re: STM32 huge ADC zero offset/funky values
« Reply #3 on: March 10, 2020, 12:27:02 am »
Mistakes are frequently present in PCB prototyping, I'm sure the problem is in "your PCB" because it's exteamly rare that the microcontroller is faulty. so for sure you made a mistake when prototyping the PCB . if you want send the schematic and PCB pictures to verify if there is a bug ,
best regards.
 

Offline reyntjensmTopic starter

  • Regular Contributor
  • *
  • Posts: 122
  • Country: be
Re: STM32 huge ADC zero offset/funky values
« Reply #4 on: March 10, 2020, 12:31:37 am »
I might send you my PCB tomorrow(i don't have it now) but it's quite large. This is the first analog part i'm using. Since it's only a simple voltage divider i would be surprised if there is a bug in my PCB. Even if i manually short the pin to ground the results are the same.
What about the VREFINT measurement? Am i doing this wrong or could my chip be broken?
Are there any other external pins i could measure to verify the ADC is working fine?
 

Offline ifrenide

  • Regular Contributor
  • *
  • Posts: 57
  • Country: dz
Re: STM32 huge ADC zero offset/funky values
« Reply #5 on: March 10, 2020, 12:55:11 am »
I think this configuration is simple , there are only few things to check.
1-be sure of the voltage polarity.
2- be sure that the analog voltage is fed to the ADC pin,and there is no short circuit .
3- be sure that you code code is correct,pins cofigured correctely, and fuctions are correct ...
there is no way to give you inverted results . be sure that the circuit gives you what you gave to it , it is a slave and you are the master .
if you didn't get what you expect , it is because you made a mistake and you just have doubts about the microctroller operating, don't wory your microcontroller is healthy because it give you a digital reading 1023 it is a good indication that it is works well.
I know you are tired to check the pcb and the code, but this is how it works , evry project has mistakes and even with professional engineers ,but they just spend more time and efforts to debbug . :-//
don't be lazy and verify each point , you will find your mistake.
don't forgive up .and I'm here for sure to help you :)
 

Offline reyntjensmTopic starter

  • Regular Contributor
  • *
  • Posts: 122
  • Country: be
Re: STM32 huge ADC zero offset/funky values
« Reply #6 on: March 10, 2020, 01:10:41 am »
Thank you for your motivating feedback, you are totally right.
Well i forgot to say one thing, in my PCB design i routed my voltage divider to a micrcontroller pin with no ADC functionality, yes i know it's yet again a very dumb mistake.
So since this is my first prototype and there are some pretty expensive components mounted on this PCB, i wired the voltage divider to another microcontroller pin with ADC functionality, but still there is a trace going to an unused pin right now. Could this be the issue? It took me some time to realize this but i guess i have to cut the trace when i'm back at my desk.
I'm also very worried about the internal VREFINT reading on the ADC1 channel 17. This should be around 1.2 volt and is now maxed out.
I have to say i'm not an expert at PCB design an this is one of my first big projects. I've learned more by making this project than in my 3 year bachelor degree so i'm still motivated to keep working on this project.
Great feedback/forum and i will keep you updated if i get around my mess.
 
 

Offline ifrenide

  • Regular Contributor
  • *
  • Posts: 57
  • Country: dz
Re: STM32 huge ADC zero offset/funky values
« Reply #7 on: March 10, 2020, 01:44:02 am »
you are wellcome .
you have to route the analog signal which is the voltage devider output to an ADC pin , if you didn't that , impossible to give you a result, it is a very big mistake.
you have to figure out which pin is the input of the adc . and give it the output of the voltage devider and be sure that your code is correct .
( but still there is a trace going to an unused pin right now) , so you are not familiar with what you did , you have to know 100%where the attachements between compenents go to.
good idea to use the output of the voltage devider and test it withe other devalopment board , but be sure that they share the same ground"ground wire between the two boards.
finaly , relax and take your time, step by step you will debbug your project.
good nigth.
 

Offline Harjit

  • Regular Contributor
  • *
  • Posts: 155
  • Country: us
Re: STM32 huge ADC zero offset/funky values
« Reply #8 on: March 10, 2020, 01:55:02 am »
With ADC's, the source resistance is a big deal because of the way the ADC works.

The ADC has an internal capacitor that they charge from the analog source. If you source resistance is large and the sampling time small, not enough charge will transfer into the internal capacitor and you'll get a mixture of the previous conversion and this one.

Look for source resistance, Rain and Cain in the datasheet.
 

Offline aheid

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: STM32 huge ADC zero offset/funky values
« Reply #9 on: March 10, 2020, 09:30:50 am »
Just as a sanity check, have you measured VDDA and AGND pins?
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3671
  • Country: gb
Re: STM32 huge ADC zero offset/funky values
« Reply #10 on: March 10, 2020, 12:18:25 pm »
What do you have the Vref+ and Vref- pins connected to?
 

Offline aheid

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: STM32 huge ADC zero offset/funky values
« Reply #11 on: March 10, 2020, 12:51:22 pm »
What do you have the Vref+ and Vref- pins connected to?

That was what I was thinking of, but forgot I'm used to the smaller footprints which don't have separate ref pins.   :palm:

So yeah, check those.
 

Offline reyntjensmTopic starter

  • Regular Contributor
  • *
  • Posts: 122
  • Country: be
Re: STM32 huge ADC zero offset/funky values
« Reply #12 on: March 10, 2020, 10:21:39 pm »
Hello everyone,

Thanks for the feedback.
So today i've looked a bit further.
I only have a Vref+ pin on my chip(STM32F429zit in 144LQFP) and this is 3,3V so this is correct.
VDDA and AGND are good.
I tried to measure all my unused pin's with all possible ADC's.
Every pin resulting in a 4095 ADC measurement. I guess a floating pin should give a result closer to 0?
Again my VREFINT was also 4095, so i guess my internal voltage reference is broken? But why are all the other things within my chip working like a charm?
I my VREFINT measurement incorrect?
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 9869
  • Country: ca
  • Non-expert
Re: STM32 huge ADC zero offset/funky values
« Reply #13 on: March 10, 2020, 11:31:05 pm »
There is no way to know what a floating pin would be. Use the internal pull-up or pull-down to set it at some level before measurement. Maybe you can post some of the code.
Vrefint should be around 1490 (1.2V).
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1917
  • Country: se
Re: STM32 huge ADC zero offset/funky values
« Reply #14 on: March 12, 2020, 04:29:54 pm »
About measuring Vrefint: if you are not using the HAL, you must make sure to:
  • Use ADC1
  • Set the TSVREFE bit in ADC_CCR
  • Reset the VBATE bit in ADC_CCR
If you are using the HAL, this is taken care of automatically when setting the channel configuration for channel 17 (still, make sure to use ADC1).
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline reyntjensmTopic starter

  • Regular Contributor
  • *
  • Posts: 122
  • Country: be
Re: STM32 huge ADC zero offset/funky values
« Reply #15 on: March 14, 2020, 03:13:06 pm »
i'm using HAL. So if my microcontroller would be ok VREFINT should be around 1490. In my case it's 4095 so for sure the chip is broken?
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 6958
  • Country: li
Re: STM32 huge ADC zero offset/funky values
« Reply #16 on: March 14, 2020, 03:25:12 pm »
Show us you schematics, pcb artwork and the code. Otherwise people here cannot help you much..
Readers discretion is advised..
 
The following users thanked this post: newbrain

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 5386
  • Country: nl
Re: STM32 huge ADC zero offset/funky values
« Reply #17 on: March 20, 2020, 03:45:39 pm »
Another thing to check is a fault in the hardware.
ESD events and such can damage I/O pins in subtle ways such as increased leakage and other parameters worsening, and without complete failure of the pin.

I've had ATmega's in which I damaged some of the ADC pins by over voltage, The ADC would not work on those pins anymore, but digital I/O still worked on those pins. So try to verify your problems with a 3nd board.
 

Offline reyntjensmTopic starter

  • Regular Contributor
  • *
  • Posts: 122
  • Country: be
Re: STM32 huge ADC zero offset/funky values
« Reply #18 on: October 12, 2021, 10:49:47 pm »
It has been a while since i replied to this topic. I had no time to continue working on this project.
I would like to make a V2 PCB now but i'm still not sure about the reason why my ADC values were acting strange.
Due to the MCU shortage, i would like to have the option to choose between 2 different MCU types so i'm planning to include 2 different MCU footprints in my PCB design. So one of the reasons why my first version didn't worked was: i had made a connection between the analog input and a MCU pin with no analog input functions... yes this is a stupid mistake. But still with some bodge wires etc. i couldn't get it to work. So i'm wondering if there could be another error in my PCB design. What about GND and AGND? I've been reading a lot of articles talking about a specific ground for the analog part of the circuit, i've also found an equal amount of articles saying it doesn't really matter. I only need 1 analoge reading and it's from a LDR, so it's not a very critical analog signal. Attached you can find some of my PCB design files. I only have 1 ground plane for the whole PCB. The analog signal is taken from a voltage divider made from a LDR and a resistor.
I would like to start very soon with the V2 PCB but it would be very sad if i encountered the same issue....
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 17278
  • Country: de
Re: STM32 huge ADC zero offset/funky values
« Reply #19 on: October 13, 2021, 08:12:30 am »
GND and AGND should be connected at 1 point. In an advanced design there may be something like a ferrite beed in between, but in most cases this would be a direct connection relatively close to the µC. With the ground one can make a few mistakes and get a little extra noise, or a slight offset of a few mV if high. So this should not explain a large error unless there is something really wrong, like no link at all.

The plan shows relatively few decoupling capacitors. Usually every pair of VCC/GND pins should get at least 1 cap.

I don't see the usual SWD debug interface, only SWDIO so far.
Unless short on pins I would not share the SWD pins with any other functions.

The ADC in many of the STM32 µCs wants to first get a calibration call. This adjusts the offset.
Some µC types have a problem when the ADC was not used for a longer time. The first reading after long waiting may be off.

If the signal source is relatively high resistance like the LDR one should consider a capacitor (e.g. 10 nF range) in parallel to the signal source. Also the sampling time may have to be set longer.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6928
  • Country: es
Re: STM32 huge ADC zero offset/funky values
« Reply #20 on: October 13, 2021, 09:58:43 am »
The input pin shouldn't affect if configured as input, but in any case, you can set any pin as analog (Not Analog for the adc, the other analog that means everything on that pin is turned off) and it'll remain in in high impedance and lowest power state.
You should show some of your code and your ADC connections, these schematics are pretty useless, showing nothing...
Probably you're skipping ADC calibration, or the sampling time is too high for the input impedance.
I've seen the ADC do very weird things when not respecting that.
« Last Edit: October 13, 2021, 10:01:30 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->