This is the latest addition to the TEC controller: One pot on ADC1 sets the temperature.
I’ve done it such way so with a linear pot the target temperature can be set between 40 and 65 degrees F.
Code:
'Last release 9_16_16 Implements pot for setting set_temp
@__config_device_pic16f819
@__config_wdt_off
@__config_hs_osc
@__config_pwrt_on
@__config_mclr_off
@__config_lvp_off
@__config_protect_on
DEFINE OSC 8
DEFINE DEBUG_REG PORTB
DEFINE DEBUGIN_REG PORTB
DEFINE DEBUG_BIT 6
DEFINE DEBUGIN_BIT 7
DEFINE DEBUG_MODE 1
DEFINE DEBUG_BAUD 38400
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
ADCON1=%01001110
pwm_out var PORTB.2
adval var word
val_1 var byte
val_2 var byte
val_3 var byte
new var word
act_temp var byte
set_temp var byte
new_temp var byte
temp_index var byte
i var word
pwm_pars var word
id var byte
pwm_flag var bit
start_ch con 126
end_sym con 251
samples con 39
divider con 20
hysteresis con 1
min_pwm con 30
max_pwm con 50
full_pwm con 40
CCP1CON = %00001100
PR2 = 15
CCPR1L = 0
CCP1CON.5 = 0
CCP1CON.4 =0
High pwm_out
Pause 500
Low pwm_out
T2CON.2 = 1
' set_temp=69
id="1"
pwm_flag=0
goto main
send_out:
debug start_ch,id,val_1,val_2,val_3,end_sym
return
set_pwm_pars:
CCPR1L = pwm_pars >> 2
CCP1CON=$0C|((pwm_pars&$3)<<4)
return
read_act_temp:
new = 0
For temp_index = 1 TO samples
ADCIN 0,adval
new = new + adval
Next
act_temp=new/divider
return
read_set_temp:
new = 0
For temp_index = 1 TO 9
ADCIN 1,adval
new = new + adval
Next
set_temp= 40 + new/100 'keeps set_temp between 40 and 65 deg. F
return
decide:
If act_temp < (set_temp-hysteresis) then
pwm_pars =0
pwm_flag=1
endif
If act_temp > set_temp and pwm_flag =0 then
pwm_pars = min_pwm+(act_temp - set_temp)
goto jump
endif
If act_temp > (set_temp + hysteresis) and pwm_flag =1 then
pwm_pars = start_pwm
pwm_flag=0
endif
jump:
gosub set_pwm_pars
val_1=act_temp
val_2=pwm_pars
val_3=set_temp
Return
Main:
gosub read_act_temp
gosub read_set_temp
gosub decide
gosub send_out
pause 1500
goto Main
end
I think that I will settle for that now. I will just test its performance for the next week or so and wrap the project up for this particular cooler.
A friend of mine is offering me a huge 125 bottles cooler with refrigeration problems (old Freon compressor type). If this first attempt will prove successful I will spend more time saving the big cooler which is a lot nicer and a lot more expencie than this one.
I manage to get 6 brand new TECs, more powerful than the other ones (7-8 Amps) and I will start experimenting with them and different setups.
It might take a little time but I will keep you posted.
Thank you everyone for the input.
Nick
Bookmarks