# ExternalDifferential ADC Values for PIC

I have a temperature sensor design that I'm using as a reference. It takes 2 RTD sensors and reads their values with a Dual Channel 16-bit Differential ADC. The ADC interfaces through the SPI bus.

I know for a general ADC you can take the formula:

Voltage on Pin (in mV) = [(ADC Value) * (System Voltage in mV)]/(Max ADC Value)


I'm just not sure how it directly applies to a differential ADC

Here is my reference code (applicable to only one of the channels):

//--------------------------------------------------------------
// Temperature in degrees C
//
// Platinum (3850 ppm/K) RTD sensor
// 0 to 850 degrees C, Rt = R0(1 + A*t + B*t^2)
//   Rt = resistance at temperature (degrees C)
//   R0 = is resistance at 0 degrees C, which is 1,000 ohms
//   A  = 3.9083 * 10^-3
//   B  = -5.775 * 10^-7
//
//   (R0 * B)t^2 + (R0 * A)t + (R0 - Rt) = 0
//
//     x = (-b +/- SQRT(b^2 - 4ac)) / 2a
//
// therefore:
//       (-(R0 * A) +/- SQRT((R0 * A)^2 - (4 * (R0 * B) * (R0 - Rt))
//   t = -----------------------------------------------------------
//                           2 * (R0 * B)
//
//       (-3.9083 +/- SQRT(15.2748 - ((-2.3104 * 10^-3) * (1,000 - Rt)))
//     = ------------------------------------------------------------------
//                             -1.1552 * 10^-3
{   float Vr, Rt;
Vr = ((ADC_Meas * 1.25) / 32768.0) + 2.5;
Rt = (1000.0 * Vr) / (5.0 - Vr);
t = ((-3.9083) + sqrt(15.2748 - (-0.0023104) * (1000.0 - Rt))) / (-0.0011552);
}
//--------------------------------------------------------------


What I'm trying to understand is how the two formulas for the Vr and Rt were devised?

Also I am still a little bit confused about how the differential ADC works.

I believe in a typical ADC we give the REF+ and REF- voltages and the resulting reading for a given channel is the ratio of how close it is to REF+ starting from REF-.

For example for a regular 16-bit adc a reading of 0 would mean our input is 0 (or equal to REF-) and a reading of 65536 would mean our channel is equal to REF+.

I suppose what I'm confused about is how a differential ADC relates to the standard ADC. based on the standard ADC example I would think that the input value must stay inside the REF-/+ values but from the example circuit I have for a differential ADC it seems that this is not necessarly the case. So how do I know what the ADC is tied to and how to associate it with the REF values?

For Vr, the formula is based on the information in the datasheet. In the datasheet, it says the differential range will be from -0.5 * Vref to 0.5 * Vref. Vref in your schematic is 2.5V, and both channels - pin is at 2.5V, so the range is from 1.25V to 3.75V, which will be interpreted as -1.25V to +1.25V in the readings (it outputs a signed 16-bit integer format)

The 0°C point is 2.5V, so 2.5V to 3.75V, is the positive half of the range, and 1.25V to 2.5V for negative temperatures. The ADC sees 2.5V as 0V though, hence the use of +1.25V in the Vr formula, and 32678 (i.e. signed 16-bit integer rather than 65536 for full unsigned 16-bit) and we add 2.5V on to get the actual voltage (since the ADC's zero point is at 2.5V)

So for example, if we read 0x661E (26142) from the ADC, we can use the formula:

$\dfrac{26142 \cdot 1.25V}{32678} + 2.5V = 1V + 2.5V = 3.5V$

For Rt, it's just a formula to work out the resistance based on the voltage divider the sensor resistance forms with the 1kΩ resistor. It works by comparing the ratio of voltages across each part of the divider (the fixed 1kΩ and the PT sensor)
From the PT formula, we know R0 is 1kΩ, so at 0°C the sensor will be this resistance, and because we effectively have a voltage divider of 2 1kΩ resistors with 5V at the top, the voltage in the middle should be 2.5V, so the formula should give us 1000 at 2.5V.
Say we had 3V for Vr, we would expect a resistance reading of 1.5kΩ (1.5k is 3/5ths and 1k is 2/5ths of 5V),

If we plug 3V into the formula to check, we should get the predicted result:

$\dfrac{3V \cdot 1000}{5V - 3V} = 1.5k\Omega$

• instead of -0.5*Vref to 0.5Vref could I think of it like. 0.5*(-Vref) to .5 * (Vref) so basically I'm taking half of the difference to the negative reference and half the difference to the positive reference? – user16105 Apr 25 '13 at 19:49
• Yes, you can think of it that way if you like. Essentially you only need to worry about 0 to 32678 (which corresponds to 2.5V to 3.75V), since the "negative" half of the range (1.25V to 2.5V) is not being used. – Oli Glaser Apr 25 '13 at 20:10
• Actually you will get negative values when the measured temperature is below zero (degree Celsius). Then the RTD is less then 1000 ohm, so the voltage on CH0+/CH1+ will be less then 2.5V. Then its lower than the voltage on CH0-/CH1-, and then you get negative results. But the calculation of Rt should work then too. – hli Apr 26 '13 at 9:40
• I guess I'm still a little confused as to the references. I'll try to edit my question so hopefully it'll make more sense. – user16105 Apr 26 '13 at 12:27
• @hli - good point, not sure why I was assuming the range was from zero degrees C upwards. 2.5V is the zero reference point (which corresponds to a zero signed reading on the ADC) – Oli Glaser Apr 26 '13 at 13:11

For the $V_r$ calculation:

• $V_{ref}=\frac{V_{cc}}{2}$, therefore $V_{ref}=2.5V$
• the differential input range is from $-0.5*Vref$ up to $0.5*Vref$, therefore from -1.25...1.25V
• the result is in two's complement, with bit 15 as MSB, so the input ranges from -32768 to 32767
• (bit 16 acts as additional sign bit, and together with bit 15 acts as overflow / underflow indicator. You might want to check this - look at pages 10+11 in the data sheet)

Try to rewrite the formula as: $$V_r=\frac{ADC_{Meas}}{32768}*1.25+2.5$$ then you see what happens:

• first you scale the measured value to the full range
• then you multiply it with the full range voltage (1.25V)
• then you add the common mode voltage (2.5V)

The same goes for $R_t$:

• Rt and the 1k resistor form a voltage divider
• the formula for a voltage divider is $\frac{R1}{R2}=\frac{V1}{V1}$
• the voltage across the 1k resistor is $5V-Vr$
• so the formula is $\frac{R_t}{R1k}=\frac{V_r}{5-V_r}$
• when you solve this for $R_t$, you get the formula above