won't work...
0-5v output, actually running from .5v to 4.5v, 10bit ADC, -40F to 185F range?
4v total range, 10 bit ADC, lowest value readable from ADC = 102.4, highest value is 921.6, range of 819.2
185+40 = 225 degrees total range thru 4v input offset by 40 degrees F
ADC value - 102 = the .5v offset at the input
ADC value * 225 / 819 = something like .275 degrees per bit
But the result so far is offset by 40, so...
IF result < 40 then
result = 40 - result
sign = negative
else
result = result - 40
sign = positive
endif
DONE....
So run a test case...
Input value from ADC is 921, corresponding to a voltage of 4.5v
921 - 102 = 819
819 * 255 / 819 = 225
The result is larger than 40, so sign is positive and subtract 40 from it,
225 - 40 = 185
sign positive 185
BAM done...
Another case at minimum...
Input value from ADC is 102, corresponding to a voltage of .5v
102 - 102 = 0
0 * 255 / 819 = 0
The result is smaller than 40, so set the sign negative and subtract it from 40.
40 - 0 = 40
sign negative 40
BAM done...
Not only that, but a search on temperature display here at this site would've most likely been a heck of a lot simpler and might actually net you some premade code just for this application....
Bookmarks