I thought this would be a relatively straightforward research project this morning, but I've been unable to find some answers to what I thought were three pretty simple questions.
My design uses the ATmega32A, but the questions would apply to any AVR mega with support for differential ADC input.
1. The conversion formula is: ADC = (Vin * 1024) / Vref.
Table 26-3 tells us that there are four possible selections for the reference (of which three are valid): the full AVCC, the internal 2.56V reference (which many have suggested is not that good), and an external reference. The the internal 2.56 reference make sense and allows the hardware a fairly easy path to the binary division. I'm unsure how the division works when VCC is within the acceptable range.
If the external VREF is chosen and is 2.56 V, then presumably we gain the extra precision of conversion (assuming the external reference is "better" than the internal). So far, so good.
But what happens when the reference is not 2.56 V? I haven't seen any register that is set to the new denominator value (and I can't imagine that there is actually a hardware divider built-in for a generic division). Or, does this mean that only 2.56 V may be used as an external reference?
BTW: I've wondered if the solution to this is that the binary output of the ADC must itself be converted later by application-level code which "knows" the value of the Vref.
2. Differential ADC inputs.
And this brings me to the closely related question. I want to measure the (small) voltage drop across a shunt resistor. One of the advantages of the differential input is that, given an appropriate VREF value, the effective resolution of the conversion can be increased to handle closely the range of the desired differential inputs.
In the final design, there likely will be an opamp to buffer and scale the shunt resistor voltage. But the main question remains: what happens, say, if I select a 1.5 V reference, then scale the shunt voltage to something close to, but lower, than 1.5 V? I'm still left with question #1: how to "tell" the formula that Vref is not 2.56 V and is 1.5 V instead (as an example).
3. A schematic that actually shows an ATmegaXxx connected to a differential source.
This really surprised me. I found lots of articles telling me that I can perform differential ADC but not one schematic, or even code sample, that actually shows this being done.
The complete datasheet has not been helpful to answer these questions either.
So, anyone out there actually use an external reference that is not 2.56 V? Did you need downstream code to "complete" the value conversion? And, does anyone have a link to a (working!) schematic that uses differential ADC?