TMP04 temperature sensor ? ?
Don Pomplun
Posts: 116
SEARCHing finds no hits for the AD TMP04 temperature sensor, so I'll ask if anyone has tried these with the Stamp. It outputs a TTL level pulse train at about 30 Hz whose duty cycle is linearly proportional to temperature. I'd like to incorporate temperature control as a lab project in my upcoming course, and this seems like a good candidate without having to add analog input circuitry.
TIA
Don
TIA
Don
Comments
www.phanderson.com/stamp/tmp04.html
That shows how easy it is to read the high and low times with PULSIN. The math there can be greatly simplified.
The calculation of temperature uses this formula:
TC_CALC: ' 2350 - (4000 * T1)/T2
and in the program the multiplication is done in a highly instructive manner as 4000 iterated additions and the diviision also as iterated subtractions.
If you want to pursue it, I could hobble together something faster and shorter using the Stamp's ** operator and a quick binary long division.. Also instructive, in its own way.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Dr. Allen,
I would definately like to see that if you have the time to put it together. I do have the components from Prof. Anderson..
TIA,
Paul
These devices are over $5 at DigiKey, even though the Analog Devices site shows them as half that in quantity. This might be a candidate for the Parallax store, eh?
-- Don
Ton VAR Word
Toff VAR Word
Temp VAR Word
start: PULSIN 0,1,Ton
PULSIN 0,0,Toff
Toff=Toff/100
Temp = 10*Ton/Toff*72
Temp=45500-Temp
DEBUG "Ton=", DEC Ton," Toff/100=",DEC Toff, " 100xTemp=", DEC Temp, CR
PAUSE 1000
GOTO start
That calculation makes it easy! I looks to me like that would give a real resolution of about 1/3 degree Fahrenheit.
The data sheet informs us that T1 (Ton) will be around 10 milliseconds, 12 maximum, and does not depend much on temperature, while T2 (Toff) will range from around 44 milliseconds at 125 degC down to around 15 milliseconds at -25 degC. On the Stamp, that is PULSIN values in the range of Toff = 7500 to 22000 (at 2 microseconds per count), and around 5000 for Ton.
Don, are those values typical of what you are seeing?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I guess I hadn't read the (16 page) data sheet very carefully, especially the part about Ton being pretty constant. But, yes it does seem to follow that. It's a little tough to follow my quick temp changes, but Ton seems to hover around 8.3 - 8.4 ms over a temp range of 4 - 117 F (pulsin values of 4144 - 4226). Over that same range, the Toff variation is 13.4 - 18.1 ms (pulsin 6694 - 9055).
What I tried may not be the optoimal approach for getting the best temperature reading. It was just the first thing that worked! It will start out being a good class discussion on the topic of overflow, and overcoming the limitations of integer arithmetic.
It looks like it should give enough resolution to do a temperature control lab.
-- Don
I did have a TMP04 (out of a box of samples!) At room temperature, I was getting T1 = 4346 and T2 = 8177 from a BS2pe. Using the data sheet formula, the temperature is 455 - (720 * 4346/8177) = 72.326 degrees Fahrenheit.
The easy compute1 formula loses precision in the T2/100 step, which is necessary to keep the computation in bounds, and it comes up with a reading of 69.08 degrees Fahrenheit, with a resolution of about 4.3 degrees. Did I get your formula right Don? As the sensor warmed up, the reading went from 69.08 to 73.4
The compute2 routine first uses binary long division to compute T1/T2 , approximated by the fraction degf/65536, and it finishes the computation to give a reading of 72.34 degrees Fahrenheit, with a resolution of 0.02 degrees.
I don't know if your students would be scared by the binary long division, but they shouldn't be. It is one of the most useful routines for math work/sensor signal processing on the Stamp.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I was taken aback by the course 4.3 degree resolution in the compute1 algorithm, but it makes sense when you follow it through. Here is an improvement, not quite as good as compute3, but about 0.3 degree Fahrenheit. (The accuracy Analog Devices claims for the sensor is 1.5 degrees Celsius typical, 4 degrees worst case).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks for the effort on your temperature Compute algorithms. It took some "soul searching" to the early days of long division to sort out. I like the 3rd one even better ;=)
Regards,
Don