At CheckAG, we're currently developing a Thermoelectric Cooler (TEC) control system for precise temperature regulation — a critical part of many of our spectrometry projects. I wanted to share the initial steps of implementing PID control for the TEC and some design choices we've made along the way.
Understanding PID Control
PID control — Proportional, Integral, and Derivative control — is a widely used feedback control method for dynamic systems. It works by continuously calculating the error between the desired setpoint (target temperature) and the current value (actual temperature), then adjusting the output (PWM to the TEC module) based on three terms:
- Proportional (P): Reacts to the present error. The larger the error, the stronger the correction.
- Integral (I): Reacts to the accumulation of past errors. This term helps eliminate steady-state error.
- Derivative (D): Predicts future error based on its rate of change. It helps to dampen the response and prevent overshooting.
The control signal is computed as:
Output=Kp×Error+Ki×∫Errordt+Kd×d(Error)dt Output = Kp \times Error + Ki \times \int Error dt + Kd \times \frac{d(Error)}{dt}
In our setup, we used these initial PID constants:
float Kp = 420, Ki = 32, Kd = 1365;
Unidirectional Control for the Peltier Module
A key design choice we made is to use unidirectional control rather than bidirectional control. Typically, bidirectional control allows a Peltier module to both cool and heat by reversing the current flow. However, we opted for unidirectional control for two reasons:
- Simplicity: It reduces hardware complexity since we don't need an H-bridge or additional switching components.
- Ambient heating: When the MOSFET is off, the TEC naturally warms back to ambient temperature due to passive heat exchange. This allows us to rely on the environment to heat the TEC when necessary.
Our control logic works like this:
- MOSFET ON: The TEC cools down.
- MOSFET OFF: The TEC passively heats back up towards ambient temperature.
The PID controller's output is simply mapped to a PWM signal controlling the MOSFET’s gate:
analogWrite(PELTIER_PWM, controlSignal);
PID Tuning: Ziegler-Nichols Method
Tuning the PID gains is crucial to getting stable and accurate temperature control. We used the Ziegler-Nichols method for tuning, which follows these steps:
- Set Ki and Kd to zero.
- Increase Kp until the system oscillates at a constant amplitude — this is the ultimate gain (Ku).
- Measure the oscillation period (Pu) — the time it takes for one full oscillation cycle.
- Calculate Kp, Ki, and Kd using these formulas:
| Kp | Kd |
|---|---|
| 0.5 * Ku | 0 |
| 0.45 * Ku | 0 |
| 0.6 * Ku | Kp * Pu / 8 |
After tuning, we landed on:
Kp = 420; Ki = 32; Kd = 1365;
Final Thoughts
This unidirectional control design simplifies the hardware and leverages natural thermal dynamics to heat the TEC. The PID controller, tuned using Ziegler-Nichols, balances responsiveness and stability.
I'll continue to share updates as we refine the system further. Let me know if you'd like to dive deeper into any part of this — from the PID algorithm to the hardware design!
What do you think? I'd love to hear your thoughts, suggestions, or even experiences with TEC control systems!
Mohamed Faizan Tabassum
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.