I am working on realizing a temperature controller using an Peltier device, H-bridge and temperature controller. My temperature controller has a PWM duty cycle that (at 20 kHz) goes from -1000 (cooling) to 1000 (heating).

I use a type C servo loop as described in the document PID Controller Calculus (http://www.vandelogt.nl/datasheets/pid_controller_calculus_v320.pdf).

I have a PID servo loop for heating and a PID servo loop for cooling because heating is faster than cooling and has different parameters.

If I heat from 10 to 15 degrees with the PID servo loop for heating, it regulates to 15 degrees. Unfortunately, the water becomes warmer due to the room temperature of 22 degrees. How do I prevent this situation? Should I switch to the PID servo loop for cooling? The problem is that the temperature set-point has already been reached and the output of the PID servo loop for cooling is equal to 0 and the temperature still rises. The Peltier device needs a certain PWM duty cycle to maintain the temperature.

  • \$\begingroup\$ At least in one commercial device using a peltier to regulate the temperature to 20.1°C, both loops run concurrently. It is mostly cooling, but does pulse the heater at times, even when "cooling." \$\endgroup\$
    – rdtsc
    Nov 17, 2023 at 13:39
  • \$\begingroup\$ You may wish to use the rate of temperature change as an additional input. The temperature and desired rate of temperature change must be reached. You can also try to bulk up on insulation... \$\endgroup\$
    – Abel
    Nov 17, 2023 at 13:47
  • \$\begingroup\$ Can you saturate the heating pid 0...1 and cooling pid -1...0 and then add the outputs and use that for your h-bridge? \$\endgroup\$
    – Jeroen3
    Nov 18, 2023 at 16:21

1 Answer 1


You need to intelligently switch between heating and cooling.

As rdtsc said, you can run them both simultaneously. But you should know that if you do this, you need a very good tune, as the loop can oscillate very easily.

If you don't require extremely tight control it is better to run only one loop at a time, and switch only when certain conditions are met. In the past I have used the following conditions (to switch from heating to cooling): Temp is over setpoint AND temperature is not falling at >X rate AND heat has not been used for Y minutes. That seemed to work pretty well.

You might be able to make it a little smarter by checking the exterior temp and switching modes automatically once you go from servoing to temp hold. If the exterior temp is higher than your set point you might know that you will need cooling, or vice versa. This might not be reliable if you've got chemical reactions or evaporation changing the temp however.


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.