Author Topic: Understanding this ADC resolution calculation  (Read 1691 times)

0 Members and 1 Guest are viewing this topic.

Offline Red_MicroTopic starter

  • Regular Contributor
  • *
  • Posts: 122
  • Country: ca
Understanding this ADC resolution calculation
« on: April 18, 2020, 06:12:00 am »
From this article the author has a 1000 turns CT and a 100 ohms burden resistor. He states:

Quote
A simple 12bit ADC will give us 2^12, or 4096 possible values. Applied to a 3300mV range, this gives us a resolution of about 0.8mV. The load pictured above has a total peak-to-peak voltage span of 1219mV, and should be about a 4.5-4.7A load. The 1219mV give us a possible 1513 values for the voltage displayed at our calculated resolution, which translates to about 3mA per ADC value when using our 100 ohm load resistor (remember: it’s RMS!). That’s more than enough for this 10 amp sensor. However, as you start reading larger and larger amperages or use a current transformer with many more turns than the AC1010, this may fall short of your requirements.

He says the resolution translates to 3mA per ADC count. If I do calculations I get:
3 mA /1000 = 3 uA
3 uA * 100 = 300 uV (rms)
Vburden_peak = 300 uV * 1.41 = 424.26 uV
Vburden_pkpk = 424.26 * 2 = 0.84 mV

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

Offline PartialDischarge

  • Super Contributor
  • ***
  • Posts: 1625
  • Country: 00
Re: Understanding this ADC resolution calculation
« Reply #1 on: April 18, 2020, 06:34:02 am »
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:






« Last Edit: April 18, 2020, 06:35:45 am by MasterTech »
 
The following users thanked this post: Red_Micro

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2275
  • Country: 00
Re: Understanding this ADC resolution calculation
« Reply #2 on: April 18, 2020, 07:03:20 am »
Also good to know:

"Coding Schemes Used With Data Converters"

http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sbaa042
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 15157
  • Country: de
Re: Understanding this ADC resolution calculation
« Reply #3 on: April 18, 2020, 07:13:21 am »
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.
 

Offline Red_MicroTopic starter

  • Regular Contributor
  • *
  • Posts: 122
  • Country: ca
Re: Understanding this ADC resolution calculation
« Reply #4 on: April 18, 2020, 07:37:21 am »
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.


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

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4705
  • Country: au
  • Question Everything... Except This Statement
Re: Understanding this ADC resolution calculation
« Reply #5 on: April 18, 2020, 08:03:39 am »
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.


 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2275
  • Country: 00
Re: Understanding this ADC resolution calculation
« Reply #6 on: April 18, 2020, 10:01:28 am »
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.

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

 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4705
  • Country: au
  • Question Everything... Except This Statement
Re: Understanding this ADC resolution calculation
« Reply #7 on: April 18, 2020, 10:22:44 am »
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 process

I agree the sample rate could be higher for the task,
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 15157
  • Country: de
Re: Understanding this ADC resolution calculation
« Reply #8 on: April 18, 2020, 11:13:37 am »
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.
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2275
  • Country: 00
Re: Understanding this ADC resolution calculation
« Reply #9 on: April 18, 2020, 01:36:48 pm »
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,

No,

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

does not give the same result.
« Last Edit: April 18, 2020, 01:38:30 pm by Karel »
 
The following users thanked this post: Siwastaja

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 4034
  • Country: us
Re: Understanding this ADC resolution calculation
« Reply #10 on: April 18, 2020, 02:59:54 pm »
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
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 9336
  • Country: fi
Re: Understanding this ADC resolution calculation
« Reply #11 on: April 18, 2020, 03:09:27 pm »
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 to actually detect 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.

« Last Edit: April 18, 2020, 04:11:43 pm by Siwastaja »
 

Offline Red_MicroTopic starter

  • Regular Contributor
  • *
  • Posts: 122
  • Country: ca
Re: Understanding this ADC resolution calculation
« Reply #12 on: April 19, 2020, 05:20:57 am »
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 uVpeak
Amplifying this: 424.26 uVpeak * 62 = 26.3 mVpeak
ADC count = 26.3*4095/3.3 = 33 counts

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

 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 15157
  • Country: de
Re: Understanding this ADC resolution calculation
« Reply #13 on: April 19, 2020, 09:44:44 am »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf