TEC controller


Closed Thread
Results 1 to 19 of 19

Thread: TEC controller

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    I got all the hardware working and wrote a simple temperature control program. Nothing fancy.
    The code drives the TEC with different power output levels depending on how far the real temperature is from the set temperature.
    I don’t have yet a mechanism of setting the target temperature but this is just to prove that the system works.
    Since the major hardware is in place and the cooler is basically functional I will settle for now for a fixed, preprogrammed target temperature.
    The ICSP connector for the 16F819 is accessible and I will play with the code to get more features.
    I’m forced to take a break from the project but I will get back to it when time permits.
    For now 62⁰F should be fine on most of the wines I drink so I’ll make it default.
    Anyway it has been a fun weekend project and what makes it special is the fact that I did not have to order any parts. Recycling old junk makes me feel really good.
    For all interested below is the simple control code, not fully tested since I just finished it last night. There are few things in the code that are not fully implemented (serial output will be used for a LCD display, hysteresis, id (to diferenciate between the two chambers). These variables will be used for future development when time comes.

    Code:
    @__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
    
    start_ch        con     126
    end_sym         con     251
    samples         con     39 
    divider         con     20
    hysteresis      con     2
    min_pwm         con     30
    max_pwm         con     50
    
    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=62
            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
            If act_temp <= set_temp then 
            pwm_pars = 0
            else
            pwm_pars = min_pwm+(act_temp - set_temp)
            if pwm_pars>max_pwm then pwm_pars=max_pwm
            endif
            gosub set_pwm_pars
            val_1=act_temp
            val_2=pwm_pars
            val_3=set_temp
            Return
    
    Main:
            gosub read_act_temp
            gosub send_out
            pause 1500 
            goto Main    
    end
    Regards,

    Nick

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    Nick, The statement:

    if pwm_pars>max_pwm then pwm_pars=max_pwm
    endif

    can be made as such: pwm_pars = pwm_pars min max_pwm

    That way no if then is needed.
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    Hi David,

    Thank you for the hint. It will be first on my “To do” list.
    I noticed it in your first post and mark it as a good candidate for the time when I will do code optimization. I just slapped the code together to see how the system works in a dynamic scenario and prove the concept. The way I thought it is that when the actual temperature is way higher than set temperature the system will push maximum power. The closer the two temperatures are the system reduces its output. Only when the actual temperature is lower than set temperature the TEC will be turned OFF. This reduces the number of ON / OFF cycles which I understand the TECs are not happy with.
    I am open to any other suggestions that will improve the project.

    Nick

  4. #4
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    I’m in between two trips and had a little time to add a new feature to the code: hysteresis.
    Adding few more variables and a call to te_control subroutine (code below) in the Main loop I can smoothly control the temperature with a ±2⁰F (good enough for me now).
    One added bonus is that when restarting the TE after it was OFF I’m starting it with a safe voltage level output (start_pwm = 40) that will make sure the fans will not hesitate starting. After one cycle the regular rule, drive the TE as hard as the difference (act_temp – set_temp) is, kicks back in place. Short bench testing shows that it works like it should. When returning from next trip I will do more testing and also play with the values of min_pwm, start_pwm and max_pwm in order to get the desired temperature range with maximum efficiency and minimum ON / OFF TEC cycles.

    Code:
    te_control:
            If act_temp < (set_temp-hysteresis) then 
            pwm_pars =0
            pwm_flag=1
            endif
    
            If act_temp > (set_temp + hysteresis) and pwm_flag =1 then
            pwm_pars = start_pwm
            pwm_flag=0
            goto jump
            endif  
    
            If act_temp > set_temp and pwm_flag =0 then 
            pwm_pars = min_pwm + (act_temp - set_temp)
            endif
    jump:
            gosub set_pwm_pars
            Return
    My questions are:
    Is there a more elegant way of doing it?
    Am I covering all logical possibilities or some more code is needed?

    Any input will be appreciated.

    Nick

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    according to this a pid style of control may extend the life of your peltier device, thermal cycling is detrimental

    https://thermal.ferrotec.com/technol.../thermalref10/
    Warning I'm not a teacher

  6. #6
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    Hi Richard,

    Thank you for the link. I’ve been reading a lot about TEC controllers lately but did not find this one.
    I know my goal might be too ambitious but so far the results are encouraging.
    All I did so far is trying to create a poor man’s PID system at its simplest form.
    Based on the temperature difference (act_temp – set_temp) I change the output level of my PWM.
    It might be a little abrupt in the beginning but after the temperature stabilizes there will be only small steps in the voltage output (about 0.15V per step). That puts me lower than maximum admitted ripple for the TEC (5 – 10%) and it is only an occasional change not continuous like a non-filtered AC to DC voltage.
    If I can find the right range (more testing is needed and unfortunately I must travel a lot for the next few weeks) I might not have to turn the TEC OFF at all and only lower the output voltage to maintain the temperature, which in turn keeps the TEC happy.
    Since I’m having the fans paralleled with the TEC I must keep this min_pwm adove a certain value. Some brushless fan manufacturers recommend 5V as minimum running voltage and 7V as minimum starting voltage. That is the reason why I’m starting the system with a kick.
    Not sure if this is the best approach reason for which I’m posting here.

    Thank you for the input. I hope others will be interested in this project and bring new ideas to the table.

    Nick

  7. #7
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    Why not add another sensor on hot side of TEC to control fans independently from TEC?

Similar Threads

  1. Repeater ID and controller
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 29th March 2012, 23:06
  2. SMS Controller
    By savnik in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th September 2006, 15:12
  3. temperature controller
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th April 2006, 20:01
  4. PID CONTROLLER help..
    By tkly36 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th April 2006, 07:19

Members who have read this thread : 0

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

Posting Permissions

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