Author Topic: STM32F030C6 ADC RMS Voltage Measurement Inconsistency After Reset  (Read 3041 times)

0 Members and 1 Guest are viewing this topic.

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 4010
  • Country: nl
Re: STM32F030C6 ADC RMS Voltage Measurement Inconsistency After Reset
« Reply #25 on: October 13, 2024, 01:49:11 pm »
C2 is probably useful. Your voltage divider has a relative high output impedance, and this reduces the accuracy of the ADC. A capacitor on the ADC input that is many times bigger then the capacitance of the ADC input itself provides a low impedance to the mostly capacitive input of the ADC. One of the uC manufacturers made an application note for this. (I think it was Atmel, but I'm not sure).

1.7 V RMS may be just a little too much for the 3.3 V supply range.

Possibly. Outputting and plotting the raw adc vaules in a graph will clearly show any saturation effects.
Starting with DC measurements is always a first start to see if your sampling frontend and ADC code does something that looks plausible. Circuits like this look deceptively simple, but all the parts have to be dimensioned right relative to each other for it to work well. Calculations on the ADC values hides all details of the sampling input. A good way to verify is to write a little oscilloscope function (including triggering, possibly on a low voltage channel only) Then verify whether your ADC frontend works by sampling some data both with a decent oscilloscope and with your gadget, and then compare the data. Probably easiest on your PC, but you may be able to upload the raw ADC values to your scope to a "reference channel". Also do this with badly distorted signals (high crest factor) and verify your ADC can capture the waveform properly.

 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5652
  • Country: gw
Re: STM32F030C6 ADC RMS Voltage Measurement Inconsistency After Reset
« Reply #26 on: October 13, 2024, 02:09:02 pm »
1.7 V RMS may be just a little too much for the 3.3 V supply range.

Yep, you have to subtract the DC=1.65V (or the "average" in the previous v1 graph)..
Readers discretion is advised..
 

Offline ShubhamTopic starter

  • Contributor
  • Posts: 24
  • Country: in
Re: STM32F030C6 ADC RMS Voltage Measurement Inconsistency After Reset
« Reply #27 on: October 16, 2024, 02:41:58 pm »
I connected my oscilloscope to the ADC pin my observation was that, when the mains power is clean (not noisy), the RMS readings are consistent and accurate, even after restarting the microcontroller.
2403967-0
However, when the mains power becomes noisy, I notice a significant impact on both the accuracy and precision of the RMS voltage calculation.
2403963-1
Could this be related to my schematic, or should I focus on modifying my code? I'd appreciate any suggestions on how to mitigate this problem.
« Last Edit: October 16, 2024, 02:43:34 pm by Shubham »
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 7660
  • Country: ca
  • Non-expert
Re: STM32F030C6 ADC RMS Voltage Measurement Inconsistency After Reset
« Reply #28 on: October 16, 2024, 10:38:23 pm »
Could this be related to my schematic, or should I focus on modifying my code? I'd appreciate any suggestions on how to mitigate this problem.

It can be filtered in code or hardware. Usually easiest is to start with hardware.
Maybe increase the capacitance of the filter and see if that has a direct effect on the noise spikes.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 15238
  • Country: de
Re: STM32F030C6 ADC RMS Voltage Measurement Inconsistency After Reset
« Reply #29 on: October 17, 2024, 07:44:13 am »
The easier filtering is with software - just use slightly faster sampling, so that the existing RC filtering is more effective as anti aliasing filter. More readings also get better averaging over ADC errors.

The main issue I see with the accuracy is when the reading window is not exactly an integer number of periods. It should still not be a large error. With 100 ms and thus 5 or 6 periods a frequency error of 1% could result in uncertainty of some 1/5 %. Starting at a point with some 70% of the peak values could reduce this error quite a bit compared to a random start. One could also do additional digital filtering with a few points with reduced weight at the start and end, so get a more soft start / stop and this way get less sensitive to the exact start phase.

If there is noise superimposed to the waveform, this does add to the RMS values - that is normal. The noise is part of the AC signal and thus needs to be included. Different meters may have a different bandwidth and may for this reason get different results. Especially the RMS result from the scope with a much higher BW can be a bit higher.

A little more care is needed for relatively small readings. Here the noise of the ADC itself should be subtracted from the squared values. This way one should be able to also get OK readings at rather small amplitudes, like 1% of the range or even less. With significant background noise it is normal that also the RMS readings may get a bit more noisy - that is natural as noise is usually random and scattering amplitude.
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5652
  • Country: gw
Re: STM32F030C6 ADC RMS Voltage Measurement Inconsistency After Reset
« Reply #30 on: October 17, 2024, 08:42:42 am »
You may also try with a "median" filter in sw. Pretty good for filtering out the "outliers" (your noise spikes)..
Readers discretion is advised..
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4215
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: STM32F030C6 ADC RMS Voltage Measurement Inconsistency After Reset
« Reply #31 on: October 17, 2024, 10:34:11 am »
What is your samplerate?
What high-pass filter are you using?
How wide of a window are your using, or are you phase locking the sampling to the base frequency?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf