info:one_wire_temp_conversion
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
info:one_wire_temp_conversion [2008/06/23 20:14] – tomgee | info:one_wire_temp_conversion [2008/09/20 11:54] (current) – tomgee | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Lessons Learned ===== | ||
+ | |||
+ | For the temperature devices, the family code is important. A Family code | ||
+ | of 0x28 is the 18b20 and contains a 12 bit data register with the least 4 bits | ||
+ | indicating digits to the right of the decimal point. The 18s20 with a family code | ||
+ | of 0x10 only has one digit to the right of the decimal point and thus you need to | ||
+ | account for this in temperature conversions. | ||
+ | |||
+ | If you don't allow enough time for the device to convert you will read the default | ||
+ | startup temperature data which is 0x0550 on the DS18b20 and is a default temp of 185 F. | ||
+ | In addition, when a conversion is started using parasitic power, the bus must be held high | ||
+ | with a strong pullup. I have been turning the AVR output driver on for this instance. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== The Formulas ===== | ||
+ | |||
+ | {{info: | ||
+ | |||
+ | {{info: | ||
+ | |||
===== Temperature conversions ===== | ===== Temperature conversions ===== | ||
Line 9: | Line 36: | ||
F = (C * 1.8) + 32.0\\ | F = (C * 1.8) + 32.0\\ | ||
- | ==== C source ==== | + | ===== C source |
float C_to_F_degrees( float temp )\\ | float C_to_F_degrees( float temp )\\ | ||
Line 15: | Line 42: | ||
return( (temp * 1.8) + 32.0 );\\ | return( (temp * 1.8) + 32.0 );\\ | ||
}\\ | }\\ | ||
+ | |||
+ | float F_to_C_degrees( float temp )\\ | ||
+ | {\\ | ||
+ | return( (temp - 32.0) / 1.8 );\\ | ||
+ | }\\ | ||
+ | |||
==== Converting C to F for One Wire ==== | ==== Converting C to F for One Wire ==== | ||
Line 27: | Line 60: | ||
LowByte = OneWireInByte(_1W_Pin); | LowByte = OneWireInByte(_1W_Pin); | ||
HighByte = OneWireInByte(_1W_Pin); | HighByte = OneWireInByte(_1W_Pin); | ||
- | TReading = (HighByte << 8) + LowByte; | + | TReading = (HighByte << 8) + LowByte;\\ |
- | SignBit = TReading & 0x8000; | + | SignBit = TReading & 0x8000; |
- | if (SignBit) // negative | + | if (SignBit) // negative\\ |
- | { | + | {\\ |
- | TReading = (TReading ^ 0xffff) + 1; // 2's comp | + | TReading = (TReading ^ 0xffff) + 1; // 2's comp\\ |
- | } | + | }\\ |
- | Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25 | + | Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25\\ |
- | Whole = Tc_100 / 100; // separate off the whole and fractional portions | + | Whole = Tc_100 / 100; // separate off the whole and fractional portions\\ |
- | Fract = Tc_100 % 100; | + | Fract = Tc_100 % 100;\\ |
- | if (n==0) | + | if (n==0) |
- | { | + | {\\ |
- | Serial.print("? | + | Serial.print("? |
- | delay(100); | + | delay(100);\\ |
- | } | + | }\\ |
- | if (SignBit) // If its negative | + | if (SignBit) // If its negative\\ |
- | { | + | {\\ |
- | Serial.print(" | + | Serial.print(" |
- | } | + | }\\ |
- | Serial.print(Whole); | + | Serial.print(Whole); |
- | Serial.print(" | + | Serial.print(" |
- | if (Fract < 10) | + | if (Fract < 10)\\ |
- | { | + | {\\ |
- | Serial.print(" | + | Serial.print(" |
- | } | + | }\\ |
- | Serial.print(Fract); | + | Serial.print(Fract); |
- | Serial.print("? | + | Serial.print("? |
- | } | + | }\\ |
- | delay(5000); | + | delay(5000); |
- | } | + | }\\ |
info/one_wire_temp_conversion.1214266496.txt.gz · Last modified: 2008/06/23 20:14 by tomgee