DS18B20 Question


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

    Default DS18B20 Question

    I am using a DS18B20, with Bruce Reynolds program, a 18f14k22 running at 16 mhz internal osc.

    I notice that when the temperature "changes direction", in other words, when it first starts to increase or decrease, the first reading of the DS18B20 does not change. After that it works fine, updates each time a new read takes place.

    I noticed this a couple of years ago, and disregarded it, because it was more of a nuisance than anything. However, now I want to detect the temperature change immediately.

    To definitely confirm this, I placed a short delay (say 5 seconds or so) following the "Start_Convert" line, to allow warming or cooling the DS18B20. To indicate the delay I simply used a LED, which is turned on for that time, and then briefly turned turned off ( 1 second) after the Convert_Temp subroutine return, prior to the GOTO back to Start_convert.

    I tried using a different MODE number on the OWIN, either a 0 or 1 for the reset pulse, with no change.

    This seems to be some weird characteristic of the DS18B20 -

    Anyone else experienced this ?

    Ken

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 Question

    Quote Originally Posted by ozarkshermit View Post
    I notice that when the temperature "changes direction", in other words, when it first starts to increase or decrease, the first reading of the DS18B20 does not change. After that it works fine, updates each time a new read takes place.


    Ken
    1) what the hell do you mean by that ???

    2) reading your datasheet may show you the conversion need some time to be read ... depending on the resolution you use.

    3) This one ( by bruce ... ) is correct, but for DS1820 - the old model without "B" or "S" - see Datasheet for end of conversion condition
    Code:
    temperature VAR WORD ' Temperature storage
    count_remain VAR BYTE ' Count remaining
    count_per_c VAR BYTE ' Count per degree C
    
    DQ VAR PORTC.0 ' One-wire data pin
    
    
    ' Define LCD registers and bits
    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTE
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTE
    DEFINE LCD_EBIT 1
    
    
    ADCON1 = 7 ' Set PORTA and PORTE to digital
    Low PORTE.2 ' LCD R/W line low (W)
    
    
    mainloop: 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)
    LCDOut $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"
    
    ' Calculate temperature in degrees F to 2 decimal places (not valid for negative temperature)
    temperature = (temperature */ 461) + 3200
    LCDOut $fe, $c0, DEC (temperature / 100), ".", DEC2 temperature, " F"
    
    Pause 1000 ' Display about once a second
    
    GoTo mainloop ' Do it forever
    Alain
    Last edited by Acetronics2; - 19th December 2014 at 18:24.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 Question

    What I mean by that is simply this:

    When the temperature increases from any temperature, (GOES UP) , Say from 72 degrees to 73 degrees,
    OR when the temperature decreases from any temperature (GOES DOWN), Say from, 74 degrees to 73 degrees . . .

    On the FIRST READ of the DS18B20 AFTER that event : INCREASE (Go up in temperature) or DECREASE (Go down in temperature) , the temperature READ FROM THE DS18B20 does not change. It will change correctly on subsequent reads.

    I read the data sheet.

    I am using the program developed by Bruce Reynolds. It uses:

    waitloop: OWIn DQ, 4, [count_remain] ' Check for still busy converting
    IF count_remain = 0 Then waitloop

    Why is the conversion time OK for everything EXCEPT for the FIRST READ after a temperature INCREASE or DECREASE ?

    Ken

  4. #4
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 Question

    When the temperature is changing from, say 72 degrees to 73 degrees or from 74 to 73 degrees I would expect it would take some time for the epoxy casing to heat/cool through to where the sensor is actually sensing. The datasheet indicates a conversion time of .1 - .75 seconds; are you allowing adequate time for the temperature change to propagate? Even as the sensor continues in the "correct" direction, there must be some lag between the actual temperature and the sensing element.

    If it is truly a hardware issue - and it requires a read/ write or some other electronic trigger to affect the suspect reading - then the problem should persist over several seconds or minutes. If you read say... once a minute... does the problem remain? What if you change the temperature rapidly - perhaps using "freeze spray" - to speed the temperature change of the body of the sensor, does this effect your results?
    Last edited by Amoque; - 19th December 2014 at 23:48.

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 Question

    If this part was capable of tracking temp that fast they would use them as MAF sensors in cars instead of investing hundreds of dollars, pounds,euros whatever in those "hot wire" devices. That little T092 case has mass, and it takes a bit to change it's temp.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 Question

    Sorry - I should have added that I am using 9 bit resolution . Things work fine using 12 bit.

    I use 9 bit since the conversion time is 93.75 ms, compared to 750 ms for 12 bit. At least, that is according to the data sheet that I have for the DS18B20. I do not want the program waiting 750 ms to convert.

    I guess it will be best just to close this thread. I will come up with some kind of work-around.

    Ken

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 Question

    Problem Solved - -
    The problem was in my code - - As I mentioned, I have the DS18B20 configured for 9 bit resolution.

    In my code, I sent the command $CC, $44 to do the Temperature conversion, AND THEN sent the 9 Bit configuration command.

    By placing the Configuration command BEFORE the temperature conversion command, it works just fine.

    Ken

Similar Threads

  1. ds18b20 code
    By leemarrow in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 3rd March 2016, 16:14
  2. Quick DS18B20 question
    By gti_uk in forum General
    Replies: 4
    Last Post: - 21st June 2009, 18:24
  3. Ds18b20
    By ahmed_salah in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 14th June 2009, 16:21
  4. Ds18b20..
    By karenhornby in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th June 2008, 17:29
  5. using the DS18B20
    By lerameur in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd December 2006, 14:09

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