DS18S20 displays wrong temperatures


Closed Thread
Results 1 to 8 of 8
  1. #1

    Smile DS18S20 displays wrong temperatures

    I am a newbie to this forum.
    I have DS18S20 displaying problem. My system uses LCD (16x2, Hitachi 44780 controller-based SC1602BSLB), PBP v.2.45 and 16F877 with 4MHz ceralock. At a room temp. of 19 degrees C (by mercury thermometer), for example, I get 155.18 degrees C on LCD. If I touch DS18S20 chip with my fingers, it gradually rises up to about 220.xx degrees C. If the chip is heated by soldering iron, when the display reaches to somewhere around 650.xx degrees C, it suddenly drops to 0.xx degrees C and begins to rise again. I cannot solve this wrong-temperature displaying problem. I need your help. Pin connections and the codes I used are as follows. Thank you.

    'Pin 1 - Vdd (+5V)
    'Pin 2 - Vss (GND)
    'Pin 3 - Vo
    'Pin 4 - RS to RD2 (PIC)
    'Pin 5 - R/W (GND)
    'Pin 6 - E to RD3 (PIC)
    'Pin 11 - RD4 (PIC)
    'Pin 12 - RD5 (PIC)
    'Pin 13 - RD6 (PIC)
    'Pin 14 - RD7 (PIC)
    'DS18S20 - DQ pin to RC2(PIC), DQ pin to Vdd pin via 4.7 k r, GND pin to GND

    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTD
    Define LCD_RSBIT 2
    Define LCD_EREG PORTD
    Define LCD_EBIT 3
    Define LCD_BITS 4
    Define LCD_LINES 2

    DQ var PORTC.2
    temperature Var Word
    count_remain Var Byte
    count_per_c Var Byte

    ADCON1 = 7
    pause 100

    Main: OWOut DQ,1,[$CC,$44]
    Waitloop: OWIn DQ,4,[count_remain]
    If count_remain = 0 Then Waitloop
    OWOut DQ,1,[$CC,$BE]
    OWIn DQ,0,[temperature.LOWBYTE,temperature.HIGHBYTE,Skip 4,count_remain,count_per_c]

    temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100)/count_per_c)
    Lcdout $fe,1,DEC (temperature/100),".",DEC2 temperature," C"

    Pause 1000
    Goto Main
    End


    'Shozo Kanamori (Tokyo)

  2. #2


    Did you find this post helpful? Yes | No

    Smile Found my mistake

    My temperature sensor provided by Maxim was actually DS18B20 instead of DS18S20. I found this by carefully observing the sensor's surface with a magnifying glass. I never had doubts about this. The resemblance between "B" and "S" made me spend many hours of frustrating time. Sorry for the viewers.

    Shozo Kanamori
    It's not easy for hobbyists to get DS18S20 here in Tokyo.

  3. #3
    Join Date
    Sep 2005
    Location
    Switzerland
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Shozo,
    here I found a well done prg. for 18B20 that maybe can help you.
    http://www.rentron.com/PicBasic/one-wire3.htm

    bye

  4. #4


    Did you find this post helpful? Yes | No

    Smile Program for DS18B20 looks good!

    Hi Lotondo,

    The article you introduced me seems to be very helpful. I have browsed a lot of webpages but never come across this article before. I will soon start my experiment using DS18B20.

    Thank you.

    Shozo Kanamori

  5. #5
    Join Date
    Sep 2005
    Location
    Switzerland
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Nice to read that my link maybe helpful.
    By the way, I have trouble using ds18S20 with temperature below 0° celsius
    if you see some code regarding how to use it, pls link it to me.
    Thanks
    Bye

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Darell Taylor has some very nice temp conversion routines here http://www.pbpgroup.com/ you might also find very useful.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce!

    I was talking with someone else off forum that had problems using the conversion routines with a DS1820 and negative temperatures, so I came up with this.
    Code:
    Sign  VAR  BIT
    TempC VAR  WORD
    
    Sign = temperature.15
    TempC = ABS(temperature)
    TempC =(TempC>>1)*10 + (TempC.0 * 5)
    IF Sign then TempC = 0 - TempC
    He said it worked, but I haven't tried it myself.

    HTH,
      Darrel
    Last edited by Darrel Taylor; - 10th May 2006 at 22:30. Reason: Changed Variable snafu

  8. #8
    Prethorian's Avatar
    Prethorian Guest


    Did you find this post helpful? Yes | No

    Default DS1820 apsolute working with negative temperature

    I will post code and you will see where is (I will note it) added change which resolve problem and working 100%
    This example was coded for PIC16F84A for my job.

    Code:
    Define	LCD_DREG	PORTB
    Define	LCD_DBIT	4
    Define	LCD_RSREG	PORTB
    Define	LCD_RSBIT	2
    Define	LCD_EREG	PORTB
    Define	LCD_EBIT	3 
    
    TempR         var word    'DS1820 read Temperature 
    TempNeg      var byte    'temperature sign -/+ 
    
    '*****DS1820 VARS AND SETTINGS*******
    count_remain var byte   'DS1820 coumter of remain bits
    count_per_c  var byte   'DS1820 counter per C bits
    symbol DQ = PortA.3     'OneWire data pin
    '**********************************
    
    TrisA 	=	%11111
    PortA = 0
    TrisB 	=	%00000000
    PortB = 0
    
    Main:
       gosub Read_Temp
       if TempR=$FFFF then Error
       gosub Disp_Temp
       pause 100
    goto Main
    
    '******DS1820 READING******
    Read_Temp:
       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, [TempR.LowByte, TempR.HighByte, Skip 4, count_remain, count_per_c]
    
    if TempR = $FFFF then return 
        if (TempR.HighByte = $FF) and (TempR.LowByte <> 0) then
          TempNeg = "-"
          TempR = TempR ^ $FFFF
          TempR = ((TempR >> 1)*100) - 25 + ((count_per_c + count_remain) * 100) / count_per_c      
          else
        if (TempR.HighByte < $FF) and (TempR.LowByte <> 0) then  
          TempNeg = "+"
          TempR = ((TempR >> 1)*100) - 25 + ((count_per_c - count_remain) * 100) / count_per_c
          else
    '************************************************
          TempR=$0000    ' THIS IS ONLY NEED TO DEFINE !!!
    '************************************************
        endif
    endif
    return
    
    Disp_Temp:
    	Lcdout $fe, 1, "Temperature: " TempNeg, DEC (TempR / 100),".", DEC2 TempR, 223, "C "
    return
    
    Error:
       Lcdout $fe, 1, "!!!ERROR!!!", $fe, $C0, "Reading Temp."
    goto Main
    end
    Now I think that this thread (I am not find any fresh thread with solved problem) was solved
    This code measure temperature with extended resolution (DEC2).


    Regards.
    Last edited by Prethorian; - 6th August 2007 at 03:25. Reason: correcting syntax

Similar Threads

  1. 7 Segment Displays and MAX7219
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 31st October 2010, 18:30
  2. DS18S20 reading negative temperature
    By srob in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th December 2007, 21:21
  3. ADCIN - AD settings are wrong
    By teverett in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th December 2006, 16:32
  4. Using DS18S20 vs DS1820 with 4x7 LED Displays
    By sayzer in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 16th October 2006, 04:36
  5. 16F877, DS18S20 and Serial Comm Problem
    By YellowTang in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2004, 10:36

Members who have read this thread : 1

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