A/D converter precision
Jeff15
Posts: 6
Does anybody have any experience using the MCP3202 A/D converter? I read the data sheet, but I don't really know what to make of the +/- 1 LSB detail. What does that mean in terms of accuracy, and how would I convert that to +/- volts?
Comments
If you have the analog side of the chip properly isolated and bypassed, you can expect to get 1 LSB of relative precision. However, even with a 0.02% voltage reference, perfect resistors, and proper calibration, that 1 LSB of absolute precision will be pretty elusive.
To reduce the need to become an analog circuit all-star, particularly at the breadboard stage, I would recommend oversampling & decimation. I take a minimum of 4 readings, usually 16, and sometimes as many as 4096 when I want to increase the resolution to 18 bits or so, which I can achieve on a breadboard with only a single 1 uF bypass cap on the MCP3304 digital supply.
To convert your 1 LSB to volts, you would take your voltage reference and divide it by the full range resolution of the ADC. For example, for a 3.3V reference, it would be 3.3V/2047, or about 1.6 mV. The 2047 comes from 11-bit resolution (12 bits minus 1 sign bit), minus 1 (2^11 - 1), for your 3202. A reading of 645 would be 645 / 2047 * 3.3V, or 1.040 V.
I think your statement is just a tad off. While there are 4096 possible values, there are 4095 steps.
I think it's easier to see why one should use 4095 for 12-bits, if instead of a 12-bit ADC we imagine a 2-bit ADC.
With just two bits, the possible outputs are 0, 1, 2 and 3. This gives only three steps. So the lsb would have the value of 5V/3, not 5V/4. Hopefully it's clear the each step up in the output corresponds to one third of the total voltage and not a fourth of the total voltage.
With a 12-bit ADC a single bit would represent a 5V/4095 change.
Of course the difference between 5/4095 and 5/4096 isn't much but I think it's a mistake worth fixing.
Always oversample in powers of 2, and accumulate (add) the results. Whatever power of 2 you use is how much your new full scale value increases. For example, if you oversample 16X (2^4), your new full range is 32767 (2^15 - 1), so an accumulated reading of 645 would be 645 / 32767 * 3.3 V,or 65.0 mV for a 3.3V reference.
In reality, you will only get an increase in usable resolution of about 2 bits, not 4 (divide the oversampling log2 by 2). This is the decimation, which serves to keep your expectations of increased precision in line.
As the other guys have said, it should be 4095 for a *single-ended* 12-bit ADC.
So, the examples become:
1 LSB = 3.3V / 4095 = 0.8 mV @ 3.3V ref
645 = 645 / 4095 * 3.3V = 0.520 V
w/16x oversampling: 645 / 65535 * 3.3V = 32.5 mV,
where the 65535 comes from (2^12 * 16) -1
Also, Thanks! you guys/gals are awesome!
Generally yes. Idealy you want your reference voltage to match the maximum voltage you expect to measure.
The MCP3304 handles a 0.5V ref before it reaches the diminishing returns threshold; I assume the 320x is similar. Look at the data sheet; it has curves of ENOB (effective number of bits) vs. ref voltage.
I use a 0.5 V ref with an MCP3304 and a 1 milliohm shunt at 4096x oversampling and resolve down to <10 uV that way (<10 ma), and it's doing that on a breadboard ATM. Even though I need to measure up to 70 V on another input, I just voltage divide it further to get below 0.5 V and all is well.
Duane, I don't think so. The 2-bit converter has really has 5 steps and 4 values. The fifth step is the end-point, call it 5 Volts.
0V to 1.25 V code %00
1.25V to 2.5V code %01
2.5V to 3.75V code %10
3.75V to 5V code %11.
You can read in the MCP3202 data sheet, section 4.2,
theoretical output code = 4096 * Vin / Vdd
Some ADCs specify the transfer function quite explicitly, for example, the LTC1298 is a similar 12 bit converter that specifies the first riser at 1/2LSB and the final riser at Vref - 1.5 LSB, so the codes change at the 1/2 bit points. The MCP3202 isn't so well characterized and has lots of room for errors, for example the offset (where the first riser occurs) can be off by as much as 3 bits.
Tracy, Thanks for the feedback. I was kind of wondering if I understood this correctly or not as I wrote the post above.
All the examples I can think of seem to work better if I use the "resolution - 1" in the conversion calculations.
I'll try to think of some examples to illustrate my confusion.
Okay, I think I can explain my confusion on this topic. Let's stick with the 4-bit ADC to make it easier. Let's call the values you listed above table 0.
I can see where a zero returned from the ADC is 0V to 1.25V as you suggest but I don't want two values, I just one a single value. This might be the crux of my problem. I want there to a 0V when the ADC is connected to ground. I suppose the lowest value should really be 0.625V since it's in the middle of 0V and 1.25V?
If we decide we're going to use the value halfway between the range for each possible ADC value then the voltages become: (Let's call these values table A.)
0.625V code %00
1.875V code %01
3.125V code %10
4.375V code %11
If the above values are correct, then the transfer function would be:
AdcReading * 5V / 4 + 0.625V (Let's call the function A.)
If instead we used the (likely erroneous) transfer function I had previously suggested:
AcdReading * 5V / 3 (Let's call the function B.)
We would get the following values: (Let's call these values table B.)
0V code %00
1.667V code %01
3.333V code %10
5V code %11
I'm relatively new to the world of microcontrollers and electronics but it seems to me function B has the appeal of giving results of both 0V and 5V. I confess to liking function B more than function A though I concede function A is a more accurate equation.
I think it was interesting while function A produced values (shown in table A) right in the middle of the range of possible values listed in table 0., the values produced in table B weren't in the center of the ranges listed in table 0 but they still fell inside (or at the edge of) the values listed in table 0.
My gut is telling me if we made similar tables for a 12-bit ADC the resulting values in table B would still fall inside the range of values listed in a table 0 for a 12-bit ADC.
It seems to me, the choice between using function A or function B doesn't make much of a difference provided the lsb of the returned value isn't important. I do think if one wanted/needed the precision of the lsb, the function A would likely produce better results.
I personally think the appeal having both, a zero volts value and a full range value, worth the small loss of precision resulting in using function B.
I'm going to try to remember about this loss of precision so I can use the more precise function A in places where the small bit of precision is important.
As I think about this a bit more, I see if one could completely trust the values coming from the ADC, function A would limit the error to 1/2 of the lsb. Function B increases the possible error up to a full lsb at the measurement extremes.
Every time I've said I'm not asking for you to explain something, you've gone ahead and explained it anyway (much to my benefit) but here again, I certainly don't expect you to educate me on the subtleties of ADC algorithms. I do hope you let me know if my understanding of the problem has significant flaws.
I certainly appreciate your challenge of my earlier post.
0.000 to 0.625V code %00
0.625 to 1.875V code %01
1.875 to 3.125V code %10
3.125 to 5.000V code %11
Now it has a narrow step down low and a wide step up high, like the LTC device. Keep in mind that is a theoretical transfer function. There are offsets and nonlinearity that varies from sample to sample. The data sheet specifies the limits of those errors.