@PaulStoffregen
Several times I've considered making an ADC shield. Might still do it. Recently have been playing with a relatively cheap (~$4) single channel 16 bit ADC chip and a 8:1 mux, both controlled with FlexIO. Input setting time is a difficult problem which leads to channel crosstalk, so not a simple thing, especially if running at speeds like 300-500 ksamples/sec. Of course there are chips with the mux built in, but the cost goes up quickly.
I hope you can understand with the built-in ADC, we simply have to live with whatever NXP provides. I really wish they would have done better. They probably do too, since they could sell more chips. But it's not so simple. Generally speaking, the improvements in silicon which allow digital circuits to run faster tend to make analog circuit less precise. With the much older & slower silicon used by Teensy 3.2, they were able to make the ADC better because the transistors were different, and specially certain analog circuits like a differential pair amplifier can be more precisely made than in chips meant for faster digital circuitry.
First, aside, Paul have you tried that ADC we talked about somet time ago? That one has a mux and can share one opamp for all of the channels. I will post or send you the design files if anyone is interested, with the proviso that it is work in progress, I wanted to make another pass over package sizes and layout. Admittedly it might not be $4 all counted, but it seems pretty good.
Also, aside, I will be posting a really good analog input, maybe in the next few days, with a custom InAmp front end and high precision differential ADC. It connects by SPI.
Okay, now to the bit about why the analog inputs on microcontrollers are the way they are. I put a lot of time into investigating this recently. It is pretty interesting, in some ways. So far I have not found an exception to the following.
(Paul - is there any way to repost this to its own topic? I think it could be of general interest. But read on, I leave it to your wisdon. Please do let me know what you think.)
A lot of what goes on in the internal analog inputs seems to be driven by a few factors; space (including the size of the sampling capacitor vs sampling noise), cost on silicon, single ended supply and market (who it is designed for).
a) Space on the chip and the size of the sampling capacitor versus precision
Noise in any sampling input is limited by the sampling capacitor, according to the famouse kT/C ("kay tee over sea") noise,
v >= sqrt( k T / C)
where kT at room temperature is about 25 meV. Multiply C by 6.2E18 e/coulomb, and you see you have units of volts, i.e. sqrt(V^2).
Now, let's say we want 16 bits on a 3.3V input, about 50uV. The sampling capacitor noise needs to be smaller than that, so lets say about 8 to 10pf at a minimum.
How about 12 bits? Then we need noise small compared to 0.8mV and noise for a 1pf capacitor 60uV.
The size of an internal cap is real estate in a chip. That is one reason 12 bits is common, and 16 bits less so.
In fact, as it turns out, the K20 16 bit inputs, have 8pf to 10pf sampling capacitors and the 12 bit inputs have 4pf to 5pf
b) Kickback
The analog input almost always involves a switched sampling capacitor. When the switch closes to connecft the capacitor to the input, current has to be supplied by the source, to charge the capacitor to the required precision of the input voltage.
This has two important consequences
i) The carge draws by the sampling capacitor becomes a current. The current spike works out to be a voltage spike of V/R where R is the impedance of whatever comes in front of the capacitor, including your source impedance for the thing you want to measure.
ii) The sampling capacitor needs time to reach the voltage of your input,
V_cap / V_input = 1 - exp(-t/RC).
That means that to get to the precision you need for n bits, you need a sampling time > nbits x ln(2) x RC
For a 10 pf capacitor, and 50 ohm source, we need t > nbits x 0.7 x 10 pf x 50 ohm = 6 nsecs. Not bad.
iii) But, faster sampling, lower source impedance, means more current draw, more kickbacl.
In the above example, 10pf cap, 16 bits, we might need to supply 3V/50 = 60mA.
You might say, well I need to drive the ADC with an opamp. But that is still a lot of current for many opamps.
So the way it is usually done, is to put an RC between the opamp and the sampling capacitor. Now the C in the RC acts as charge reservoir and the opamp only need supply a smaller current to replenish the charge reservoir.
Here is what it looks like if you only use an opamp. See the large spikes when the switch S1 closes.
And here is what it looks like with an RC between the opamp and sampling input. Now the red is current through C2, the cap in the RC in front of the input. Notice the current comes from that capacitor instead of being drawn as kick back through the opamp (or whatever else you might have attached if you were trying to use the analog input as a direct input).
iii) Cost and market
The above with the RC, is the right way to do it. But to do that you need a negative supply for the opamp. You also need an opamp.
Here is what manufacturers choose to do instead. Honest to goodness, this is from the K20 datasheet (the Teensy 3.2.
Notice the resistor Radin in front of the ADC SAR engine (the sampling cap is inside the SAR).
Radin is 2K. So the current drawn by the sampling capacitor cannot be larger than about 1.6mA.
But now we need a longer sampling window, t > 16bits x 0.7 x 10 pf x 2 kohm = 220 nsecs. That still fits the sampling speed for the Teensy.
And by the way, this is why they tell you anyway, not to use a large source impedance. If you put another large resistor in front then you might need to be careful about the length of your sampling window. That is the story beind many of those forum posts about funny readings for a 10k thermistor in a 20k divider.
Why do they do this? They could just give us a bare input, and let us worry about driving the SAR.
What that large resistor does, is at least two things. For a packaged source device, and slow measurements, it might be good enough. It also makes it possible for a hobbyist, to be able to use the input in some instances, without thinking about it too much.
The problem with that approach, is that it also makes it impossible to use the ADC input a more correct way. And there is a limited set of circumstances where it works to give a realistic voltage.
So that is the story of analog inputs on MCU chips.