Shop OBEX P1 Docs P2 Docs Learn Events
A/D converter precision — Parallax Forums

A/D converter precision

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

  • It looks like that's a 12 bit converter so each bit is the full range divided by 4096. For example, if you measure a 5 volt signal the error is +/- 5/4096, or a little more than 0.001 v
  • I haven't used the 3202, but I've used the 3304 a lot, which adds 1 more bit of precision and more inputs to the same method of ADC.

    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.
  • RDL2004 wrote: »
    It looks like that's a 12 bit converter so each bit is the full range divided by 4096. For example, if you measure a 5 volt signal the error is +/- 5/4096, or a little more than 0.001 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.
  • I forgot to explain the oversampling and decimation, in case you want to go that route. Actually, since the prop has 32-bit registers, I just skip the decimation; that will happen when you convert to a float or float string, anyway.

    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.
  • Nix my reference to the sign bit; the MCP3202 doesn't have one !

    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
  • If I lower my reference voltage, would that decrease error? Since 1LSB=Ref/Resolution=error in millivolts, would a lower ref really increase my precision, or am I not taking into account other factors?
    Also, Thanks! you guys/gals are awesome!
  • Jeff15 wrote: »
    If I lower my reference voltage, would that decrease error?

    Generally yes. Idealy you want your reference voltage to match the maximum voltage you expect to measure.

  • Duane Degn wrote: »
    I think your statement is just a tad off. While there are 4096 possible values, there are 4095 steps.
    ...
    Of course the difference between 5/4095 and 5/4096 isn't much but I think it's a mistake worth fixing.
    Yes, you're right. I always forget that -1 part.
  • Jeff15 wrote: »
    If I lower my reference voltage, would that decrease error? Since 1LSB=Ref/Resolution=error in millivolts, would a lower ref really increase my precision, or am I not taking into account other factors

    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.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2015-10-17 22:09
    Duane Degn wrote: »
    RDL2004 wrote: »
    It looks like that's a 12 bit converter so each bit is the full range divided by 4096. For example, if you measure a 5 volt signal the error is +/- 5/4096, or a little more than 0.001 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.

    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.

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

    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.

  • Tracy AllenTracy Allen Posts: 6,664
    edited 2015-10-18 00:05
    Steps vs values, they are not precise terms and can be confused. Is the step equivalent to the value, the flat part, or is it the action, the change from value to value? You can say there are 4096 binary values, and 4095 steps (risers) necessary to get through them all. Start at zero with code 0, then a riser at a time, and at last the 4095th riser up to %111... But it never takes the implied 4096th riser up the final end point (5.000V) where it would theoretically roll over to zero again.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-10-18 20:13

    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

    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.

  • Tracy AllenTracy Allen Posts: 6,664
    edited 2015-10-18 20:41
    While Microchip makes interesting analog products, analog is not their forte. Attached is the diagram of the theoretical transfer function of the Linear Tech LTC1298. You can see it follows the pattern kind of like your table A, and the error is limited to 1/2 bit. The first riser, when the output code goes from 0 to 1 occurs at the 1/2 bit point, and all successive risers also occur at 1/2 bit points. That makes the final output code, all ones, cover a 1+1/2 bits of input level. You'll have to be more specific about your table A, call it table A1:
    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.
    585 x 612 - 38K
Sign In or Register to comment.