Implementing DS18B20.bas into code w/ ADC

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Implementing DS18B20.bas into code w/ ADC

Post by MrDEB » Fri Aug 10, 2012 3:40 am

my problem now is comparing the sensor temp to the ADC reading
Hoping myTemp = DecToStr(TempA),Dectostr(TempB) would have done the trick but I guess not.
Perhaps compare the Dec of Temp to ??

Code: Select all

NoInline   Sub sens_tep()
        Dim myTemp As Word
        Dim TempA As ShortInt
        Dim TempB As Word
            If DS18B20.Find Then
            While true
                DS18B20.Convert
                DS18B20.GetTemp(TempA,TempB)
                LCD.Cls
                LCD.WriteAt(1,1,"bx temp",DecToStr(TempA),".",DecToStr(TempB,1), "'C    ") // displays temp in C
                myTemp = (DecToStr(TempA),".",DecToStr(TempB,1))     // trying to compare to deg_s (ADC.read(1)
                DelayMS(3000)
              //  LCD.writeat(1,1,dectostr( TempB))
              //  delayms(3000)
             if myTemp > deg_s
             then
                  LED_g = 1
                  LED_r=0
             else  
                 LED_g = 0
                  LED_r=1
             end if
            
         
                Exit
                Wend
            EndIf
   End Sub

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Implementing DS18B20.bas into code w/ ADC

Post by bitfogav » Fri Aug 10, 2012 3:57 am

Ill probably change your code to something like this?:, get rid of myTemp and the While.. Loop and Exit..

But note TempA is going to be the value in Celsius, So your have to change deg_s to suit or convert TempA value into Fahrenheit. you've just got to uncomment the line of code as indicated in my code.

Code: Select all

Sub sens_tep()
        Dim TempA As ShortInt
        Dim TempB As Word
            If DS18B20.Find Then
                DS18B20.Convert
                DS18B20.GetTemp(TempA,TempB)
                LCD.Cls
                LCD.WriteAt(1,1,"bx temp",DecToStr(TempA),".",DecToStr(TempB,1), "'C    ") // displays temp in C
                DelayMS(3000)

// just uncomment the line below, it will convert C to F
 //        TempA = TempA * 9 / 5 + 32   

             If TempA > deg_s Then
                  LED_g = 1
                  LED_r=0
             Else  
                 LED_g = 0
                  LED_r=1
             EndIf
            EndIf
End Sub

If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Implementing DS18B20.bas into code w/ ADC

Post by MrDEB » Fri Aug 10, 2012 5:10 am

Will try your suggestion
BUT hopefully with out the EXIT it won't stop in the sub route.
This is what it WAS doing before I added the EXIT.

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Implementing DS18B20.bas into code w/ ADC

Post by MrDEB » Fri Aug 10, 2012 8:14 am

Your suggestion worked GREAT. Not real happy that the display is what it is. Am sure there is a way to get degree fractions but Celius is better. Display shows Box temp in Celius and Desired temp in F.No big deal at this point.
Here is the SUB routine you suggested. I added a delay for DEFROST (1000 * drf)
drf is derived from the ADC routine for defrost timer.

Code: Select all

not really happy with it but it seems to work.
[code]Public Sub sens_temp()     
       
        Dim TempA As ShortInt
        Dim TempB As Word
      
            If DS18B20.Find Then
                DS18B20.Convert
                DS18B20.GetTemp(TempA,TempB)
                LCD.Cls
                LCD.WriteAt(1,1,"bx temp",DecToStr(TempA),".",DecToStr(TempB,1), "'C    ") // displays temp in C box temp
                DelayMS(3000)

// just uncomment the line below, it will convert C to F
       
             TempA = TempA * 9 / 5 + 32                //tempA is box temp
             If TempA < deg_s Then
                  LED_g = 0                              // cooling off
                  LED_r=1                                //defrost cycle
                 
              DelayMS(1000*drf)                          //defrost cycle timer time = dfx X 1000
           
                  
                 Else 
                  LED_g = 1                              //cooler on
                  LED_r = 0
             EndIf
            EndIf 
                  
            

End Sub
  

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Implementing DS18B20.bas into code w/ ADC

Post by brad » Fri Aug 10, 2012 1:22 pm

After not logging on here for a couple of days, it's great to see you guys getting right in there and solving problems - just like the good old days!

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Implementing DS18B20.bas into code w/ ADC

Post by bitfogav » Fri Aug 10, 2012 7:10 pm

brad wrote:After not logging on here for a couple of days, it's great to see you guys getting right in there and solving problems - just like the good old days!
Late again to the party Brad? :lol: hehe..


mrDeb, do you have any pictures to share of your beer cooler? or the what the LCD display looks like? :)
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Implementing DS18B20.bas into code w/ ADC

Post by MrDEB » Fri Aug 10, 2012 9:20 pm

Will be going out to the Fairgrounds next week and will take some pics and perhaps enjoy a beer when I get back to town.
YES I can snap a pic of the LCD display perhaps a short clip as the display changes from displaying the DESIRED TEMP/ Defrost time to Box temp.
i am working on changing the DESIRED TEMP to Celius but I can only use whole numbers. Perhaps just convert the Faheringh numbers to Celius but the result is not an integer.
Working on solution after I confirm the DELAYMS(1000 * drf) works well.
Contemplating perhaps a loop with a counter, somethingf like UNTIL COUNTER = drf (drf is derived from the DEFROST ADC routine.

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Implementing DS18B20.bas into code w/ ADC

Post by MrDEB » Sat Aug 11, 2012 8:46 am

Been trying to get a simple timer for the DEFROST cycle.
Looked at lots of different codes as well as the Swordfish manuals.
Well I think I got it. Found I could not put the D_counter = 0 in the sub. WHY ???
Anyway it appears to work Have it running right now and it FREEZES on the Box Temp display which is understandable.
Need to tiddy up etc but it appears to STOP when the BOX temp is lower than the DESIRED TEMP. Changing the DELAYms() for a ten minute delay then hopefully the variable drf will adjust as desired.

Code: Select all

{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 8/8/2012                                                       *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
    Device = 18F4520
    Clock = 20
    // some LCD options...
    #option LCD_DATA = PORTD.4
    #option LCD_RS = PORTD.2
    #option LCD_EN = PORTD.3
    // uses LCD and AD libraries...
    Include "LCD.bas"
    Include "ADC.bas"
    Include "convert.bas"
    Include "DS18B20.bas"

    Dim LED_g As PORTC.4
    Dim LED_r As PORTC.5
    Dim Vref As Word
    Dim Vsensor As Word
    Dim Desired_T As Word          //DESIRED TEMP
    Dim D_Frost As Word          //DEFROST TIME
    Dim deg_s As Word
    Dim D_counter As Word
    Dim count_down As Integer
            //DESIRED TEMP
  


         
    // Read the AD ports and scale
    Function Dsired_T() As Word
     result = (ADC.Read(1) +1) /100  //Read DESIRED TEMP Adjustment
    End Function

    Function sensor() As Word
     result = (ADC.Read(0) + 1)/100  // 100  //Read DEFROST TIMER ADJUSTMENT
    End Function
    Dim drf As Word
    
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    // I need this routine to read the DS18B20 buit keep getting syntax errors
    // the LCD, ADC sections all worked before putting the DS18B20 into the code
    //syntax says a sub routine or  or function is expected
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
       
Public Sub sens_temp()     
      
        Dim TempA As ShortInt
        Dim TempB As Word
      
            If DS18B20.Find Then
                DS18B20.Convert
                DS18B20.GetTemp(TempA,TempB)
                LCD.Cls
                LCD.WriteAt(1,1,"bx temp",DecToStr(TempA),".",DecToStr(TempB,1), "'C    ") // displays temp in C box temp
                DelayMS(3000)

// just uncomment the line below, it will convert C to F
       
             TempA = TempA * 9 / 5 + 32                //tempA is box temp
             If TempA < deg_s Then
                  LED_g = 0                              // cooling off
                  LED_r=1
               
               
                  repeat
                  delayms(1000)
                  inc (D_counter)
                  until D_counter = drf*60                                //defrost cycle
                 
                  
                 Else 
                  LED_g = 1                              //cooler on
                  LED_r = 0
             EndIf
            EndIf 
                  
            

End Sub
  
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    // Start Of Program...
    Input(PORTA.0)                  // DESIRED TEMP
    Input(PORTA.1)                  // DEFROST TIMER
    Low (LED_g)                     //set lEDs OFF
    Low (LED_r)
    ADCON1 = %10000000              //set up ADC regesters
    ADCON0.7 = 1
    ADCON0.6 = 1
   
    ADCON1 = $07               
    TRISA = %111111   
    TRISB = %11111111 
    TRISC = %00000000           
    TRISD = %00000000   
    TRISE = %000   

 SetPin(PORTB.3)                  // sensor pin    

           
    DelayMS (150)
    LCD.Cls
    //========================================================
       
     While true
            // call function REF_V() and assign the result to word variable 'Vref'
            Vref =Dsired_T ()           //DESIRED TEMP
            Vsensor = sensor()       //DEFROST TIMER
                 
    Select Vref                             
           Case <1 deg_s = 50
           Case <2 deg_s = 51
           Case <3 deg_s = 52
           Case <4 deg_s = 53
           Case <5 deg_s = 65
           Case <6 deg_s = 70
           Case <7 deg_s = 75
           Case <8 deg_s = 76
           Case <9 deg_s = 77
    End Select
    Select Vsensor
           Case <1 drf = 10                   
           Case <2 drf = 12
           Case <3 drf = 14
           Case <4 drf = 16
           Case <5 drf = 17
           Case <6 drf = 19
           Case <7 drf = 21
           Case <8 drf = 23
           Case <9 drf = 25
           
    End Select
    // main program loop...
           
             sens_temp()             // get temperature
          
            LCD.MoveCursor (1,1)
            LCD.WriteAt(1,1,"Desired temp=", DecToStr(deg_s),"F")  // Display DESIRED TEMP
       
           
     // call function sensor() and assign the result to word variable 'drf'
           
            LCD.MoveCursor (2,1)
            LCD.Write("DEFROST = ", DecToStr(drf),"    ")   //Display DEFROST TIMER
            DelayMS(3000)
              D_counter = 0
             {
            if led_r = 1 then
               D_counter = 0
                  Repeat
                  DelayMS(1000)
                  Inc (D_counter)
                  Until D_counter = drf*6000
                       //drf is case select Vsensor 
                 endif 
              } 
             Wend
                  
        //   If LED_r = 1 Then
          //    DelayMS(1000*drf)
   

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Implementing DS18B20.bas into code w/ ADC

Post by brad » Sun Aug 12, 2012 10:58 pm

bitfogav wrote:
brad wrote:After not logging on here for a couple of days, it's great to see you guys getting right in there and solving problems - just like the good old days!
Late again to the party Brad? :lol: hehe..


mrDeb, do you have any pictures to share of your beer cooler? or the what the LCD display looks like? :)
Yeah, fair enough!

Although, I have been eye deep in my first commercial project - which will be launched very soon now (Just waiting on quotes from manufacturers...)

Details to come soon!

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Implementing DS18B20.bas into code w/ ADC

Post by bitfogav » Mon Aug 13, 2012 5:40 am

I'm fascinated to what you've have been working on Brad, look forward to seeing it. :)
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Implementing DS18B20.bas into code w/ ADC

Post by brad » Mon Aug 13, 2012 10:03 pm

I think you'll like it!

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Implementing DS18B20.bas into code w/ ADC

Post by MrDEB » Tue Aug 21, 2012 9:17 pm

BEER COOLER is up and running. It is kinda crude as the code could use some tweeking and would like the display to scroll across the screen. Ran out of time. No big deal right now.
Will take some pics today as the beer is being delivered today.
During the 4 days our KoC beer booth is open well sell 18-20 kegs, 30_+ cases of caned beer and 10-15 cases of wine coolers. You have a hard time getting a beer after the Rodeo on Thursday and Friday night.

Beer on tap = Coors Light biggest seller
PBR, Koenknee, Bohra Ale(local brew pub) and Alaskan Amber.
My favorite is Alaskan Amber
ALL the beer is poured at a COLD 34 degrees

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Implementing DS18B20.bas into code w/ ADC

Post by brad » Wed Aug 22, 2012 6:33 am

Great to hear you got it all up and running!

Any pics of the completed project?

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Implementing DS18B20.bas into code w/ ADC

Post by MrDEB » Tue Aug 28, 2012 10:44 am

The code was hanging up in the sub routine so made a few minor changes.

Code: Select all

Public Sub sens_temp()     
       
        Dim TempA As ShortInt
        Dim TempB As Word
      
            If DS18B20.Find Then
                DS18B20.Convert
                DS18B20.GetTemp(TempA,TempB)
                LCD.Cls
                TempA = ((TempA * 9) / 5)+ 32               // converts from Celius to F
                LCD.WriteAt(1,1,"box temp =",DecToStr(TempA ),".",DecToStr(TempB,1), "F") // displays temp in C box temp
                DelayMS(3000)


       
             //tempA is box temp
             If TempA <= deg_s Then                         // compare box temp w/ desired temp
                  LED_g =0                                  // cooling off
                  LED_r=1
                  High(ctr)                                 //Defrost relay ON 
                  //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                  //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                  // defrost counter If box is < DESIRED TEMP
                  
                 
                  Repeat
                  DelayMS(5000)             [b] THIS SECTION WAS HANGING thus stopping and leaving the cooler ON[/b]
                  Inc (D_counter)
                  delayms(5000)
                  Until D_counter = drf *6             //drf is case select Vsensor
                  
                  Else 
                  LED_g = 1                              //cooler on
                  LED_r = 0
                  Low(ctr)                               //relay OFF
             EndIf
            EndIf 
                  
            

End Sub
  

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 7 guests