User Tools

Site Tools


info:one_wire_temp_conversion

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

Temperature conversions

Fahrenheit to Celsius

C = (F - 32.0) / 1.8

Celsius to Fahrenheit

F = (C * 1.8) + 32.0

C source

float C_to_F_degrees( float temp )
{
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

unsigned int temperature;
float tempf;
tempf = 32.0 + (9.0*(float)temperature)/10.0;
temperature = tempf + 0.5; integer Fahrenheit

One Wire PH Anderson
LowByte = OneWireInByte(_1W_Pin);
HighByte = OneWireInByte(_1W_Pin);
TReading = (HighByte « 8) + LowByte;
SignBit = TReading & 0x8000;
test most sig bit
if (SignBit) negative
{
TReading = (TReading ^ 0xffff) + 1;
2's comp
}
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
Fract = Tc_100 % 100;

if (n==0) if its the first time, clear the LCD
{
Serial.print(“?f”);
delay(100);
}
if (SignBit)
If its negative
{
Serial.print(“-”);
}
Serial.print(Whole);
Serial.print(“.”);
if (Fract < 10)
{
Serial.print(“0”);
}
Serial.print(Fract);
Serial.print(“?n”);
}
delay(5000); 5 second delay. Adjust as necessary
}

info/one_wire_temp_conversion.txt · Last modified: 2008/09/20 11:54 by tomgee