Understanding this ADC resolution calculation - Page 1
Forum section: electronics / projects

author: Red_Micro
author_rank: Regular Contributor
timestamp: April 18, 2020, 06:12:00 am
content: Fromthis articlethe author has a 1000 turns CT and a 100 ohms burden resistor. He states:QuoteHe says the resolution translates to 3mA per ADC count. If I do calculations I get:3 mA /1000 = 3 uA3 uA * 100 = 300 uV (rms)Vburden_peak = 300 uV * 1.41 = 424.26 uVVburden_pkpk = 424.26 * 2 = 0.84 mVAs you see, for a 12 bit ADC, 0.8mV is one count. However, the author references one count to the peak to peak voltage. So when sampling, the ADC would read 1.65V + 0.4 mV for positive peak, and 1.65 - 0.4 mV for negative peak.Is my reasoning right? Is this method good to find the peak of a sine wave? Why one ADC count refers to the peak to peak voltage instead of just the peak?

author: PartialDischarge
author_rank: Super Contributor
timestamp: April 18, 2020, 06:34:02 am
content: That article is plagued with errors, remove it from your mind. It's so bad that a college professor made a few videos about it:

author: Karel
author_rank: Super Contributor
timestamp: April 18, 2020, 07:03:20 am
content: Also good to know:"Coding Schemes Used With Data Converters"http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sbaa042

author: Kleinstein
author_rank: Super Contributor
timestamp: April 18, 2020, 07:13:21 am
content: When calculating the RMS value one usually uses a lot more than 1 ADC reading. So one has quite some oversampling and the actual resolution for the RMS value can be quite a bit higher, going up with the square root of the number of readings used. There is a little lost for the suppression of the ADCs DC offset though.

author: Red_Micro
author_rank: Regular Contributor
timestamp: April 18, 2020, 07:37:21 am
content: Quote from: Kleinstein on April 18, 2020, 07:13:21 amIn my application I don’t need to calculate RMS strictly. Finding the peak would be enough. I’m thinking of taking 100 samples every 200us and finding the peaks. But I’m not sure, as I’m a bit confused about the relationship between the current and the ADC count.

author: Rerouter
author_rank: Super Contributor
timestamp: April 18, 2020, 08:03:39 am
content: For finding the RMS, you only need to invert the polarity of any negative samples, and add over a fixed time window, the average is the RMS, (in reality its meant to be square the value then take its square root, but its faster to just compare on most micros), nothing to do with finding peak values.

author: Karel
author_rank: Super Contributor
timestamp: April 18, 2020, 10:01:28 am
content: Quote from: Rerouter on April 18, 2020, 08:03:39 amIt's not.Simply square all samples, then take the average, then take the square root of the average. But it only works accurately enough if the samplerate is high enough relative to the base frequency of the signal of interest. For 50 Hz, start thinking about a samplerate of a couple of KHz.

author: Rerouter
author_rank: Super Contributor
timestamp: April 18, 2020, 10:22:44 am
content: Squaring all samples turns all negative numbers positive, Taking a square root of the average of these numbers gives the same result as what I suggested,The difference being, the data type for the average becomes at least twice as long, and the square root in the common math library involves treating it with floating point math, so much longer to processI agree the sample rate could be higher for the task,

author: Kleinstein
author_rank: Super Contributor
timestamp: April 18, 2020, 11:13:37 am
content: The square root for the RMS value is slow and may need quite some code. Still it is needed only once. For the modern µCs calculating the square is not a big deal with data coming at a few kHz.One can still check for the maximum and minimum, but this is more sensitive to noise and does not get extra resolution from oversampling.It may be needed to make sure would does not hit the limits.

author: Karel
author_rank: Super Contributor
timestamp: April 18, 2020, 01:36:48 pm
content: Quote from: Rerouter on April 18, 2020, 10:22:44 amNo,Quote from: Rerouter on April 18, 2020, 08:03:39 amdoes not give the same result.

author: ejeffrey
author_rank: Super Contributor
timestamp: April 18, 2020, 02:59:54 pm
content: The rms of a sinewave is 1/sqrt(2) ~ .707. the absolute average is 2/pi ~ .637. not the same at all.You can do sqrt pretty fast if you don't need to handle full floating point resolution and range. For a integer or fixed point you can just use a lookup table and do linear interpolation if you want. That would only require a few additions and a single multiplication, plus a small amount of flash memory for the table. But that probably isn't worth it for such a low speed application

author: Siwastaja
author_rank: Super Contributor
timestamp: April 18, 2020, 03:09:27 pm
content: Rerouter,Summing absolute values is completely different than summing squares. The latter gives rms when you take sqrt of the sum. Which one you want to use depends on what you need, but they are not the same. Squaring puts more emphasis on large values.Depending on instruction set, squaring (x*x) is likely faster, or at least not any slower than abs(x), hence if you want RMS, you don't even save time by calculating sqrt(sigma(abs)) instead.If the window from which you calculate RMS is long, the sqrt operation is a small portion, even if your instruction set doesn't implement sqrt. Note, often you just compare things to a threshold, or log it somewhere; in these cases, you don't need to calculate sqrt. Square the comparison threshold instead. Or, calculate sqrt after logging.On peak detection, do note that you don't want to detect infinitesimally short peaks, otherwise you are just measuring noise. For example, if you sample at 1MSPS, and want toactuallydetect 1ms peaks, you can average 1000 samples, then detect peaks. So specify your "peak length" first; don't try to detect peaks that are so short that they don't actually appear on the signal of interest.

author: Red_Micro
author_rank: Regular Contributor
timestamp: April 19, 2020, 05:20:57 am
content: See attached my circuit. This is my approach:My CT is 1000 turns secondary. It has high sensitivity so I can read down to mAs.For a range of currents: 5 mA to 500 mA, switch is closed, so the gain becomes ~62.For a range of >500mA to 30 A, switch is open, the gain becomes ~1.I have designed both ranges so that at max current level, the peak-to-peak voltage is not greater than 3V.Doing some quick calculations:For 10 mA through the primary, 10 uA secondary multiplied by the burden 30 ohms = 300uVrms = 424.26 uVpeakAmplifying this: 424.26 uVpeak * 62 = 26.3 mVpeakADC count = 26.3*4095/3.3 = 33 countsFor 15 mA I get 50 counts. So there's a difference around 18 counts between 10 mA to 15 mA. Is it enough to deal with noise?Overall, do you think I'm in the right path?

author: Kleinstein
author_rank: Super Contributor
timestamp: April 19, 2020, 09:44:44 am
content: For just single ADC readings there can be noise in the 1 LSB range, maybe more. So 18 LSB for the 5 mA step is than not much but usually still well visible.For the RMS readings one would have many more readings averaged, more like 10000 readings over 1 second. This would reduce the noise level nearly 100 times. So there should be no problem resolving better than 1 mA maybe even 0.1 mA.However at low levels there can be an effect of external hum that can cause trouble at low low levels. So good shielding can be important if one really needs to measure low levels.