PID auto-tuning algorithms on various controllers can be annoying. I got tired of having to wait for them, only to see results that oscillated rather than being steady (especially during a print), so over time I learned how to do it myself. With the method I describe here, my hot end never wavers from the set temperature by more than 0.1 degrees C during a print. I also never get that thing where it's "warming up forever," but never quite reaches the exact print temperature, causing the print to never start. The heated bed stays on target, rather than oscillating between low and high power, so the cooling fans aren't changing pitch all the time due to large swings in current draw. Finally, I don't have to wait for the auto-tune, only to get temperature control that's wavering by half a degree or more, when I can just do it myself in less time and get a fraction of that variation.
THERMAL RUNAWAY WARNING
A "thermal runaway" is where the heating element receives partial or full power well above the set temperature, which may cause it to keep heating until something melts or catches fire, like your whole entire house. DO NOT take your eyes off the temperature reading during the PID tuning process.
The following conditions can cause a thermal runaway:
- P set to a very low value - I would start at a minimum of 20 for a hot end, and 100 for a heated bed, and adjust up or down from there. (Even 20 might be too small - be cautious about this.) I have seen values less than 10 cause thermal runaway.
- Possibly other bad PID settings (haven't seen this myself, but can't rule it out).
- Power MOSFET on the controller, or external solid-state relay (SSR), "fails open," causing partial or full power delivery, even though the controller has commanded it to shut down. This can happen any time the heater is energized, whether or not you are messing with the PID settings. A thermal fuse is one way to compensate for this. If your power supply is capable of accepting a "shutdown signal", your controller and firmware may have a facility for triggering that - look in the documentation. (ATX power supplies may be able to do this. LED-style power supplies can't.) Alternately, it should be possible to fit an external DC SSR that controls voltage to ALL the heaters, assuming your board's microcontroller is fed separately from the heater power. That's pretty common. If your board can let you have 24V heaters, then the power is fed separately. I know Smoothieboards are like this, and I'm pretty sure the Duet and RAMBo are like this as well. The firmware would have to have thermal runaway code that sets the SSR's pin high when the system is in a normal state, to enable the heaters, and it would have to take the pin low if it detected a thermal runaway. I don't know which firmware does and doesn't do this. If you do, post about it!
- Possibly other things. Feel free to chime in.
How PID Variables Work
Now that you've made it through the scary disclaimers, we can get on with the show.
You can read up on proportional-integral-derivative (PID) algorithms, but they tend to be very complicated to understand. Instead, let me save you some time on that by showing you this excellent GIF animation from the article on Wikipedia:
See? MUCH easier than reading an enormous wall of text about integrals and derivatives! From that article, there is some explanation of what each factor does:
That table is nice, but for me, it's too much theory and not enough application. Let me boil all that jargon down into something directly actionable:
- "P" controls the reactiveness. It is called "proportion", but I like to think of it as "power" instead. This is because it determines BOTH how aggressively it will try to get the heater up to temperature, AND how aggressively it will back off as the temperature is approached/exceeded. The higher this value, the closer you have to be to the set point to get a big reaction out of the system, so increasing it to the right amount will narrow the range of temperature oscillation. (However, if you set it too high, it will backfire, so you'll have to experiment a little.) Set this first. If the heater doesn't get hot enough, increase it. If the heater overshoots like crazy, and never quite settles down to the requested temperature, decrease it - but not too low. If you set it to a very low value, it will heat constantly, and the temperature will run away! Anyway, don't expect the temperature to be smooth at this point. You just want it to be "sorta close."
- "I" fine-tunes the result you get from P, but will also make the temperature oscillation more "peaky." As you can see in the GIF animation above, it will get the average temperature to be what you set. If you ask for 210 degrees, and it's oscillating between 209 and 211, you have this one set right.
- "D" smooths out the final result. Increase this to take the "wobble" out of the temperature. Don't jump the gun and set it to some high number out of the gate. If there is an overshoot, undershoot, or excessive temperature oscillation, doing so may make it harder to figure out whether P or I (or both) need to be changed.
Maximum Current and PWM
In addition to the P, I, and D variables, you can set the maximum current and PWM pulse width. You may want to limit the current to both hot end and heated bed if you're using 12V heater(s) on a 24V system. Otherwise, it's usually left alone. Look at your documentation to be sure. If you are using an external SSR to feed the heated bed, this value is unlikely to do anything, so in that case I'd leave it alone.
The hot end usually doesn't require PWM to be adjusted, but the heated bed might. PWM (pulse-width modulation) controls how frequently the voltage is high (turned on), and how frequently it's low (turned off). The range is usually 0 (always off) to 255 (always on). If it's 127 (halfway point), it will be on half the time, and off half the time. Max PWM can be quite useful, especially if you have a "clean" circuit between the power supply and heated bed (i.e., you're using fat wires and a very-low-voltage-drop SSR to feed the heated bed). I think this is because when you use the controller's on-board FET, there is more of a voltage drop (electricity being lost and turning into waste heat), which has the same effect as reducing the PWM - in other words, less voltage gets to the heated bed per unit of time. When you're using a really good SSR, the voltage drop is negligible, the heater is able to heat more effectively, and the propensity to overshoot the target heat is greater. Reducing the max PWM allows us to "calm down" the heater a little, so it won't be as likely to overshoot.
On Smoothie, current is controlled with X, and max PWM is controlled with Y. On the Duet, it's different, and I'm not sure exactly how it works, but there are some values here on the RepRap Wiki. I don't know whether Repetier supports either current or max PWM.
As for Marlin, I suggest using Repetier instead. Runs smoother in my experience, stores many more config values in EEPROM, direct integration with Repetier Host, etc.
For the Hot End and Heated Bed sections, I'm using starting values that have worked on me with Smoothie. If you have a RAMBo or Duet, look in the documentation to see what starting values are good.
For an E3D v6, try P=30, I=5, D=5. The Cyclops, with a much bigger heater block, needs a P value more like 60. The hot end has a relatively small thermal mass, so it doesn't require a ton of power. Do the initial tuning with the printer not doing anything. You can refine it when an actual print is running. You may find that your best tune during a print is better than your best tune when the printer is still. I definitely see less oscillation when the printer is actually extruding. (This is another reason why hand-tuning is more accurate than auto-tuning on a 3D printer.)
These are more difficult to tune because they have a large amount of thermal mass, which adds a great deal of inertia to the equation. If you change the PID values on your hot end, you will usually see the result within a few seconds. Change them on your heated bed, and they may take 30 seconds to a minute to settle!
When tuning the heated bed, jog the hot end down to about Z=3 or so. The hot end's cooling fan will wash the heated bed with some air, increasing the heating load, and that will throw off the result. If you have a part cooling fan that you use a lot, it's not a bad idea to turn that on as well. If the printer is homed, you won't have those real-world effects going on, and you may find that the result is not as good as it could be.
For an Onyx, try P=130, I=1, D=15. It has far more thermal mass, so P has to be higher, and you can expect far less oscillation than you'd see with a hot end (assuming you tune it right). On RAMBo, I seem to remember P being set much higher (like 600 or something). Not sure on that, haven't used one for years. It would be a good idea to look up the best values, if they are available. Also, as heat loss increases exponentially with target heat, it's harder to PID tune an Onyx at 75C than it is at 50C. You may want to auto-tune the heated bed, and then fine tune it from there. I will add more information here, assuming I can figure it out myself!
Heated Bed with Solid State Relay (SSR)
PID values that work fine for the MOSFET on your controller won't work if you install a solid-state relay (SSR). The resistance of an excellent SSR, like the Auber Instruments 100-amp DC SSR, is extremely low, whereas the resistance of a relatively small MOSFET (like you find on a controller) is - if not exactly "high" - still significant. That's why the FET on your controller will get hot, whereas the Auber SSR will barely be above room temperature at 12V. When I asked Smoothie to auto-tune my SSR-fed Onyx, it came up with the values P=155, I2.5, D2350. P and I are not surprising, but D is huge! Maybe that is how the algorithm compensates for the very long thermal lag time.
EDIT: When I wrote the above paragraph, I was running the SSR on the ground side of the circuit. I have since switched it to the hot (+12V) side of the circuit and installed a Blue Sea Systems 25A circuit breaker. This threw off my PID tune. I'm now using values P=170, I=0.5, D=2250, and the temperature is almost always exactly at set point (75C +- 0.1 degree, sigma appears lower than 0.01C). It may be that the hot side of the circuit is a better location to put the SSR. When it was on the ground side of the circuit, it had more variance, and I had to limit the max PWM. As it is now, max PWM is 255 (highest value) and it has no trouble maintaining temperature.
Fore more info about using SSRs, this appears to be the definitive thread. For reference, this is my (amateur and not certified by an electrical engineer) SSR/breaker setup:
- Heater keeps getting significant power well above set temperature (thermal runaway): Make sure P is at least 20 (hot end) and 100 (heated bed). If it already is, you may have a "failed open" MOSFET or SSR. SHUT OFF MAIN POWER TO THE PRINTER WITHOUT DELAY.
- Heater never quite gets up to temperature: Increase P
- Heater overshoots by a lot/always stays above the requested temperature: Decrease P (but not too low). If not using an SSR, and it does this only on initial warm-up, you can try reducing the current.
- Heater oscillates in temperature, and the average isn't quite what you set the temperature to: Increase or decrease I
- Heater oscillates in temperature, and the average is at or very close to what you set the temperature to: Increase D
- Temperature oscillates by more than a few tenths of a degree: Fine-tune the values during an actual print. What you obtain from a "static" tune is different than an "in-print" tune.
- I still can't get it to stop oscillating: Try reducing the max PWM. 100-200 is a good starting range. If using an SSR, consider moving it to the hot (positive) side of the circuit if it isn't already.