Adapt MELABS DS18B20 example to show negative temperatures?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Adapt MELABS DS18B20 example to show negative temperatures?

    Hello.
    I'm using the melabs sample code for DS18B20 and it works fine.
    However, as it states:

    Code:
    
       OWOut DQ, 1, [$CC, $44]       ' Start temperature conversion
    
    
    waitloop:
       OWIn DQ, 4, [count_remain]    ' Check for still busy converting
       If count_remain = 0 Then waitloop
    
    
       OWOut DQ, 1, [$CC, $BE]       ' Read the temperature
       OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
    
    
       ' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
       temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    What should be fixed there to display negative temperature properly?
    As I've read DS18B20 datasheet, negative temperature output will always have 4 MSB bits set to 1111. But what's wrong with the above conversion formula?

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Adapt MELABS DS18B20 example to show negative temperatures?

    what part of this have you failed to understand
    http://www.picbasic.co.uk/forum/showthread.php?t=24650
    Warning I'm not a teacher

  3. #3
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Adapt MELABS DS18B20 example to show negative temperatures?

    I just had no idea same can be applied to DS18B20 readings

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Adapt MELABS DS18B20 example to show negative temperatures?

    What should be fixed there to display negative temperature properly?
    As I've read DS18B20 datasheet, negative temperature output will always have 4 MSB bits set to 1111. But what's wrong with the above conversion formula?
    you may have read the DS18B20 datasheet but you are using code for a DS18S20 so the first step is work out what you really have and then use the correct method
    Warning I'm not a teacher

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Adapt MELABS DS18B20 example to show negative temperatures?

    Well I have it running with DS18B20 and it displays positive temperatures just fine...

  6. #6
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Adapt MELABS DS18B20 example to show negative temperatures?

    I also used this:

    https://melabs.com/samples/LABX1-16F...emp_DS1822.htm

    But it is much slower.
    And I don't need high precision, this is just room temperature thermometer, 1C precision is ok.

Similar Threads

  1. Why does PICkit2 show it as an LF device?
    By Balachandar in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st October 2018, 15:28
  2. Best way to read multiple temperatures?
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th May 2012, 21:07
  3. How to compare two temperatures
    By SKOLS1 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th April 2012, 09:07
  4. How do I compare two temperatures
    By critix in forum Code Examples
    Replies: 4
    Last Post: - 4th January 2011, 12:42
  5. DS18S20 displays wrong temperatures
    By Shozo Kanamori in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th August 2007, 03:18

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts