Author Topic: STM32 ADC noise  (Read 20927 times)

0 Members and 1 Guest are viewing this topic.

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
STM32 ADC noise
« on: October 25, 2018, 12:07:43 pm »
I have a demo board of STM32F407

I have configured the ADC in DMA mode for 500 samples. I just added the samples together to get the maximum variance of data. Therefore if the ADC readings were stable, then the sum of the samples would be also a fixed number.

The problem is that I can not get stable results even if I connect the ADC input to the ground. Naturally, it should demonstrate 0, but it shows massive variations. Interesting is that when I connect the ADC input the ground after the 3.3V regulator (the ground which is in common with the MCU), it shows much more noise in comparison with when I connect the input to the ground before the regulator/board. Personally, I think this is the issue with bypass caps (the designer has excluded them) and weak or lack of grounding.

Here is output which I captured using SWV real-time tracing

ADC has connected to the ground after 3.3V regulator


ADC has connected to the ground before 3.3V regulator

« Last Edit: October 25, 2018, 12:11:23 pm by VanitarNordic »
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 785
  • Country: ca
Re: STM32 ADC noise
« Reply #1 on: October 25, 2018, 02:13:41 pm »
Looks o'k, 500 pulse in the chart is just +1 count of the adc summed up over 500 samples. When connection is done before voltage regulator, there is negative offset, 12-bits adc would change +1 to 0 having -1mV voltage, though no wonder second chart is shifted down copy of the first one. To compare properly, DC offset has to be added to avoid negative voltage at the input.
 
The following users thanked this post: VanitarNordic, thm_w

Offline MT

  • Super Contributor
  • ***
  • Posts: 1616
  • Country: aq
Re: STM32 ADC noise
« Reply #2 on: October 25, 2018, 04:01:47 pm »
Read errata papers on ADC for the F4 series.
 

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 ADC noise
« Reply #3 on: October 25, 2018, 06:50:36 pm »
Looks o'k, 500 pulse in the chart is just +1 count of the adc summed up over 500 samples. When connection is done before voltage regulator, there is negative offset, 12-bits adc would change +1 to 0 having -1mV voltage, though no wonder second chart is shifted down copy of the first one. To compare properly, DC offset has to be added to avoid negative voltage at the input.

No, it must be much more stable than this, especially when it is connected to the ground. 500 samples with 0.5uS speed (2Msps), means 250uS capture of input. Let assume we plan to make an oscilloscope with this. therefore each sample is important because it is a representation of the input. I think the grounding is very bad in this demo board which makes the ground too noisy and when we connected the ADC input to the edge of the ground (ground wire), it is quieter and less noisy than the ground on the PCB.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14475
  • Country: fr
Re: STM32 ADC noise
« Reply #4 on: October 25, 2018, 07:23:36 pm »
Would be interesting to see pictures of this board.
 
The following users thanked this post: VanitarNordic

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4228
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: STM32 ADC noise
« Reply #5 on: October 25, 2018, 07:36:54 pm »
Have you checked that the ADC clock rate is configured to a valid value?
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 ADC noise
« Reply #6 on: October 25, 2018, 07:44:22 pm »
Would be interesting to see pictures of this board.



it is a two layers board without a ground plane
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 785
  • Country: ca
Re: STM32 ADC noise
« Reply #7 on: October 25, 2018, 09:42:30 pm »
Looks o'k, 500 pulse in the chart is just +1 count of the adc summed up over 500 samples. When connection is done before voltage regulator, there is negative offset, 12-bits adc would change +1 to 0 having -1mV voltage, though no wonder second chart is shifted down copy of the first one. To compare properly, DC offset has to be added to avoid negative voltage at the input.

No, it must be much more stable than this, especially when it is connected to the ground. 500 samples with 0.5uS speed (2Msps), means 250uS capture of input. Let assume we plan to make an oscilloscope with this. therefore each sample is important because it is a representation of the input. I think the grounding is very bad in this demo board which makes the ground too noisy and when we connected the ADC input to the edge of the ground (ground wire), it is quieter and less noisy than the ground on the PCB.

My understanding, each data point is a sum of 500 samples. Here is DS , page 135, table 68.
https://www.st.com/resource/en/datasheet/dm00037051.pdf
ET Total unadjusted error +-5 LSB.  Summing up 500 samples, error grows to 2500 LSB. If averaging needed, than you need to divide a summ by 500, to convert it back into 12-bits range.
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 ADC noise
« Reply #8 on: October 26, 2018, 06:42:12 am »
Quote
My understanding, each data point is a sum of 500 samples. Here is DS , page 135, table 68.
https://www.st.com/resource/en/datasheet/dm00037051.pdf
ET Total unadjusted error +-5 LSB.  Summing up 500 samples, error grows to 2500 LSB. If averaging needed, than you need to divide a summ by 500, to convert it back into 12-bits range.

well, 500 samples mean 500 full conversions in a sequence. if we add them up, it gives a number which shows any small variances in them. if we average them, we have averaged 500 samples in sequence and minimized the variance in the data. in case of connecting to the ground, because theoretically, all 500 values are zero, then sum or average must be fixed numbers in time.

You say LSB error is typically +/-2 and maximum +/-5. Therefore adding this up causes at least to 1000 -/+LSB error, and this naturally causes by the STM32 error if other conditions are perfect.

My goal is to grab a specific part of the input signal and detect any small changes in the amplitude. I just use the sum concept (getting an integral which is the sum of all ADC values) to detect the variance in data. By the datasheet, it seems to be natural or maybe it can be slightly better by shielding.

I have to do integral to detect a small change in amplitude. it means I have to sum up the values, which is an unstable number by this situation.

if I want to build a DSO, then I have to just pass each sample to the output or screen.
 

« Last Edit: October 26, 2018, 07:26:02 am by VanitarNordic »
 

Offline JVR

  • Regular Contributor
  • *
  • Posts: 201
  • Country: be
Re: STM32 ADC noise
« Reply #9 on: October 26, 2018, 07:59:58 am »
In a board with a proper layout, I've been able to get around 1LSB of noise out of a F4, so I would suggest you read the DS again, make sure that the clock is set up correctly, make sure there is not another function trying to use the ADC pin as well, or just change to a different pin for a test. Check that you have the capture time set up aligned to the ADC clock.
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 ADC noise
« Reply #10 on: October 26, 2018, 08:09:09 am »
In a board with a proper layout, I've been able to get around 1LSB of noise out of a F4, so I would suggest you read the DS again, make sure that the clock is set up correctly, make sure there is not another function trying to use the ADC pin as well, or just change to a different pin for a test. Check that you have the capture time set up aligned to the ADC clock.

All of them are correct except the layout which is a demo board. it has no ground plane. no pin uses the ADC. actually, I have enabled just the ADC, nothing more. I check the values using the real-time SWV> I have tested another Pin also. as discussed above, since I add the values, then I add the variance or error. therefore this output seems to be normal.

What I struggle is that I want to take an integral or check the amplitude of the signal in the given samples or time frame. therefore I have summed all 500 values. but if I do so, this instability is obvious. maybe I have to read several times (for example 5 times) and average this, but this causes a delay.

this is the clock





« Last Edit: October 26, 2018, 08:12:57 am by VanitarNordic »
 

Offline JVR

  • Regular Contributor
  • *
  • Posts: 201
  • Country: be
Re: STM32 ADC noise
« Reply #11 on: October 26, 2018, 09:36:49 am »
The problem with just summing, is that you are summing the error as well, as has been said. Decimate the error by dividing your 500 samples by 500, and you should get a very stable output from the ADC.

In terms of the board, yes its not a spectacularly good design, lack of decoupling etc, but since you have nothing else connected, it should not be that noisy. Also make sure that your debugger and the DUT are on the same ground voltage, using good quality USB cables, as the noise might be induced from your PC. I'f often found the best way to characterize a system's ADC is to have it powered from the design PSU, and getting samples off either via BT, or IrDA. PC's are noisy bastards, and if you are sharing a groundplane with one, you will need a lot more than just a few caps to clean that power up to avoid 0.8mV ripple affecting your ADC pins.

Also does the F4 you are using have a reference, or are you referencing to Vcc? Since the supply ripple will also affect the ADC.
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 ADC noise
« Reply #12 on: October 26, 2018, 10:22:18 am »
The problem with just summing, is that you are summing the error as well, as has been said. Decimate the error by dividing your 500 samples by 500, and you should get a very stable output from the ADC.

In terms of the board, yes its not a spectacularly good design, lack of decoupling etc, but since you have nothing else connected, it should not be that noisy. Also make sure that your debugger and the DUT are on the same ground voltage, using good quality USB cables, as the noise might be induced from your PC. I'f often found the best way to characterize a system's ADC is to have it powered from the design PSU, and getting samples off either via BT, or IrDA. PC's are noisy bastards, and if you are sharing a groundplane with one, you will need a lot more than just a few caps to clean that power up to avoid 0.8mV ripple affecting your ADC pins.

Also does the F4 you are using have a reference, or are you referencing to Vcc? Since the supply ripple will also affect the ADC.

I have no other option to check the values. because I either have to connect a programmer and PC to check variables by the SWV or connect using the serial port. Either PC is involved, at least within prototype settings. First Vref was connected to Avcc but I disconnected it myself and connected it to a TL431 reference, but no improvement.

Regarding summing up and averaging, of course averaging and dividing by 500 will handle stable result but it is not useful for my purpose because as I mentioned I suppose to take integral (or the sum of digital values) to check the amplitude of the signal and averaging destroys small changes or variations. one solution is to take sampling several times (for example 10 times) and then divide by 10 but it causes a delay in high-frequency pulses because the ADC has to be stopped, the calculation should be done and then started again and if the calculations cause a delay, it affects the response.
 

Online eliocor

  • Supporter
  • ****
  • Posts: 519
  • Country: it
    • rhodiatoce
Re: STM32 ADC noise
« Reply #13 on: October 26, 2018, 11:08:36 am »
Use ADC in DMA mode with a ping-pong buffer.
 
The following users thanked this post: VanitarNordic

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4228
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: STM32 ADC noise
« Reply #14 on: October 26, 2018, 11:19:02 am »
How could that possibly affect the noise level?

IMHO if the board has no ground plane, all bets are off. NO sane reason exists to make a PCB without one, and time spent diagnosing problems that are due to poor grounding is completely wasted. It's not even a good learning experience.

If there's any doubt about the board layout, pick up a dirt cheap ST Nucleo board for a similar CPU and try that. Life is too short to waste any part of it on 2 layer boards.

I have an STM32F405 on one of my own boards right in front of me. No issues with the ADC whatsoever.
 
The following users thanked this post: VanitarNordic

Offline JVR

  • Regular Contributor
  • *
  • Posts: 201
  • Country: be
Re: STM32 ADC noise
« Reply #15 on: October 26, 2018, 11:25:46 am »

I have no other option to check the values. because I either have to connect a programmer and PC to check variables by the SWV or connect using the serial port. Either PC is involved, at least within prototype settings. First Vref was connected to Avcc but I disconnected it myself and connected it to a TL431 reference, but no improvement.

Regarding summing up and averaging, of course averaging and dividing by 500 will handle stable result but it is not useful for my purpose because as I mentioned I suppose to take integral (or the sum of digital values) to check the amplitude of the signal and averaging destroys small changes or variations. one solution is to take sampling several times (for example 10 times) and then divide by 10 but it causes a delay in high-frequency pulses because the ADC has to be stopped, the calculation should be done and then started again and if the calculations cause a delay, it affects the response.

Right, I've been doing too much refactoring today. I kept reading that as Integer  :-DD

Easiest is as Andy suggests, bin the board. But if you want to give it the best possible chance, run it off a batterypack, and connect serial TX/RC via 1k resistors at a low-ish baudrate. With the ground connected to the PC via a 100R.

Throw some decoupling at the chip, and beef up the grounds if you can.

Its not pretty, but it will get you out of a hole.
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 ADC noise
« Reply #16 on: October 26, 2018, 12:02:29 pm »
How could that possibly affect the noise level?

IMHO if the board has no ground plane, all bets are off. NO sane reason exists to make a PCB without one, and time spent diagnosing problems that are due to poor grounding is completely wasted. It's not even a good learning experience.

If there's any doubt about the board layout, pick up a dirt cheap ST Nucleo board for a similar CPU and try that. Life is too short to waste any part of it on 2 layer boards.

I have an STM32F405 on one of my own boards right in front of me. No issues with the ADC whatsoever.

The ST Nucleo is a 4 layers design? Actually, I want to design a PCB just for my own purpose (not a demo board or header board which uses all I/Os) and dedicate one layer completely for the ground and another one for traces.

Would you please check how your board reacts with my challenge? I mean summing up the values. assign a DMA buffer size of 500 and sum all value, like taking an integral
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 785
  • Country: ca
Re: STM32 ADC noise
« Reply #17 on: October 26, 2018, 02:03:18 pm »
Basically, integrating over a pull of samples you increasing resolution of your adc. I'd refer to atmel's AVR121 app. note, but thumbs rule  is you should divide by 2 for sum of 4 samples, getting 1 extra bit. Divide by 2 for s16, 3 - s64, 4 - s256 etc.
 I'd measure performance of the STM adc on stm32f103 blue pill board (two layers) in the past, and got pretty bad results with ENOB close to 8-bits (12-bit adc).
So, I don't think 4 layers would make big difference, and the only option to get better resolution is to use external fast 14/16 bits adc, like ad7988 or similar.


 
The following users thanked this post: VanitarNordic

Online splin

  • Frequent Contributor
  • **
  • Posts: 999
  • Country: gb
Re: STM32 ADC noise
« Reply #18 on: October 26, 2018, 02:08:04 pm »
Your results look fairly typical to me for the STM32F405 which are known to have very noisy ADCs. You need to read AN4073 which should explain it all and give some tips to minimise the noise by changing the ART settings etc.

https://www.st.com/content/ccc/resource/technical/document/application_note/a0/71/3e/e4/8f/b6/40/e6/DM00050879.pdf/files/DM00050879.pdf/jcr:content/translations/en.DM00050879.pdf

From that document you can see that with a low noise DC voltage at the ADC i/p, the ADC noise results in a peak to peak dispersion of output codes of around 20 LSBs, which equates to a standard deviation of approx 20/6.6 or 3.03 LSBs. The SNR (signal to noise ratio) is  therefore 20 x log10(4096/2/sqrt(2)/3.03) = 53.5dB which isn't great. ST don't specify the SNR of the STM32F405 in the datasheet - probably for that reason.

The F3 series 12bit ADCs are much better with a typical SNR of 67dB with a single ended input (the '405 ADC is S/E) or 70dB with differential inputs - almost 7x less noise than the STM32F405.

As you are averageing 500 samples (albiet without the final divide by 500), the random, uncorrelated ADC noise will be reduced by sqrt(500). Assuming all the noise is uncorrelated the 20 LSB peak to peak noises reduces to .89. Multiply by 500 to give the same scale as your results gives 447 which is far off your 500 LSB spread (approx 30 to 530).

There is a big caveat hower; as has been pointed out earlier you shouldn't test by grounding the input because of DC offset in the ADC - any noise which takes the input level below 0V will give a zero code, so depending on the amount of offset you could be seeing only a fraction of the noise in your results - which you demonstrate by moving the grounding point.
 
The following users thanked this post: VanitarNordic

Online iMo

  • Super Contributor
  • ***
  • Posts: 4785
  • Country: pm
  • It's important to try new things..
Re: STM32 ADC noise
« Reply #19 on: October 26, 2018, 02:31:11 pm »
If your first picture shows the sum of 500 samples then your DC offset is aprox +0.5 LSB (500*0.5=250) and the noise is aprox +/-0.45 LSB [250-(500*0.45) .. 250+(500*0.45)]..
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 ADC noise
« Reply #20 on: October 26, 2018, 03:27:52 pm »
very good technical points from all contributors discussed in this topic to solve the problem, but I got confused about what should I do with this task.

the task is to measure the amplitude or detect amplitude changes in the input signal and by the way, we have to take an integral or sum up all ADC values. 500 ADC values or whatever.

I should not be concerned about the mentioned noise when I connect the ground to the input? I have connected the input to a waveform generator and the result was noisy also

The PCB board does influence the results? it means designing 4L PCB or 2L with a full layer of the ground will fix it?

Should I choose a different MCU? I have some STM32F103C8 in hand. It can handle the speed of 1MSPS which is enough.

Should I use an external ADC to do this? such as ADCS747X or MCP33121D-10 or similar but I see they also offer LSB errors similar to STM32 although smaller, but anyway it will affect the result in case of summing up the ADC values   :'(
« Last Edit: October 26, 2018, 03:29:36 pm by VanitarNordic »
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14475
  • Country: fr
Re: STM32 ADC noise
« Reply #21 on: October 26, 2018, 03:36:42 pm »
Just a couple remarks here.

You mentioned the lack of bypass caps, but looking at the board, at least the MCU seems properly bypassed as there seems to be a bypass cap in each corner of the IC and even an LC at what probably is VDDA (but I'm not sure, didn't bother to check the pinout in the datasheet). The placement is not ideal but it should do the job. Maybe the power supplies are not properly bypassed? Didn't look too closely.

I don't know how the power supply and ground are distributed on the board. But without a proper ground plane, they may not be routed properly and there may even be some loops? (Can't see that on the pic.)

Hardware issues aside, not sure either what your MCU setup really is. You said you're not using any analog input if I get it correctly? Then how is the ADC channel configured? With your incomplete config, the ADC's input may actually be floating? Something to check.

 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 ADC noise
« Reply #22 on: October 26, 2018, 03:46:41 pm »
Just a couple remarks here.

You mentioned the lack of bypass caps, but looking at the board, at least the MCU seems properly bypassed as there seems to be a bypass cap in each corner of the IC and even an LC at what probably is VDDA (but I'm not sure, didn't bother to check the pinout in the datasheet). The placement is not ideal but it should do the job. Maybe the power supplies are not properly bypassed? Didn't look too closely.

I don't know how the power supply and ground are distributed on the board. But without a proper ground plane, they may not be routed properly and there may even be some loops? (Can't see that on the pic.)

Hardware issues aside, not sure either what your MCU setup really is. You said you're not using any analog input if I get it correctly? Then how is the ADC channel configured? With your incomplete config, the ADC's input may actually be floating? Something to check.

he has not used bypass for VDDA. I mentioned I just have configured one ADC input and nothing more to check where the noise comes from. I have configured the ADC in DMA mode for 500 samples. When the conversion finishes, it calls the callback routine and it that routine I first Stop the DMA and make the calculation and at the end I start the DMA again. ADC does the job because I can see changes when I connect the input to ground or VCC or similar. The problem is not because of these points.
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 785
  • Country: ca
Re: STM32 ADC noise
« Reply #23 on: October 26, 2018, 03:55:39 pm »
1. 
the task is to measure the amplitude or detect amplitude changes in the input signal and by the way, we have to take an integral or sum up all ADC values. 500 ADC values or whatever.

2.
Should I use an external ADC to do this?  such as ADCS747X or MCP33121D-10 or similar but I see they also offer LSB errors similar to STM32 although smaller,
If integral sum of 500 needed, that means extra 9-bits required for your application, totalling to 12 + 9 = 21 bits.  No chance you ever could get such resolution with internal ADC.

Quote
MCP33131D-10 16-bit 1 Msps Differential ±5.1V 91.3 dBFS 103.5 dB -99.3 dB ±2 LSB ±0.8 LSB
+-2LSB for 16-bits, in other words noise is 16 times(!) lower, than for internal STM adc.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14475
  • Country: fr
Re: STM32 ADC noise
« Reply #24 on: October 26, 2018, 04:00:57 pm »
he has not used bypass for VDDA.

I was referring to L1/C21/C22 group. What are they actually connected to?

Funnily enough, the board is not just a poor layout job. The component referencing is also funky. There are multiple components with the same reference. Guess they may have assigned one reference for one value? That's weird. I wonder what PCB package they have used that even allows duplicate references.

I mentioned I just have configured one ADC input and nothing more to check where the noise comes from. I have configured the ADC in DMA mode for 500 samples. When the conversion finishes, it calls the callback routine and it that routine I first Stop the DMA and make the calculation and at the end I start the DMA again. ADC does the job because I can see changes when I connect the input to ground or VCC or similar. The problem is not because of these points.

OK, I may have misunderstood this part you said: "no pin uses the ADC. actually, I have enabled just the ADC, nothing more."

Could still be some ADC parameters to tweak.
Also, you could check if there is a mean to internally connect the ADC input to ground and see what difference it makes (unless you already did that).
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf