# How do I tune this PID for my coffee machine?

I have tried to reach out to the developer of this software with no success. There seems to be an error in the code, and when you follow the steps, the last step does nothing.

Steps for PID Tuning (Ziegler-Nichols Open-Loop):

• Set to Manual Mode and 100% Duty Cycle
• Wait for Temperature to increase by at least 10%
• Turn Temp Controller off and Stop data capture
• Highlight Sloped Line after Dead Time on Plot

(I would have assumed in the bottom right corner it would suggest new values but in the Java code you get an error (when you highlight you get 0,0 instead of what's actually on the graph.)

Anyway. I have researched how to adjust/tune a PID, but whenever I try to cross-reference this one, the letters don't match up. Usually kp ki etc. but I have PID Kc parameter, PID Ti parameter, PID Td parameter.

So can anyone suggest how I can tune this manually? And also explain to me what these inputs mean? Actually ELI5

I know the setpoint is the target temp, but I don't quite understand duty cycle and cycle time or actually any of the rest.

This is the web view of my espresso PID controller:

Thanks a lot for your help. Once again, I'm not really looking to fix the broken issue with the Java code, just want some sort of translation so I can manually tune this PID.

• And the code is where ? – Graham Stevenson Oct 11 '20 at 0:05

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 "predicts" 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.

• Please re-read the question, as you have not addressed the askers actual difficulty at all, but only repeated the sort of generic guidance they said they have already found. – Chris Stratton Oct 11 '20 at 1:46

There are different forms of the PID controller. Most likely the controller algorithm does something like this (image from here):

The controller gain Kc affects all three components of the controller output in this configuration.

You can attempt to do a open-loop Z-N tuning of the controller manually. This uses the step response of the system.

It's also possible to use closed-loop Z-N tuning, you basically disable I and D and increase gain to provoke an oscillation, then use the measured parameters to calculate the control parameters. The original numbers tend to be a bit aggressive (lower gain is better).

Practical PID controllers usually have some additional algorithm tweaks to prevent integral windup and inhibit overshoot, usually involving an additional parameter, however this controller design does not appear to implement that.

I don't know how fast your system responds, but the gain shown looks plausible for Kc but Ti seems rather fast. Td usually isn't too important- keep it no more than 20-25% of Ti. Too short a Ti time for a given Kc will cause instability.