How do I tune this PID for my coffee machine?
The duty cycle is based on a period and how long the heater is on. So if lets say your coffee heater is on for 1 second and off for 1 second. Your period is 2 seconds and your duty cycle is 50% since it's on for 1 out of the 2 seconds. If your heater is on for 1.5 seconds and off for .5 seconds, your duty cycle would be 1.5/2 (75% Duty cycle).
The Kp is your proportional. The error (setpoint - actual reading) will get multiplied by your proportional value. The Ki is your integral, this accumulates the error over time and then will essentially increase/ decrease your output more and more over time until the error gets closer to 0. The Kd is your derivative and this basically &quot;predicts&quot; where your going. This counter acts the integral to prevent too large of over shoots.
So when you're tuning, this is a good way to look at things.
If your proportional (kp) is too low, it will take too long to get to the set point since your duty cycle will be low, but the temperature will have little or no overshoot past your setpoint. If the Kp is higher, it will heat up faster but you're likely to have a decent overshoot.
If your integral (ki) is too low, then your temp will rise slower but tend to have less overshoots. If your integral is too high, you will heat up faster and faster until you reach your set point. This will cause you to have some positive and then negative overshoots (oscillations).
I typically set Kd to 0 until the Kp and Ki are working fairly well. This is called a PI controller. Then I use the Kd to reduce the overshoots. If you set this too high, you will get oscillations.
It's a trade off game between how fast you want to reach your setpoint and how much you're willing to overshoot.