I am doing a project to control the temperature with PWM. I use peltier, thermistor,mcu and h-bridge mosfet.

I want to reach a temperature with an error less than 0.05 and stay at that temperature without much (at most 0.05 C) oscillation. My first aim is to reach that temperatures in room temperature (no other effects than room temperature). Lets consider cooling mechanism, in room temperature, for example 14'C requires .285 PWM (out of 1) ,13'C requires .330PWM, and 20'C requires .180PWM. There is no linearity between them, and also changing PWM does not provide linear current change, ex: 1.0 PWM provides 2.15A, 0.5PWM provides 0.6A, and 0.2 PWM provides 0.16A across the peltier in room temperature. My first cooling algoritm:Initially constant=0 Keep PWM 1.0 until temperature is close to set temperature (t_set) by 2, then lowering the PWM with, PWM=constant+ (temperature-t_set)/2, after temperature is set to a temperature constant=PWM, and then PWM=constant+ (temperature-t_set)/5 and so on. And the system reaches steady temperature after 10-15 seconds after the PWM is changed, when PWM change >0.1

First question: How the mcu can can learn the PWM value that keeps the temperature constant? ( ex: 13'C requires .330PWM)

Second question: Is it possible to use PID algorithm to stabilize PWM value at set temperature without knowing the constants at first question?

Third question: If I find a good way that mcu to learn PWM values to keep temperature constant at different environments, and If I use good PID coefficients, do the PWM coefficients works for any environment, or are the PWM coefficients environment specific, ie: heat sink medium and differnt temperatures.

Thanks in advance.

--After 6 hours, from the answers

Q1- Learning that coefficient (I think) requires some algorithm when there is no PID.

Q2-Yes, with good PID coefficients it perfectly stabilizes, error term will be 0 and the only integrator term keeps the system stable, in noiseless environment.

Q3- If good PID coefficients are used and with educated (??) guess some level of stabilization can be accomplished.

To achieve good results in different environments (I think) it is needed to develop a auto tuning PID. My design criteria are keeping the temperature error minumum and keeping the reaching time for stabilization low (if possible).

From the result if it is approprite to ask here my fourth question is: Q4: Which methods do you suggest me to find Ki, Kp and Kd coefficients in different environments (auto tuning PID coefficients when the mcu starts or restarts).

  • 1
    \$\begingroup\$ Before you get into the control system for maintaining temperature to within 0.05 degC, you have to first be able to measure better than 0.05 degC. That's not trivial. Frankly if you're asking here and this hasn't even occurred to you so far, then this project is way over your head. Get someone that knows this to do it for you and learn from them. Then maybe next time you can to it yourself. \$\endgroup\$ Commented Oct 22, 2014 at 13:51
  • 1
    \$\begingroup\$ @OlinLathrop , yes I am able to measure better than 0.05 deg, by NTC thermistor and after collecting 100-150 samples at each measurement I apply a filter, and some kind of averaging with last 3 temperature, this gives fairly good measurement. \$\endgroup\$
    – electro103
    Commented Oct 22, 2014 at 14:09

1 Answer 1


Q1: The controller will find the PWM value to keep the temperature at the setpoint if the PID is reasonably well tuned. If it not tuned well, it may oscillate around the setpoint or be very sluggish in approaching the setpoint, and also slow to respond to demand changes (such as a change in ambient temperature).

Q2: Yes, if you make an educated guess as to the values it is possible to get stable control with a try or two. Or use a self-tuning algorithm. And/or a manual method such as Ziegler-Nichols.

Q3: They will work reasonably well for some range where things stay more-or-less linear. If you triple the wattage of the Peltier, for example, you'll probably get a lot of overshoot. In most applications (not all) the tuning parameters are fixed numbers for a given range of setpoints (perhaps all valid setpoints).

It's not always possible to get the control you need with a single control loop, sometimes nested loops are required. I've gotten control down to the \$\mu K/\sqrt {Hz}\$ level but it's not easy. Your 0.05°C may be difficult or not so bad, depending on what the system looks like.

  • \$\begingroup\$ Should the PWM equation depend only PID result, or it depends PID result + some constant. Let say my t_set is 13'C and required PWM is 0.33 at steady state. Without knowing 0.33 let say PID controller bring temprerature between 12.90 and 13.10. I'm new to PIDs, one thing that I do not understand is, if the PID reaches to the set temperature (13.0), then the error term is 0 so the proportional term is 0, and difference (derivative) term is 0, the only balance is integrator term 0.33? \$\endgroup\$
    – electro103
    Commented Oct 22, 2014 at 12:39
  • \$\begingroup\$ And of course the loop keeps the temperature of the sensor "right on" (if tuned correctly.) But it's the temperature of something else that you really care about. @electro103, Re: integrator, yes at balance it's the integrator that holds the correct "gain" number for the system. \$\endgroup\$ Commented Oct 22, 2014 at 12:59
  • \$\begingroup\$ thank you for the information "integrator that holds the correct gain" @GeorgeHerold. It really helped. \$\endgroup\$
    – electro103
    Commented Oct 22, 2014 at 13:05
  • \$\begingroup\$ The constant basically sets where the integrator starts out from, where it finished will give you the steady-state output (it will integrate until the error is driven to zero, as seen by the controller). So if it needs 100% power, 0% or anywhere in between, the integrator will produce an output that will result in that output (taking into account any fixed bias in the ouput). The proportional term will be zero at zero error, and the derivative term will be zero when the output is stabilized. \$\endgroup\$ Commented Oct 22, 2014 at 14:14
  • \$\begingroup\$ @GeorgeHerold I don't much like the use of the term 'gain' here. There are integral, derivative and proportional gains, and the output of the integrator is none of those. Maybe I'm missing something, but it seems inappropriate. \$\endgroup\$ Commented Oct 22, 2014 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.