Author Topic: STM32 alternating between working and not working  (Read 1202 times)

0 Members and 1 Guest are viewing this topic.

Offline yashrk

  • Frequent Contributor
  • **
  • Posts: 261
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
STM32 alternating between working and not working
« on: May 14, 2021, 05:01:29 am »
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.194MHz
2. ADC is set for continuous conversion mode, a gain of 32, low latency filter, 2K SPS and uses internal reference and current sources.
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline georges80

  • Frequent Contributor
  • **
  • Posts: 864
  • Country: us
Re: STM32 alternating between working and not working
« Reply #1 on: May 14, 2021, 05:20:56 am »
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.
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 7977
  • Country: nz
Re: STM32 alternating between working and not working
« Reply #2 on: May 14, 2021, 05:32:38 am »
yeah, sounds like you have AC noise on your signal

Scope the signal at the ADC pin with the scope ground connected to the nearest ground spot to the signal pin.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline yashrk

  • Frequent Contributor
  • **
  • Posts: 261
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: STM32 alternating between working and not working
« Reply #3 on: May 14, 2021, 06:36:46 am »
yeah, sounds like you have AC noise on your signal

Scope the signal at the ADC pin with the scope ground connected to the nearest ground spot to the signal pin.

I 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    Error
1   13106.8   13213   -0.32%
1   13106.8   13143   -0.11%
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline yashrk

  • Frequent Contributor
  • **
  • Posts: 261
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: STM32 alternating between working and not working
« Reply #4 on: May 17, 2021, 05:42:43 am »
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.

[attach=1]
« Last Edit: May 17, 2021, 05:45:08 am by yashrk »
Find me and things I'm working on - https://www.yashkudale.com/
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 7977
  • Country: nz
Re: STM32 alternating between working and not working
« Reply #5 on: May 17, 2021, 12:06:25 pm »
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)
« Last Edit: May 17, 2021, 12:14:02 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline yashrk

  • Frequent Contributor
  • **
  • Posts: 261
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: STM32 alternating between working and not working
« Reply #6 on: June 02, 2021, 04:16:48 am »
It issue was due to the ferrite beads added to the 3.3V and 5V rails. Removing them solved that issue. :-+
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 3812
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: STM32 alternating between working and not working
« Reply #7 on: June 02, 2021, 05:56:06 am »
So, removing them made the issue go away, but why did they cause it in the first place?

Offline bugnate

  • Contributor
  • Posts: 33
  • Country: us
Re: STM32 alternating between working and not working
« Reply #8 on: June 02, 2021, 06:44:57 pm »
So, removing them made the issue go away, but why did they cause it in the first place?

The 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.
« Last Edit: June 02, 2021, 06:49:13 pm by bugnate »
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 6907
  • Country: fr
Re: STM32 alternating between working and not working
« Reply #9 on: June 02, 2021, 06:56:35 pm »
So, removing them made the issue go away, but why did they cause it in the first place?

The 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.

600 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.

 
The following users thanked this post: thm_w

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 3812
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: STM32 alternating between working and not working
« Reply #10 on: June 02, 2021, 07:05:40 pm »
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 long enough after 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.

Offline bugnate

  • Contributor
  • Posts: 33
  • Country: us
Re: STM32 alternating between working and not working
« Reply #11 on: June 02, 2021, 09:38:36 pm »
600 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.
Appending "@100 MHz" to the bead spec is implied, or so I thought. At least for chip type, which I guess I had assumed here.

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.
Most 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.
 

Offline yashrk

  • Frequent Contributor
  • **
  • Posts: 261
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: STM32 alternating between working and not working
« Reply #12 on: June 07, 2021, 12:17:54 pm »
So, removing them made the issue go away, but why did they cause it in the first place?

This 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."


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.

Well Andy you were right it came back to bite me.
[attach=1][/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?
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 6907
  • Country: fr
Re: STM32 alternating between working and not working
« Reply #13 on: June 07, 2021, 03:25:25 pm »
This 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."

It'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.
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 3812
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: STM32 alternating between working and not working
« Reply #14 on: June 07, 2021, 06:08:35 pm »
Do you have any more insights?

Please 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.

Offline yashrk

  • Frequent Contributor
  • **
  • Posts: 261
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: STM32 alternating between working and not working
« Reply #15 on: June 08, 2021, 04:45:00 am »

It'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.


Now 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?

Please 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.

The 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.[attach=1]

The expected ADC value is 20,640 and the value we are getting is

@Room Temp  @High Temperature
   20649          20650
   20643          20650
   20646          20650
   20651          20648
   20649          20647
   20649          20768
   20645          20767
   20644          20650
   20650          20770
   20653          20648
   20649          20648
   20643          20650
   20649          20775
   20648          20646
   20650          20649
   20651          20772
   20647          20648
   20644          20647
   20646          20644
   20648          20771
   20648          20775
   20646          20652
   20649          20645
   20651          20650
   20650          20767
   20649          20774
   20649          20651
   20650          20775
« Last Edit: June 08, 2021, 05:00:23 am by yashrk »
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline bson

  • Supporter
  • ****
  • Posts: 1932
  • Country: us
Re: STM32 alternating between working and not working
« Reply #16 on: June 15, 2021, 07:52:05 pm »
The pot is warming up, either because it's close to the ADC or you're fondling it?
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 3812
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: STM32 alternating between working and not working
« Reply #17 on: June 15, 2021, 09:06:52 pm »
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?

Offline yashrk

  • Frequent Contributor
  • **
  • Posts: 261
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: STM32 alternating between working and not working
« Reply #18 on: June 16, 2021, 05:17:03 am »
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.  :-//
Find me and things I'm working on - https://www.yashkudale.com/
 
The following users thanked this post: SiliconWizard

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 3812
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: STM32 alternating between working and not working
« Reply #19 on: June 16, 2021, 06:04:00 am »
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.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf