User Tools

Site Tools


info:one_wire_temp_conversion

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
info:one_wire_temp_conversion [2008/06/23 20:14] tomgeeinfo: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:c.gif|}} 
 +
 +{{info:f.gif|}}
 +
 ===== 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 22: Line 55:
 tempf = 32.0 + (9.0*(float)temperature)/10.0;\\ tempf = 32.0 + (9.0*(float)temperature)/10.0;\\
 temperature = tempf + 0.5;                         // integer Fahrenheit\\ temperature = tempf + 0.5;                         // integer Fahrenheit\\
- +\\ 
-**One Wire PH Anderson**+**One Wire PH Anderson**\\
  
 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;  // test most sig bit +SignBit = TReading & 0x8000;  // test most sig bit\\ 
-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 its the first time, clear the LCD +if (n==0)  // if its the first time, clear the LCD\\ 
-+{\\ 
-Serial.print("?f"); +Serial.print("?f");\\ 
-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("0"); +Serial.print("0");\\ 
-+}\\ 
-Serial.print(Fract); +Serial.print(Fract);\\ 
-Serial.print("?n"); +Serial.print("?n");\\ 
-+}\\ 
-delay(5000);      // 5 second delay.  Adjust as necessary +delay(5000);      // 5 second delay.  Adjust as necessary\\ 
-}+}\\
  
  
info/one_wire_temp_conversion.1214266457.txt.gz · Last modified: 2008/06/23 20:14 by tomgee