Problem with DS18B20 Module when using negative temperatures

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Rickado
Registered User
Registered User
Posts: 17
Joined: Tue Apr 28, 2009 9:43 pm
Location: Dunedin, New Zealand

Problem with DS18B20 Module when using negative temperatures

Post by Rickado » Wed Dec 08, 2010 8:37 pm

Problem with DS18B20 Module when using negative temperatures

Public Sub GetTemp(ByRef pTemp As ShortInt, ByRef pFraction As Word)
and
Public Function GetTempAsStr() As String
Return incorrect negative Temperatures

From DS18B20 datasheet
-0.5 outputs %11111111 11111000 but module returns -1.5

-10.125 outputs %11111111 01011110 but module returns -11.875

-25.0625 outputs %11111110 01101111 but module returns -26.9375
the module does not do the 2's Complement on the full number



Here's a function that you might want to look at. It returns a float so you can compare temperatures , add temperatures, work out averages etc.

Code: Select all

{
*************************************************************** 
* Name : TempAsFlt 
* Purpose : Convert temperature to Float   pTemp = GetTemp 
* undefined bits return 0  from + and – temperatures ( tested) 
***************************************************************
} 
Public Function TempAsFlt(pTemp As Integer)  As Float
                         
  Result =  0.0625 * pTemp

End Function

Post Reply