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