Please help with 1-wire DS1820


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2010
    Posts
    6

    Default Please help with 1-wire DS1820

    I tried this code below :


    temperature Var Word ' Temperature storage
    count_remain Var Byte ' Count remaining
    count_per_c Var Byte ' Count per degree C

    DQ Var PORTD.6 ' One-wire data pin

    loop :

    OWOut DQ, 1, [$CC, $44] ' Start temperature conversion

    OWIn DQ, 4, [count_remain] ' Check for still busy converting

    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"

    goto loop

    It worked well when i use crystal 6 Mhz , OSC_HS . Data from DS1820 was ok.

    But when i used crystal 6 Mhz , OSC_HS or higher Mhz , OSC_HS . Data from DS1820 allway 54.11'C .

    Maybe the speed of PIC is too high but I need the high speed process from PIC . How can i config DS1820 when connect to High-speed PIC ?

    Who can help me to fix this problem ?

    Many thanks !
    Sory for my English.

  2. #2
    Join Date
    Aug 2008
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Did you try to include the following:

    DEFINE OSC 20 ' 20Mhz Osc

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default

    hatuan291,

    What PIC are you using? The DS1820 has its limits in speed as stated in the datasheet. First try using a PAUSEUS after the conversion command.

    Code:
    OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
    Double check that your PIC is working with the new oscillator settings. Try a blinking LED first with the new settings.

    http://datasheets.maxim-ic.com/en/ds/DS18S20.pdf

    Robert

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by Pic2008 View Post
    Did you try to include the following:

    DEFINE OSC 20 ' 20Mhz Osc
    if using 8 Mhz Xtal, your DEFINE must be OSC 8

    also ...

    Code:
    OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
    Pause 750
    will be nice.

    no need for
    Code:
    OWIn DQ, 4, [count_remain] ' Check for still busy converting
    that, alone, doesn't check for anything ...

    Alain
    Last edited by Acetronics2; - 7th March 2010 at 13:31.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I won't even ask if you are using the recommended 4.7K pull-up resistor.
    Charles Linquist

  6. #6
    Join Date
    Mar 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Pic2008 View Post
    Did you try to include the following:

    DEFINE OSC 20 ' 20Mhz Osc
    When i'm not include DEFINE OSC 8 ( with xtal 8Mhz ) , test with blink LED is so fast .

    but when include ( the same xtal ) , the time between Led-On and Led-Off so long .

    Maybe define osc will slow down the speed of PIC ?

    I used 18F4680 . DS 1820 had an resistor pull-up .I have tried

    1-DS1820 work well with 10 Mhz xtal , config OSC_HS , not define osc 10
    2-but with the same xtal , config OSC_HSPLL , DS1820 didn't work . not define osc 10 OR define i got the same result .


    who can help me ?
    Last edited by hatuan291; - 9th March 2010 at 14:03.

Similar Threads

  1. Thermo 7 segments - little problem
    By fratello in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 27th July 2013, 07:31
  2. RS485 bus - starting probem
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th January 2010, 13:35
  3. 32 bit square root
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 6th May 2009, 03:37
  4. one line led light make image
    By bioul in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 12:19
  5. HSERIN doesn´t work
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th July 2007, 14:23

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