AVR221 and TEC Temperature Controller

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I am using AVR221, which contains cond for a PID controller. I have everything working correctly, but the PID controller is not doing exactly what I expect. When I go above the setpoint temperature, the TEC is set to cool. When I go below the setpoint temperature, the TEC is set to heat.

I am using a H-Bridge to route current through a TEC. One direction cools, another heats.
- The bottom two NMOS are pulsed using PWM. A higher voltage at the NMOS gate allows more current through. One is pulsed and the other is fully off.
- One PMOS is fully on and one fully off.

I believe that a PID controller is supposed to decrease the current going through the TEC when it gets closer to the setpoint, until it reaches a comfortable level. If the PID controller bottoms out and hits the min output, I would force the TEC to start heating/cooling by forcing the current the other way and starting the PID process over.

I can't figure out how to do this. I believe the following blank code is supposed to do this.

void Set_Input(int16_t inputValue)
{
  ;
}

I wrote this:

void Set_Input(uint16_t inputValue)
{
  if(heat_mode == 'h') 
  {
    OCR1B = 83*inputValue; //observed max of inputValue was 767 at setpoint = 99.9 and temperature = 0
                           //0xFFFF / 767 = 85.4
    
    if ((temperature - 1 ) > setpoint) //cool if temperature is overshot and enter cool mode
    {
      PORTA = HBOFF;
      __delay_cycles(80000);
      PORTA = LRFLOW;
      heat_mode = 'c';
    }//end if 
  }//end if
  
  else 
  {
    OCR1B = 0xFFFF - 83*inputValue;  //observed max of inputValue was 767 at setpoint = 99.9 and temperature = 0
                                     //0xFFFF / 767 = 85.4
    
    if ((temperature + 1 ) < setpoint)  //heat if temperature is overshot and enter heat mode
    {
      PORTA = HBOFF; 
      __delay_cycles(80000);
      PORTA = RLFLOW;
      heat_mode = 'h';
    }//end if
  }//end else
	
}//end Set_Input

I also am not sure if the 83 is correct. I am multiplying by 83 because I found that the max value of inputValue is 767. Multiply 767 * 83 = 2^16 approx, which is close to the max value of OCR1B.

How do I get the PID controller to decrease the current to the TEC without flipping back and forth between heating an cooling? So say at 30'C, the PWM should output a voltage that produces x amps of current, which keeps the TEC constantly running at around 30'C. If the temperature oscillates, the PID should increase/decrease the currently slightly to return to equilibrium, rather than switch to heating/cooling non-stop, which is what I am doing now.

Cheers

Attachment(s): 

Last Edited: Fri. Jan 4, 2013 - 06:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why is Q5 back to front?

The 2N7000 is rated at 60V absolute maximum yet you are running them at 120V!
What about the other 4 FETs? Are they rated for 120V?

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The picture doesn't show the dot well in 12.0V in the schematic.
Good catch with Q5. I rotated Q5 from the other instance of it. I should haves mirrored it vertically. I will fix this and repost the image. The TEC uses 12V. The four ports are 5V.

The h-bridge works perfectly fine. It's my PID set_Input() function I need some advice on. I tried blocking the statements that switch the TEC to cooling when I am just heating, but that didn't work. The PID actually went to overdrive when the temperature went above the setpoint. It went into thermal runaway.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I fixed all of the mosfets on the right. They were all flipped the wrong way. And the PMOS were backwards as well. Thanks for the tip mate.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
The picture doesn't show the dot well in 12.0V in the schematic.
Unless you are planning on using some fractional point power supply drop the .0 and just use 12V.

So is it running correctly now? :-)

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know why I used the .0... I'm used to adding it for 5.0V so I just kept the same format for 12V.

I built the H-Bridge the correct way from memory. The schematic was rushed, so I missed a thing or two.

I can guarantee the H-bridge is 100%. My problem is getting the PID to work right. I can't figure out how to dial down the current without causing the PID to flip to heating or cooling close to the setpoint.

Any advice?