ds1820 error


Closed Thread
Results 1 to 14 of 14

Thread: ds1820 error

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Location
    Melbourne, Australia
    Posts
    25

    Exclamation ds1820 error

    hi all. think i got the correct spot. i am having a issue with the dallas ds1820 temp sensor. i know it has been written many times. but think this is a different issue. i keep getting the same temp (85.00 deg c) even when i put the hair drier on it. is it stuffed????????

    my code for a 16f88 internal osc set at 4 mhz

    OSCCON = %01101000 'INTRC = 4 MHz
    TRISA = %11111111
    ANSEL = 0 'DISABLE ALL ADC
    CMCON = 7 'DISABLE ALL ANALOG COMPARATOR
    WHILE OSCCON.2=0:WEND 'STABILISE THE CLOCK
    ADCON1 = 1
    DEFINE OSC 4
    PAUSE 1000
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4 '4,5,6,7
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 3
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    pause 1000
    lcdout $fe, 1

    ' One-wire temperature for DS18S20

    ' This program must be compiled with PBP version 2.40 or later


    temperature VAR WORD ' Temperature storage
    count_remain VAR BYTE ' Count remaining
    count_per_c VAR BYTE ' Count per degree C

    DQ VAR PORTA.1 ' One-wire data pin


    mainloop: OWOUT DQ, 0, [$B4] ' READ POWER SUPPLY
    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 500 ' Display about once a second
    LCDOUT $FE, 1, "DALLAS DS1820"
    PAUSE 1000
    GoTo mainloop ' Do it forever


    any ideas of maybe where i went wrong

    thanks

    crazy cooter
    IF ITS STOCK IT WONT ROCK

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


    Did you find this post helpful? Yes | No

    Default

    The fact that you're getting 85°C is a good sign.

    That's the power-on default for the temperature registers of the DS1820. So at least you know the hardware is working.

    My guess is that the "READ POWER SUPPLY" line is not allowing the "start conversion" to work. Try it with that line commented out.
    <br>
    DT

  3. #3
    Join Date
    Nov 2006
    Location
    Melbourne, Australia
    Posts
    25


    Did you find this post helpful? Yes | No

    Exclamation

    i have tried it without the READ POWER SUPPLY. I have also tied a 4.7k resistor from the DQ line to 5V. Am i initialising it correctly??? This was a direct copy from melabs using "onewire.bas"
    IF ITS STOCK IT WONT ROCK

  4. #4
    Join Date
    Jul 2007
    Location
    Maryland, USA
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Did you set internal osc?

    Right after you compile, the screen comes up to program the chip. if you click view -> configuration. You can set INTOSC.

    a place I've tripped up before, just a thought.

    hope it helps

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


    Did you find this post helpful? Yes | No

    Default

    Try changing this;
    OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]

    to this;
    OWIn DQ, 2, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]

    I beleive you need mode 2 after the last read to issue the reset pulse so the sensor
    is ready for the next on return to the start of your program.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    I had to try it out, but all I have is a DS18B20.

    The original code worked fine, except I had to change the formula. But the communications seems OK.
    <br>
    DT

  7. #7
    Join Date
    Nov 2006
    Location
    Melbourne, Australia
    Posts
    25


    Did you find this post helpful? Yes | No

    Thumbs up Its A Goer

    Thanks To Everyone Who Gave Me Advice Here. It Ended Up Being Two Dead Ds18s20. I Got Some New Ones Now And Its All Working Well.


    Regards

    Crazy Cooter
    IF ITS STOCK IT WONT ROCK

Similar Threads

  1. Using input from Switch to control a loop
    By MrRoboto in forum mel PIC BASIC
    Replies: 9
    Last Post: - 2nd February 2009, 05:02
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Optimizing DIV
    By skimask in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 22nd September 2008, 04:58
  4. 16F88 Compile error
    By Toley00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd November 2005, 00:22
  5. Compiler/Assembler Error
    By LT_Pic in forum General
    Replies: 7
    Last Post: - 21st July 2005, 09:47

Members who have read this thread : 0

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