Go Down

### Topic: Question regarding resolution (Read 3167 times)previous topic - next topic

#### Constantin

##### Mar 04, 2012, 02:41 pm
The other night, I thought about AC line power measurement resolution and I started wondering if I was barking up the wrong tree using a 12bit external ADC vs. the built-in quasi-10bit ones inside the Atmega 328P. So here goes:

The S22P current sensor has a linear output range of about 0.5-4.5V. So you essentially lose a Volt between the top and bottom end. Since I am unlikely to come up with a solution to only measure that range (I'm sure it's possible!) let's assume the actual measurement range is hence only 80% of the total. With a input range of 0-20A, that comes out to 20A / 80% x 1024 or a 0.0244 Amp resolution. On the voltage side, I'm assuming a 25% buffer for safety so my resolution is about 0.2V per bit. Multiplying the two suggests that I would be able to achieve a 0.005W resolution. Does that seem right?

If so, I may have to rethink my external ADC strategy. Yes, I may be able to practically eliminate phase shift error (it's a 2-channel ADC with simultaneous measurements) and speed sampling rates beyond the 5500/s limit I'm at now (with a 20MHz clock) but I don't think I would gain much in terms of usable precision, right? For all I now, the float calculations in the arduino are imprecise enough to obfuscate the benefits of a 12bit ADC....

#### retrolefty

#1
##### Mar 04, 2012, 04:55 pm
Quote
Since I am unlikely to come up with a solution to only measure that range (I'm sure it's possible!)

The arduino map() function can be your friend in this matter.

Quote
For all I now, the float calculations in the arduino are imprecise enough to obfuscate the benefits of a 12bit ADC....

That would have to be demonstrated to be factual or not. I tend to stay away from using floats as by using say proper scaling of the units and casting to use long ints, one can generally utilize all the resolution possible with internal or external AD conversion values even with 24 bit A/D converters.

Lefty

#### Constantin

#2
##### Mar 04, 2012, 07:36 pmLast Edit: Mar 04, 2012, 07:42 pm by Constantin Reason: 1
Hi there and thanks for the quick reply!

Interesting... How does the map function get around the problem of an ADC with one range and a voltage output of a more restricted range? It's not the output that's the question, it's that the range of voltages present for the ADC to sample is 0.5 above the minimum input and 0.5v below the maximum input. I would wager that a different sort of electrical magic would need to be used to have the ADC range overlap more broadly with the output of the current transducer. However, I'm inclined to leave the 20% on the table for simplicities sake.

As for keeping everything integer, that is a fine idea that I tried once to implement. I'll have another look at the code. It may work better this time around (with a two channel simultaneous ADC) since there will be no phase lag.

As it stands, the voltage measurement offers a theoretical 9.5 bits of resolution, the current is about the same. Does that mean that the two multiplied will offer something close to 19 bits?

#### robtillaart

#3
##### Mar 04, 2012, 11:00 pm
Quote
As it stands, the voltage measurement offers a theoretical 9.5 bits of resolution, the current is about the same. Does that mean that the two multiplied will offer something close to 19 bits?

yes,  it is similar to 12 x 12 = 144  - the number of digits grow, same for binary digits aka bits ..
That means that you need to use a long if you want to keep it in the integer domain,
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### Constantin

#4
##### Mar 04, 2012, 11:20 pm
Wowieee....

In other words myltiplying two 12 bit samples under similar circumstances could get me up to 23 bits of resolution.... So 16x better not just 4 as I expected. Issue is though whether the arduino can handle the math. That's some pretty big numbers coming its way!

Thanks you two, I appreciate the input.

#### borref

#5
##### Mar 05, 2012, 07:26 am
Two simultaneus samples will only give you an increased precision of 0.5LSB (half a bit). The following Atmel application note sheds some light on the topic of oversampling.

http://www.atmel.com/Images/doc8003.pdf

The map function does not increase precision in any way whatsoever. This is the simple equivalent of two lines of code to scale and offset a value.

Despite popular belief, using floats is typically faster and more efficient than using long integers on 8 bit RISC micros. Computation time is proportional to bits of precision and for longs you have 32 vs floats 24. There is an initial code size overhead of linking the float core library, but using floats typically simplifies calculatuions when the extended precision is required.

#### Constantin

#6
##### Mar 05, 2012, 01:15 pm
Hi BenF and thanks for replying.

I'm not sure how this is oversampling... the Arduino is sampling two different signals (voltage and current), the product of which is power. Multiplying the two respective resolutions (LSB of current and voltage) is how I got to the power resolution.

Thanks also re: the note on float calculations. One way that the external ADC will simplify things in the future is that the voltage and current are measured simultaneously, eliminating phase lag. That in turn removes some of the calculations that the Atmega has to engage in to calibrate the phase signals - as the Atmega ADC has to alternatively sample each signal, introducing phase shift.

#### borref

#7
##### Mar 07, 2012, 07:38 am
Resolution in terms of measurement is defined as the smallest change you can detect and is related to precision. When we combine two measurements (as in V*A for W), resulting resolution is the product of the measurement's respective precision (say 2LSB * 2LSB = 4LSB). That is, you can not trust the lower bits of your computed result.

To improve resolution/precision for your power meter, you will need to improve precision of the individual samples. One way to go is oversampling as outlined in the Atmel application note I referenced above. It is typically always preferred to oversample when precision is important and so sampling rate is as essential as bits per sample.

If you want use an external ADC, you may want to look for a component that can do differential input and use an external voltage reference.  This would allow you to use the full range of the ADC (say 12 bits for the 4V range from 0.5V to 4.5V).

Accuracy again is a different animal altogether as it defines how your final result relates to the real world. This depends on additional specifications such as linearity, variations across temperature, voltage reference stability and so forth. A careful choice of components may improve on this, but typically at a significant cost.

#### Constantin

#8
##### Mar 07, 2012, 01:24 pm
Spot on.

The original reason to go to an external ADC was the phase shift issue as well as the question how accurate the ADC in the Atmega really is. I figured that if I lost a LSB here or there from a 12 bit signal that it would impact measurements far less than if it happened to a 10 bit ADC. Plus, I could be more generous with the range that the ADC can sample if there are more bits to play with in the first place. That is, it is not as important to exactly match the electrical ranges of signal and ADC when you have spare bits, something that helps with allowing signals that may exceed spec for whatever reason.

My current design includes a 150V MOV and 1A slow-blow fuse. The thought being that significantly higher voltages will cause the MOV to do the marimba and blow the fuse.  But I may change some of the resistor values around to allow the system to sample up to 230Vrms signals, and then add a safety margin on top of that. All AC components are actually rated for 230V use (the transformer for voltage measurements, the current transformer, as well as the on-board power supply). Thus, I would be able to use the power board for 3-wire 230V as well, a nice to have for the rare instances where it is needed. Thing is, even a 16 bit accurate resolution on the product of voltage and current would resolve to less than 0.1W on a 5000W signal.

While I could use decimation to smooth out noise and improve accuracy further, the numbers get pretty big at high sampling rates (about 6,000/s are planned) and averaging may be the way to go. Previous attempts at decimation with large numbers and high sampling rates required me to keep track of the values inside the accumulators, then subtract large numbers that were easily divisible as the limits of the unsigned long range were approached. Can be done, but it's easier to implement on a 8 bit microprocessor if one only has to sample 1024 samples at a time, rather than 4096 to get to the desired resolution. Anyhow, off to feed the kids and thanks!

#### Constantin

#9
##### Mar 08, 2012, 05:57 am
OK, revised the board because the differential measurement aspects of the external ADC are confusing to say the least. So now everything is unipolar. I went back to my AC line safety exercise and changed the resistor values around to work with a 230V input. Then I added a zener diode instead of the Schottkys I was using to bias the signal and prevent the ADC from blowing up under extreme circumstances. I'd like to think that between the 275V MOV and the 450V+ input-tolerant voltage measurement circuit, we should be OK.

The only fly in the ointment is Pulse discontinuing the power transformer line and Digikey treating these transformers as non-stock. To replace them, I'd have to import them from Europe via Newark electronics. No big deal, just an additional \$20, please.

The other good news is that I managed to design two power measurement boards with different add-ons but with an identical GTP file. That's one less solder paste stencil I'll have to order. I also got a e-mail back from CUI re: my grounding question. For now, I'll still plan for a 1M resistor and a 2200pF, 2.2kV capacitor in parallel connecting the GND to the 120VAC GND. I can then experiment to see what the impact (if any) there is from having these through-hole components in place. If there is no benefit, I'll simply leave the holes empty.

Go Up