Interesting.
I don't think I've ever seen this anomaly before.
It's often convenient to think of a SAR ADC as if it samples the input analog voltage at some instant in time.
In practice, there is a narrow window of time where changes in the input analog voltage --
or noise on the analog voltage reference, or noise on the GND or other power pins of the ADC --
can affect the output digital value.
If the input voltage is slowly rising during that window, then the less-significant bits of the SAR output will be all-ones.
If the input voltage is slowly falling during that window, then the less-significant bits of the SAR output will be all-zeros.
A very narrow noise pulse at the "wrong" time during conversion can have a similar effect.
Right now my best guess is that you're using some sort of analog switches or op amps that don't work quite as well (higher resistance or something) near the high and low power rails as they do near mid-scale, somehow letting in one of the above kinds of noise, which causes the less-significant bits to be all-ones or all-zeros.
I've seen some sigma-delta ADCs and sigma-delta DACs that have good resolution at mid-scale, but worse resolution near the rails -- but the effect looks different than what you show.
The "plot of the difference between one sample and the next sample over the entire full scale range" is fascinating.
If I were you, I would make a similar plot that, instead making the X value the difference between one sample and the next, make the X value the least-significant 6 bits of the raw ADC output sample.
That would quickly show if the "stuck" values are mostly lots of 1s in the least-significant bits (maybe input is slowly rising?) or lots of 0s in the least-significant bits (maybe input is slowly falling?).
I am sampling "pulsed" DC voltages. That means that for each
measurement I put a voltage on the DAC, let it settle for at least 100
times it's settle time, then tell the ADC to convert - and when
conversion is finished, I put the DAC back to 0 V.
My understanding is that when ADC manufacturers say "no missing codes",
the test they use involves several capacitors adding up to a huge capacitance directly connected to the ADC input,
and some system driving a large resistor connected to that capacitance that very slowly charged or discharged that capacitor,
slowly enough that the ADC is expected to see exactly "the same" voltage (within 1/2 LSB) for several conversion cycles before it sees "the next" voltage (incremented by 1 going up, decremented by 1 going down).
If I were you, I would see if such a "continuous slope" test gives the same weird "stuck code" symptoms as the "pulsed test".
Perhaps that would give more clues as to exactly what component(s) are causing this problem.
Please tell us if you ever figure out what caused these symptoms.
The problem has been solved.
function X = ReadTiAdcData(filename,N)
fid = fopen(filename,'r');
X = fread(fid,'int16');
fclose(fid);
X = X-2^(N-1);
X = X./2^(N-1);
Jim B's post explains the HSDC's binary file encoding and how to convert from it. N = 12. Turns out the full scale voltage didn't matter because we just needed the scaled voltage level relative to full scale, which was already encoded in the binary file, "full scale" being 4096.
I hope this is helpful for those who are struggling with converting raw ADC data using the TI HSDC.
Best Answer
According to the schematic, there is a 10k--6.8k resistor divider in the circuit.
6.8k / (6.8k + 10k) = .4047619 1/.4047619 = 2.470588
Another place to look might be:
__lsb = float(0.0000078125) # default lsb value for 18 bit 7.8125e-6 * 2^18 = 2.048 // full-scale value? 5V / 2.048 = 2.441406
Or maybe some combination of those things.
Sorry I don't have time to analyze the whole datasheet, but both of those numbers are close to your magic number.
I encourage you to work through it step by step and try to get it figured out fully -- to the point where your results match within a few mV. There is going to be a right answer, and it will help if you keep track of your units (mV, LSBs, etc)
You can learn a lot about how digital systems talk to the real world!