Ds18b20 + 16f628a


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Jun 2008
    Location
    Milwaukee, WI
    Posts
    37


    Did you find this post helpful? Yes | No

    Default same thing

    So quick..thanks guys

    DT: yeah, this is a mess, thanks for pointing me to the rentron site. I've been there before, but I forgot that bruce had this for us. and thanks for all that you do here. I'm just starting to play with instant interrupts.

    Ace: Thanks, but I'm seeing my debug messages just fine.

    Ok, I trashed that old program and brought in the new one from bruce at rentron. I don't have a serial LCd, so I changed the outputs to debug outputs. sure, there is some lcd formatting characters in there, but I'll worry about that later.

    Now it's the same thing. It does not look like I get past the first owout command. I never see my '*******' message. I do see the ones before it though. I power the board, then I see 'Power Up' and 'start convert' and then nothing...but there is a never ending stream of data on the one wire...


    here is the new code:
    Code:
     
    '    PIC16F628A Configuration
    '    ================
    @ __CONFIG  _HS_OSC & _MCLRE_ON  &  _LVP_OFF & _WDT_OFF & _PWRTE_ON  & _BODEN_OFF
    
    DEFINE DEBUG_REG PORTB		'RS-232 output on PORTB.4
    DEFINE DEBUG_BIT 4
    DEFINE DEBUG_BAUD 19200
    DEFINE DEBUG_MODE 0			'not inverted. using RS-232 module
    
    
    DEFINE OSC 20		'  external oscillator
    
    CMCON=7
    
    TRISB = %00000100          
    TRISA = %00000000         
    
    DEBUG REP $00\8,13,10,"Power Up"
    
    
    '****************************************************************
    '*  Name    : Temp.BAS                                          *
    '*  Author  : Bruce Reynolds                                    *
    '*  Notice  : Copyright (c) 2003 Reynolds Electronics           *
    '*          : All Rights Reserved                               *
    '*  Date    : 7/28/2003                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
    
    Comm_Pin    VAR	PortB.0     ' One-wire Data-Pin "DQ" on PortB.0
    Busy        VAR BIT         ' Busy Status-Bit
    R_Temp      VAR	WORD        ' RAW Temperature readings
    TempC       VAR WORD        ' Temp in deg C
    TempF       VAR WORD        ' Temp in deg F
    Float       VAR WORD        ' Holds remainder for + temp C display
    Cold_Bit    VAR R_Temp.Bit11' Sign-Bit for +/- Temp. 1 = Below 0 deg C
    Real_Cold   CON 1           ' Define Real_Cold = 1
    
    Deg         CON 223         ' Data to display Deg ° symbol
    CLR         CON 1           ' CLR LCD command
    
    Sign        VAR BYTE        ' +/- sign for temp display
    Dummy       VAR BYTE        ' Dummy for Div32
    
    
    
    DEBUG REP $00\8,13,10,"start convert"
    
    Start_Convert:
        OWOUT   Comm_Pin, 1, [$CC, $44]' Skip ROM search & do temp conversion
        
    DEBUG REP $00\8,13,10,"****************"
    
    Wait_Up:
        OWIN    Comm_Pin, 4, [Busy]    ' Read busy-bit
        IF      Busy = 0 THEN Wait_Up  ' Still busy..?, Wait_Up..!
        OWOUT   Comm_Pin, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory
        OWIN    Comm_Pin, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
        GOSUB   Convert_Temp
        GOTO    Start_Convert
        
    Convert_Temp:                 ' +32.0 to +257 F 
        IF      Cold_Bit = Real_Cold THEN Yikes ' If Cold_Bit = 1, it's below "0" deg C
        Sign  = "+"
        Dummy = 625 * R_Temp      ' Multiply to load internal registers with 32-bit value
        TempC = DIV32 10          ' Use Div32 value to calculate precise deg C
        Dummy = 1125 * R_Temp
        TempF = DIV32 100
        IF TempF >6795 THEN ' Over 99.5 deg F..?
           TempF = TempF + 3200
    
    		DEBUG REP $00\8,13,10," TempF = ",Sign,DEC TempF DIG 4,DEC TempF DIG 3,DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "
        ELSE
           TempF = TempF + 3200
    		DEBUG REP $00\8,13,10," TempF = ",Sign,DEC TempF DIG 3,DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "
        ENDIF
        TempC  = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
        Float = ((R_Temp.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625
    		DEBUG REP $00\8,13,10, " TempC = ",Sign,DEC TempC,".",DEC Float,Deg,"C "
      		DEBUG REP $00\8,13,10,   "Raw", IBIN16 R_Temp
        RETURN
    
    Yikes:                      ' Display full range -C to -F conversion
        Sign   = "-"            ' Display - symbol for negative temp
        Dummy  = 625 * ~R_Temp+1' Multiply to load internal registers with 32-bit value
        TempC  = DIV32 10       ' Use Div32 value to calculate precise deg C
        TempF  = ~R_Temp / 16   ' Begin conversion from -C to deg +/-F
        IF TempF >=18 THEN      ' Check for -degrees F "-18 C = -0.4 F"
           TempF   = ((((TempF + 50) * 9) /5) -122) ' -C to -F below -17 deg C
    		DEBUG REP $00\8,13,10, " TempF = ",Sign, DEC TempF,Deg,"F     "
    		DEBUG REP $00\8,13,10, " TempC = ",Sign,DEC TempC DIG 4,DEC TempC DIG 3,".",DEC3 TempC,Deg,"C "
    		DEBUG REP $00\8,13,10, "Raw", IBIN16 R_Temp
        ELSE                    ' Else result = +deg F
           TempF   = ((((-TempF + 50) * 9) /5) -58)' -C to +F below 32.0 deg F to -17 deg C
    		DEBUG REP $00\8,13,10, " TempF = ","+",DEC TempF,Deg,"F     "
    		DEBUG REP $00\8,13,10, " TempC = ",Sign,DEC TempC DIG 4,DEC TempC DIG 3,".",DEC3 TempC,Deg,"C "
    		DEBUG REP $00\8,13,10, "Raw", IBIN16 R_Temp
        ENDIF
        RETURN
        
        END

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


    Did you find this post helpful? Yes | No

    Default

    Are you 100% sure you have your sensor wired right?
    Regards,

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

  3. #3
    Join Date
    Jun 2008
    Location
    Milwaukee, WI
    Posts
    37


    Did you find this post helpful? Yes | No

    Default still trying

    I checked and re-checked, and I think I have it hooked up right. I have the DS18B20Z, with the SOIC package, so I have GND on pin 5, the PIC's 5V on pin3, and the one wire line on pin 4. I have a 4.7k ohm res pulling the one wire line up to 5V. The one wire line is connected to PIC portB.0. I bought 2 sensors from digikey, and I tried both of them, the same thing happens with each one. I power up the board, then in hyperterminal I see:

    Power Up
    start convert

    and then nothing else, but there is lots of activity on the one wire line.

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


    Did you find this post helpful? Yes | No

    Default

    I found a bug a while back where OWOUT would sit in a nasty loop when any osc > 8MHz
    was defined. It's been fixed since, but it sounds like you have a version that has this bug.

    Download & install the patch. Should fix you right up....;o}
    http://www.melabs.com/support/patches.htm
    Regards,

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

  5. #5
    Join Date
    Jun 2008
    Location
    Milwaukee, WI
    Posts
    37


    Did you find this post helpful? Yes | No

    Talking Ya hooo!

    That sounds exactly like what is happening.... and lo and behold, I installed the patch and it works now, using that same code.

    Bruce, your website has such a wealth of info. Thanks for keeping it available.

    and yes, I figured out what modedefs.bas is for... (I asked in my first post)

    and now I just need to decide what to do with this little gem!

    Thank you all for your help. you got a beer waiting for you in Milwaukee ... but don't worry, the beer wouldn't be from Milwaukee...hahaha.

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


    Did you find this post helpful? Yes | No

    Default

    Glad you got it working...;o}

    I just need to decide what to do with this little gem!
    Make a bunch & sell them. You would be really surprised at how many folks are out
    there that pay good $ for embedded control solutions.

    P.S. Be careful mentioning BEER here. Darrel has a beer radar....;o}
    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

    Talking

    I don't think he has anything to worry about ...

    <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="509" HEIGHT="421" ><PARAM NAME="MOVIE" VALUE="http://www.pbpgroup.com/files/Flash/Milwaukee.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="true"><PARAM NAME="QUALITY" VALUE="high"><EMBED SRC="http://www.pbpgroup.com/files/Flash/Milwaukee.swf" WIDTH="509" HEIGHT="421" PLAY="true" LOOP="true" WMODE="opaque" QUALITY="high" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>
    DT

Similar Threads

  1. Please help with code for DS18B20
    By fratello in forum mel PIC BASIC Pro
    Replies: 109
    Last Post: - 28th April 2013, 21:12
  2. Help with DS18B20 program
    By presario1425 in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 22nd August 2012, 00:50
  3. Crystal oscillator problems on a 16f628a
    By achilles03 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th February 2009, 16:33
  4. DS18B20 error reading
    By Gaetano in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th August 2007, 16:21
  5. HSEROUT and 16F628A
    By fredblah in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th May 2004, 00:07

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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