Just tried it today. I derived something that makes a bit of sense from Freescale's sign-inverted, reciprocal computation. They compute temperature as a delta of -1.715 mV/C where 25C measures 719 mV.
Converting from volts to C: slope is negative, and reciprocal of 1.715 mV/C, which gives
deltaC = - 583.0904 deltaV
I set the 1.2V reference in a hopeful attempt to get stability;
I used 12 bit conversions, with no averaging;
deltaV = deltaA2D * 1.2 / 4096
deltaC = deltaA2D * (1.2 / 4096) * -583.0904 = deltaA2d * -0.17083
25C is 719 mV which the A/D would read as 2454.19
The result, if one used floating-point arithmetic would be:
C = 25.0 + 0.17083 * (2454.19 - a2d)
It is possible to scale everything to stay in the world of integer arithmetic. Scaling everything by 16384 (2 ** 14) produces the following. I add 8191 to the multiplied result to round the result rather than truncating it.
= 25 + (2799 * (2454 - a2d)
= 25 + 419.25 - 0.17083 * a2d
= 444.25 - 0.17083 * a2d
To test...
2454 --> 25.033 C
2448 --> 26.06 C
I performed a further optimization in my code scaling by an additional factor of 100 to make reporting of 1/100 C easier:
100 * C = 44424.93 - 17.0827 * a2d
Scaling by 4096 (that's the max available to prevent integer overflow in 32 bits),
17.0827 * 4096 = 69970.845 rounded to 69971
44424.93 * 4096 = 181964504.1 rounded to 181964504
c * 100 = (181964504 - 69971 * a2d) >> 12
To print the value, I use "sniprintf" (integer only snprintf):
sniprintf(mybuf, sizeof(mybuf), "a2d: %04x %d temp: %d temp: %d.%02d\r\n", a2d, a2d, temp100c, temp100c/100, temp100c % 100);
And now some output from a teensy3 riding on top of my monitor:
Code:
a2d: 095a 2394 temp: 3528 temp: 35.28
a2d: 0958 2392 temp: 3562 temp: 35.62
a2d: 095a 2394 temp: 3528 temp: 35.28
a2d: 0956 2390 temp: 3597 temp: 35.97
a2d: 0958 2392 temp: 3562 temp: 35.62
a2d: 0957 2391 temp: 3580 temp: 35.80
a2d: 095a 2394 temp: 3528 temp: 35.28
a2d: 0959 2393 temp: 3545 temp: 35.45
a2d: 0958 2392 temp: 3562 temp: 35.62