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

    Hi All,

    After gathering all the stock ingredients I ventured to prototype something to get me started (see attached schematic). Most of the stuff was already made from older projects so I just needed some re-wiring.
    To my surprise, at the first try, I was able to drive a TEC with an 80KHz output from an older PIC 12F683 board. I will have to look back to find the code that runs it but it basically outputs 80KHz of about 40% duty cycle PWM for about 3 seconds and about 75% for 3 seconds.
    The output voltage to the TEC goes from 5.5V to 8.5V with a current draw of 1A and respectively 3A.
    Checking with an old scope the TEC voltage is pretty clean.
    I separately built a refrigeration box out of ¾” Styrofoam and I was able to maintain a bottle of wine at about 45⁰F for two days running the TEC under 5.5 V from a separate PSU. I will do some more testing like this to figure out the minimum voltage that is needed to maintain a decent temperature in the cooler without having to turn the TEC OFF. I will do so after replacing the first wine bottle which became “a casualty of the project” and I opened it to celebrate the first successful test. This is becoming a fun project. LOL
    Next step will be to fine tune the switching frequency for efficiency and the needed PWM range to get my lowest and highest output.

    I will keep you posted and I might come back with some clarifications and maybe questions. I will also post the code that I’m running after I get it optimized.

    Nick
    Attached Images Attached Images

  2. #2
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    I trying to control PWM output on a PIC12F683 and I wrote the following code for a quick test:
    Code:
    @ device  pic12F683, intrc_osc_noclkout, wdt_on, mclr_off, protect_off
    
    OSCCON=%01110111     
    DEFINE OSC 8        
    
    ADCON0=%00001101
    ANSEL   = %00111000       
    TRISIO=%00011000        
    CMCON0=%00000111        
                
    i           var         byte
    pwm_out     var         GPIO.2
    
    CCP1CON = %00001100     
    PR2 = 15            
    CCPR1L = 0         
    CCP1CON.5 = 0
    CCP1CON.4 =0
        
    
        Pause 200
        T2CON.2 = 1             
        Goto main
    Main:
         for i=8 to 14
         CCPR1L = i
         CCP1CON.5=0
         CCP1CON.4=0
         pause 250
         CCPR1L = i
         CCP1CON.5=0
         CCP1CON.4=1
         pause 250
         CCPR1L = i
         CCP1CON.5=1
         CCP1CON.4=0
         pause 250
         CCPR1L = i
         CCP1CON.5=1
         CCP1CON.4=1
         pause 250
         next
         for i=14 to 8 step -1
         CCPR1L = i
         CCP1CON.5=1
         CCP1CON.4=1
         pause 250
         CCPR1L = i
         CCP1CON.5=1
         CCP1CON.4=0
         pause 250
         CCPR1L = i
         CCP1CON.5=0
         CCP1CON.4=1
         pause 250
         CCPR1L = i
         CCP1CON.5=0
         CCP1CON.4=0
         pause 250
         next
         CCPR1L=0
         Pause 5000
    Goto Main
    What I’m trying to do is use the finest possible steps in controlling the PWM.
    Please ignore the low case spelling on some lines of the code. I did not realized I have the auto capitalize feature enabled and I became lazy. The code works since the Micro Code Studio fixes them for me. I know is a bad and risky habit and I will try to fix it.
    The code rumps up and down from 5.5V output to 9.5V in 28 steps and after 5 seconds stop repeats the cycle which should take 14 seconds without the pause. It is just to easily explore all possibilities.

    The question is: Can I somehow combine the CCPR1L and CCP1CON<5:4> in one single variable so it is easier to handle in the FOR / NEXT loop and make the code more elegant?

    Any input will be greatly appreciated.

    Nick

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


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    This is how I do it for a word sized variable that gives you 10 bits of resolution:

    CCPF = CCPF MIN MAXPWM
    CCPR1L = CCPF >> 2 'UPDATE PWM1 UPPER 8 BITS
    CCP1CON = $0C | ((CCPF & $3) << 4) 'UPDATE PWM1 LOWER 2 BITS
    Dave Purola,
    N8NTA
    EN82fn

  4. #4
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    For CCP1CON bits this is much faster
    CCP1CON.5=CCPF.1
    CCP1CON.4=CCPF.0

  5. #5
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    Thank you Dave and Pedja089 for your input.
    I will try implementing your suggestions and report back the results. Unfortunately I just started work so it has to wait for a few good hours.
    I was thinking to try something like this subroutine but it was too late last night:

    Code:
    Set_pwm_pars:
    	CCP1CON.4 = Pwm_pars.0
    	CCP1CON.5 = Pwm_pars.1
    	CCPR1L = Pwm_pars >> 2
    	RETURN		
    Main:
    	FOR i = min_pwm to max_pwm
    	Pwm_pars = i 
    	GOSUB Set_pwm_pars
    	PAUSE 250
    	NEXT
    	PAUSE 5000
    	GOTO Main
    My goal for now is to get enough steps with about 0.25V between them so the TEC will not complain.
    BTW does anyone know if slow, occasional (every few minutes) 0.25V steps combined with heavy capacitor filtering will affect the TEC?

    Thanks again for your input.

    Nick

  6. #6
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    Just a quick update: I’ve tried all three suggested methods and they all work as expected.
    I will do some more hardware changes, now that I have a stable test code. I will experiment especially with frequency changes and inductors values. I’m trying to get as much efficiency as possible.
    What is encouraging though is that running the prototype for long time does not generate heat at all. The main power components are cold and the current draw (from the 12V source) swings between 1A and 2.5A.
    I will post the latest working code as soon as I get it cleaned up.

    Nick

  7. #7
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: TEC controller

    This is the working code. It steps up through 21 steps of PWM (from 30 to 50) and then steps down (from 50 to 20). The result is an output voltage between 5.5V and 8.5V (the numbers are rounded up). This is design for testing the flexibility of the system only. Final code will implement a temperature controlling algorithm. BTW I switched to PIC16F819 since this is the PIC I'm going to use for this task.

    Code based on Dave's input (183):
    Code:
    @__config_device_pic16f819
    @__config_wdt_off
    @__config_hs_osc
    @__config_pwrt_on
    @__config_mclr_off
    @__config_lvp_off
    @__config_protect_on
    @__config_CCP1_RB2
    
    OSCCON=%01110111     
    DEFINE OSC 8        
                
    i           var         word
    pwm_out     var         PORTB.2
    pwm_pars    var         word
    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 
        goto Main
    set_pwm_pars:
         CCPR1L = pwm_pars >> 2
         CCP1CON=$0C|((pwm_pars&$3)<<4) 
         RETURN
    Main:
         for i=min_pwm to max_pwm
         pwm_pars = i
         gosub set_pwm_pars
         pause 250
         next
         for i=max_pwm to min_pwm step -1
         pwm_pars = i
         gosub set_pwm_pars
         pause 250
         next
         Pause 5000
    Goto Main
    With the same main loop I changed the subroutine set_pwm_pars based on Pedja089 input (163):

    Code:
    set_pwm_pars:
         CCP1CON.5 = pwm_pars.1                
         CCP1CON.4 = pwm_pars.0
         CCPR1L = pwm_pars >> 2
         RETURN
    Finally my simplified version for the subroutine (187):

    Code:
    set_pwm_pars:
         CCP1CON.5 = pwm_pars.1                
         CCP1CON.4 = pwm_pars.0
         CCPR1L = pwm_pars / 4
         RETURN
    The output from all is the same (as expected). Cannot comment on execution speed and for my purposes it doesn’t really matter. I will only set a step, based on the temperature control algorithm, and sit on it for a while. I’m sure that the wine will not mind a few microseconds shifted response.
    The one difference between the three versions is the code space required. The numbers in parentheses are showing that.

    So far I’m happy with my results.
    I will work on the hardware for the next few days and start working on the temperature control algorithm after that.
    Before I start this new task I’m asking all the people in this forum that might have some experience in this field: Am I on the right track? Is there a better way to do it?
    I love its simplicity and the fact that I fully understand how it works but in the same time I hate to find it out that is wrong after I already spent a lot of time on it.

    As always looking forward for input.

    Nick

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