سلام دوستان/
من این برنامه رو برای کنترل دما پیدا کردم/
دمای پایین و بالا توسط کلید به میکرو داده میشه و خروجی به یک رله وصل میشه/
ولی بعضی اوقات چندین بار باید کلید رو فشار بدی تا دما تغییر کنه و بعضی مواقع مقدار دما ناخودگاه ریست میشه/
کسی علت این مشکل رو میدونه؟
واقعا کلافه شدم
من این برنامه رو برای کنترل دما پیدا کردم/
دمای پایین و بالا توسط کلید به میکرو داده میشه و خروجی به یک رله وصل میشه/
ولی بعضی اوقات چندین بار باید کلید رو فشار بدی تا دما تغییر کنه و بعضی مواقع مقدار دما ناخودگاه ریست میشه/
کسی علت این مشکل رو میدونه؟
واقعا کلافه شدم

کد:
[left]$sim $regfile = "m8def.dat" $crystal = 8000000 ' 8 MHz crystal $swstack = 40 $hwstack = 32 $framesize = 32 '************************************************* ******** ' CONFIGURE 16X2 LCD '************************************************* ******** Config Lcd = 16 * 2 Config Lcdpin = Pin , Db4 = Portb.3 , Db5 = Portb.2 , Db6 = Portb.1 , Db7 = Portb.0 , E = Portb.4 , Rs = Portb.5 Cursor Off 'MAKE CURSOR OFF '************************************************* ******** ' CONFIGURE ADC FOR MEASUREMENT OF LM35 '************************************************* ******** Config Adc = Single , Prescaler = Auto , Reference = Avcc Start Adc '************************************************* ******** ' DECLARATION OF I/0 '************************************************* ******** Config Pind.2 = Input Config Pind.5 = Input Config Pind.6 = Input Config Pind.7 = Input H1_up Alias Pind.5 H1_down Alias Pind.2 L1_up Alias Pind.6 L1_down Alias Pind.7 Config Portd.4 = Output Heater Alias Portd.4 'MAKE FAN OFF Heater = 0 'MAKE HEATER OFF '************************************************* ******** ' DECLARATION OF VARIABLES '************************************************* ******** Dim W As Word , W_single As Single , W_avg As Single Dim T As Integer Dim Gp As Byte Dim H As Integer , H_s As Eram Integer Dim L As Integer , L_s As Eram Integer Dim Heat_off As Integer , Heat_on As Integer '************************************************* ******** Deflcdchar 0 , 4 , 14 , 31 , 14 , 4 , 32 , 32 , 32 ' replace [x] with number (0-7) Cls 'CLEAR DISPLAY Lcd "T=" ; Spc(3) ; Chr(0) ; "C" ; Spc(2) ; "HT=" Lowerline Lcd "L=" ; Spc(3) ; Chr(0) ; "C" ; Spc(2) ; "H=" L = L_s H = H_s Main: Gosub Measure_lm35 Gosub Check_temp Debounce L1_up , 0 , L_up Debounce L1_down , 0 , L_down Debounce H1_up , 0 , H_up Debounce H1_down , 0 , H_down Goto Main '************************************************* ******* 'HEAR WE MEASURE TEMPERATURE FROM LM35 SENSOR 'FIRST WE MEASURE THE ADC COUNT AT 'W' 'AS WE KNOW ADC WILL COUNT MAXIMUM VALUE(1024) AT 5V 'WE CAN PER COUNT VALUE BY THE FORMULA, 'W_SINGLE=(WX5)/1024=WX0.005 'I.E. EACH COUNT IS EQUAL TO 5mV 'NOW FROM DATA SHEET OF LM35 WE KNOW THAT LM35 WILL 'OUTPUT 10mV PER DEGREE CENTRIGATE 'SO EACH COUNT=W_SINGLE/2 DEGREE CENTRIGATE 'FOR ACCURACY WE TAKE 100 SAMPLE AND THEN TAKE AVARAGE '************************************************* ******* Measure_lm35: W_avg = 0 For Gp = 1 To 100 W = Getadc(0) 'W_single = W * 5 'CHECK MATH FOR LM35 'W_single = W_single / 1024 'W_single = W_single / 2 If W <> 0 Then W_single = W / 2 Else W_single = 0 End If W_avg = W_avg + W_single Next Gp If W_avg <> 0 Then W_avg = W_avg / 100 'MAKE AVAGARE OF DISPLAY Else W_avg = 0 End If T = W_avg 'TO IGNORE THE FRACTION Locate 1 , 4 'LOCATE THE DISPALY VALUE LOCATION Lcd Spc(3) 'ERASE OLD VALUE Locate 1 , 4 'LOCATE THE DISPLAY VALUE LOCATION Lcd T 'DISPLAY THE CURRENT VALUE Locate 2 , 4 Lcd Spc(3) Locate 2 , 4 Lcd L Locate 2 , 14 Lcd Spc(3) Locate 2 , 14 Lcd H 'DISPLAY THE SET VALUE Return '************************************************* ******* 'HERE WE INCREASE SET TEMPERATURE VALUE BY 1 '************************************************* ******* L_up: Incr L 'INCREMENT SV BY 1 If L > 110 Then L = 0 End If L_s = L 'SAVE SV AT EEPROM Locate 2 , 4 Lcd Spc(3) Locate 2 , 4 Lcd L Goto Main '************************************************* ******* 'HERE WE DECREASE SET TEMPERATURE VALUE BY 1 '************************************************* ******* L_down: If L <> 0 Then Decr L 'DECREASE SV BY 1 Else L = 110 End If L_s = L 'SAVE SV AT EEPROM Locate 2 , 4 Lcd Spc(3) Locate 2 , 4 Lcd L Goto Main '************************************************* ****** H_up: Incr H 'INCREMENT SV BY 1 If H > 110 Then L = 0 End If H_s = H 'SAVE SV AT EEPROM Locate 2 , 14 Lcd Spc(3) Locate 2 , 14 Lcd H Goto Main '************************************************* ****** H_down: If H <> 0 Then Decr H 'DECREASE SV BY 1 Else H = 110 End If H_s = H 'SAVE SV AT EEPROM Locate 2 , 14 Lcd Spc(3) Locate 2 , 14 Lcd H Goto Main '************************************************* ****** Check_temp: Heat_off = H + 1 'HYSTERISYS=1 If T >= Heat_off Then 'TURN ON THE FAN Heater = 0 'TURN OFF HEATER Locate 1 , 14 Lcd Spc(3) Locate 1 , 14 Lcd "OFF" End If Heat_on = L - 1 'HYSTERISYS=1 If T <= Heat_on Then 'TURN OFF FAN Heater = 1 'TURN ON HEATER Locate 1 , 14 Lcd Spc(3) Locate 1 , 14 Lcd "ON" End If Return '************************************************* *********** End 'end program[/left]
دیدگاه