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)