STM32 alternating between working and not working - Page 1
Forum section: electronics / general

author: yashrk
author_rank: Frequent Contributor
timestamp: May 14, 2021, 05:01:29 am
content: Hey!I am working with STM32L051K8 with ADS114S06 ADC.While most of the code runs fine and as expected, the error we are getting in the raw ADC value is higher in the alternate power cycle. That is at the input of 50mV we are expecting to get ~20970 from the ADC, once we will get 20982 which is a reasonable 0.03% error of the full span. But after the power cycle, we will get a value in the range of 21080 with an error of 0.33%. Again after doing few a power cycles, we go back to getting 0.03% error, and again after few power cycles, it will go bad, so on and so forth.The only thing that solves the problem is adding a huge delay between two acquisitions on the scale of 25mS and above.I have tried changing Sample Per Seconds in the ADC with no luck. I'm just not sure where to start digging.Some more information:1. The controller is running at 4.194MHz2. ADC is set for continuous conversion mode, a gain of 32, low latency filter, 2K SPS and uses internal reference and current sources.

author: georges80
author_rank: Frequent Contributor
timestamp: May 14, 2021, 05:20:56 am
content: Without a heck of a lot more details, we're only guessing...Could be dirty power, power not coming up stable, analog path to the ADC, phase of the moon etc...cheers,george.

author: Psi
author_rank: Super Contributor
timestamp: May 14, 2021, 05:32:38 am
content: yeah, sounds like you have AC noise on your signalScope the signal at the ADC pin with the scope ground connected to the nearest ground spot to the signal pin.

author: yashrk
author_rank: Frequent Contributor
timestamp: May 14, 2021, 06:36:46 am
content: Quote from: Psi on May 14, 2021, 05:32:38 amI also just tried reducing the gain to 1 and increasing the input voltage to 1V, get a higher signal-to-noise ratio.Volt Expected Actual Error1 13106.8 13213 -0.32%1 13106.8 13143 -0.11%

author: yashrk
author_rank: Frequent Contributor
timestamp: May 17, 2021, 05:42:43 am
content: Hey,I have narrowed the problem down to the ADC itself. After adding reset in the main loop the value started to switch between the errors without the system power cycling.I have also added a schematic of the ADC section.

author: Psi
author_rank: Super Contributor
timestamp: May 17, 2021, 12:06:25 pm
content: I have no experience with the ADC you're using but some of them can get a bit unhappy when you change the selected inputs. You must disregard the first sample after a ADC channel change (or sometimes after any changes to the ADC registers).Also, maybe you should add some PU and PD resistors on one side of the differential input to keep it centered around mid-rail. (Depending on what is connected)

author: yashrk
author_rank: Frequent Contributor
timestamp: June 02, 2021, 04:16:48 am
content: It issue was due to the ferrite beads added to the 3.3V and 5V rails. Removing them solved that issue.

author: AndyC_772
author_rank: Super Contributor
timestamp: June 02, 2021, 05:56:06 am
content: So, removing them made the issue go away, but why did they cause it in the first place?

author: bugnate
author_rank: Regular Contributor
timestamp: June 02, 2021, 06:44:57 pm
content: Quote from: AndyC_772 on June 02, 2021, 05:56:06 amThe ferrite beads are 600 ohm in the schematic. This is IMO on the high side for a power rail without doing some homework. Higher values and smaller packages tend to be more inductor-like at lower frequencies which can bite you. Guessing that is what happened here.

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 02, 2021, 06:56:35 pm
content: Quote from: bugnate on June 02, 2021, 06:44:57 pm600 ohm is not the series DC resistance, but the impedance at a high frequency. Not having the exact reference of the ferrite beads, we don't know about the DC resistance, but assuming it's low enough, the problem I see here is not the ferrite beads per se, but the fact the bypass capacitance is too low for them. Oh and I don't see the point of paralleling a 1nF cap with a 100nF one, seriously?Check the DC resistance of those ferrite beads, of course, and then try increasing the bypass caps to something like 10µF for AVDD and 1µF for DVDD, and see how that goes.

author: AndyC_772
author_rank: Super Contributor
timestamp: June 02, 2021, 07:05:40 pm
content: My question was really intended to promote further investigation; anything not fully understood, in my experience, has a high probability of coming back to bite you when you least expect it further down the line.A "600 ohm" ferrite bead will be 600 ohms at some stated frequency; it's impossible to tell what the true characteristics are without the data sheet. Often they're more like a frequency dependent resistor (V and I in phase) than a classical inductor.As to why it matters here, and to what extent, I wouldn't like to speculate without being able to probe the design carefully with a scope. The usual culprit for weird, small ADC errors is a high impedance source, whose voltage varies when the ADC's sample & hold cap is connected.Also check the errata for the device. I've just completed a design using another STM32 part that turned out to have an erratum along the lines of: "if you wait too long between consecutive conversions, then the result will be wrong".That, coupled with the (undocumented) fact that self-calibration fails if you don't wait longenoughafter first enabling the ADC, kept me guessing for quite a while. So did the extra surprise bonus fact that the physical pins of the device don't actually get connected to the ADC inputs when you configure them into analogue mode, unless you also enable some analogue switches that are off by default and documented in a different chapter of the manual entirely. Thanks ST... now go make some more chips so I can actually order them.

author: bugnate
author_rank: Regular Contributor
timestamp: June 02, 2021, 09:38:36 pm
content: Quote from: SiliconWizard on June 02, 2021, 06:56:35 pmAppending "@100 MHz" to the bead spec is implied, or so I thought. At least for chip type, which I guess I had assumed here.Quote from: AndyC_772 on June 02, 2021, 07:05:40 pmMost datasheets seem to only give the @100 MHz and DC values, unfortunately. I much prefer datasheets that more fully characterize, as in the attached example.

author: yashrk
author_rank: Frequent Contributor
timestamp: June 07, 2021, 12:17:54 pm
content: Quote from: AndyC_772 on June 02, 2021, 05:56:06 amThis is the explanation that I got"Another potential issue is the ferrites used on the supplies. Generally the recommendation is not to use ferrites on the supplies. Although the ferrites are useful for high frequency noise filtering, the added inductance can cause issues where very short, but larger current demands are required by the ADC. You could try replacing the ferrites with a 0 Ohm resistors to see if there is improvement."Quote from: AndyC_772 on June 02, 2021, 07:05:40 pmWell Andy you were right it came back to bite me.[/attach=1]Here is a temperature vs error graph where we go from 28°C to -35°C blue line, from -35°C to 80°C Red and finally 80°C to ambient yellow.Do you have any more insights?

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 07, 2021, 03:25:25 pm
content: Quote from: yashrk on June 07, 2021, 12:17:54 pmIt's pretty common to use ferrite beads on supplies, especially on the AVDD rail for MCUs. It causes no issues when done right.As I said earlier, the way to avoid excessive voltage drops due to them is to use enough bypass capacitance. The result is always an LC filter. This is not an inductance alone. As I said already and IMO, the bypass capacitance that can be seen on your schematic looks too low. Just increase it.

author: AndyC_772
author_rank: Super Contributor
timestamp: June 07, 2021, 06:08:35 pm
content: Quote from: yashrk on June 07, 2021, 12:17:54 pmPlease can you share some of the actual vs expected raw ADC values? Sometimes it's informative to see how much error corresponds to 1 LSB, and what the voltage ranges are that have issues.

author: yashrk
author_rank: Frequent Contributor
timestamp: June 08, 2021, 04:45:00 am
content: Quote from: SiliconWizard on June 07, 2021, 03:25:25 pmNow I have removed the ferrite bead (BLM18KG601SN1D) from 5 and 3.3V but still, I am getting issues at high temperatures do you still think the bypass caps may be the issue?Quote from: AndyC_772 on June 07, 2021, 06:08:35 pmThe voltage remains the same during the complete cycle. As we want to give a differential signal we use pot to generate the offset voltage (ADC GND is the same GND given to the POT) and used a precision voltage generator to give 49.21mV (calibrated span value), please refer image below, the opamp is representing the ADC.The expected ADC value is 20,640 and the value we are getting is@Room Temp @High Temperature20649 2065020643 2065020646 2065020651 2064820649 2064720649 2076820645 2076720644 2065020650 2077020653 2064820649 2064820643 2065020649 2077520648 2064620650 2064920651 2077220647 2064820644 2064720646 2064420648 2077120648 2077520646 2065220649 2064520651 2065020650 2076720649 2077420649 2065120650 20775

author: bson
author_rank: Unknown
timestamp: June 15, 2021, 07:52:05 pm
content: The pot is warming up, either because it's close to the ADC or you're fondling it?

author: AndyC_772
author_rank: Super Contributor
timestamp: June 15, 2021, 09:06:52 pm
content: There's definitely a clue here, in that when the noise is present, the ADC result toggles between two disparate values - almost.It's weird that it starts abruptly at a particular temperature. What's in the rest of the system? Does something start switching when it gets to a particular temperature? Does anything else in the system depend significantly on temperature?What does the layout look like in terms of power distribution and filtering?

author: yashrk
author_rank: Frequent Contributor
timestamp: June 16, 2021, 05:17:03 am
content: First of all, thank you all.We found the issue, as a few of the comments suggested we started looking at the capacitor values we used in the circuit.After changing the power supply capacitor and having no effect, eventually, we thought we are on edge with the 1uF cap at the Vref pin. So we changed it to a higher value.During the process, we found out our assembler screwed up the placement of the capacitor and the 0.1uF capacitor ended up in the place of the 1uF capacitor hence all the problem.Apparently, if a lower capacitance value is used at the Vref pin, the reference (sometimes - especially at the high temperature) starts to oscillate and the IC will start to pull the power supply voltage low due to the limited current capability of the supply (<10mA). As we could not scope the power rails at high temperatures in the chamber we never could see it in action. But we confirmed the same by intentionally providing a lower value capacitor. If we had a larger current budget we wouldn't have had this issue.Any suggestions to avoid this issue with the wrong placement of the capacitor in the future would be appreciated as unlike resistors we cannot read the capacitance value.

author: AndyC_772
author_rank: Super Contributor
timestamp: June 16, 2021, 06:04:00 am
content: Glad to hear you found the problem after all.If it's any consolation, yesterday I was building up some prototypes by hand, and just happened to check the value of a capacitor that I'd removed for better access to a nearby IC. Should have been 1uF, actually measured 0.1uF.It turned out that every part of that value was the same, the supplier had put the wrong components into a correctly labelled bag. If I hadn't checked, then I'd probably have spent today chasing exactly the same kind of problem as you.