Quick PID Tuning Example


 

Bryan Mayland

TVWBB Hall of Fame
I want to do some calibration testing sort of like how the commercial NIST calibration blocks work but first I needed a steady temperature. Just running a bench power supply at fixed current output worked ok but it takes a long time to settle at a temperature. I've built a quick test rig using a 4.3 prototype HeaterMeter, an E3D V6 hotend that I had sitting in my parts drawer, and an M6 threaded thermocouple off Amazon (which happens to be the size of E3D nozzle threads). The cartridge heater can be controlled by the HeaterMeter 12V fan output and the aluminum block adds a nice mass to connect the two instead of just kapton taping the two together.

The PID coefficients that I use on the grill didn't do a terrible job but I thought it would be fun to do a PID tuning and post the results. Kp, Ki, and Kd are the PID constants instead of P, I, and D because it is difficult to tell if I mean "(I) did this" or "(The I Term) did this".



  • First step was to get the temperature close to where I wanted to tune (100C) then set Ki and Kd to 0 in the webui as well as setting the Lid Detect to 100% to disable it. I picked a starting Kp of 10 randomly. As you can see following the first hump (by the F in 'Fast Decay') the oscillation error in the system quickly decayed and almost settled out. Needed a higher Kp.
  • Kp=15 and restart the test. Looking at the temperature swings, this does a good job but you can see in the Fan Output that the output is decaying which means that the temperature oscillations will also decay, just at a slow pace. Close, but need a higher Kp.
  • Kp=18 and restart the test. The first two oscillations decay as the controller locks in, but the next 5 look great. I pop over to the Status -> System Log and scroll to the bottom to see that HeaterMeter has calculated our PID constants for us for a 71 second period, 2 degree amplitude oscillation with no decay (0 gain):
    Code:
    Sat Mar 18 14:54:48 2017 user.warn : New -1 peak @1489848865=98.0 half=35 per=71 amp=-2.0 gain=0.0
    Sat Mar 18 14:54:48 2017 user.warn :   Ziegler P=10.8 I=0.304 D=3.2
  • Enter these new terms into the webui for Kp, Ki, Kd aaaaaand disappointment. The temperature is now oscillating around the setpoint, but it is still oscillating. I would call this the typical pretty terrible results I've seen from PID tuning. The temperature swing is about +0.6C to -1.2C. Using the formulas on the PID Tuning wiki page, I calculate the Tyreus-Luyblen coefficients using the same data from the syslog. P=8.18 I=0.115 D=6.76. This looks better with only +0.1 to -0.2C max oscillation, but seeing the power go up and down shouldn't be happening considering how stable the test device is.
  • Cut all PID parameters in half, to P=4.09 I=0.058 D=3.38. This reduces the ability of the controller to react quickly to needed output changes, but reduces sensitivity that can cause fluctuations at steady state. After that, looks great!

That's all there is to it! The problem with possibly applying this to use on a smoker is that instead of a 71 second period for an oscillation, the slow-reacting nature of a fire can cause each period to be 10 minutes or longer. Instead of taking 40 minutes, this would take 400 minutes. In that time, the conditions in the firebox will change which reduce the repeatable nature of each test iteration and could invalidate the entire process.
 
Bryan,

I used this exact method that you outlined to do the PID tuning on my masterbuilt electric smoker. Worked like a charm. Turns out it is not that much different than a 3d printer head, lol. Thank you for sharing this!
 
Great clarification on how to tune a loop. As your example shows it takes time and the "I" value calculations does not always calculate out as an effective value to plug in. One thing i might add is where you figure out the period oscillation, the next big player that will come to haunt you is the ambient temperature that the device, smoker, is in. That real world variable is fun to deal with. Maybe there is a way to fine tune the PID values based on using one of the unused probes to compensate for ambient temperature influences on the smoker. When its cold out, I sometimes need to adjust the "I" value because of the loop now has a slower period of oscillation. Just opening the damper just starts to cause oscillations because that acts as a "P" increase.
 
It seems that historically there hasn't been much luck using the Ziegler parameters in the log, so would it be helpful to replace those with the Tyreus ones.
 
It seems that historically there hasn't been much luck using the Ziegler parameters in the log, so would it be helpful to replace those with the Tyreus ones.

+1 good idea. or can somebody make a converter for it? input Ziegler output Tyreus.
 
Dummy question - do I need to change PID settings for lower temp, like 190-200 for example? I tried to use default at it didn't work at all on such low temps, but works fine for 250.
 
Dummy question - do I need to change PID settings for lower temp, like 190-200 for example? I tried to use default at it didn't work at all on such low temps, but works fine for 250.

No, it should work fine. What are you seeing happening at lower temps?
 
I've always found using a high startup fan setting is better as the rate of change in pit temp is more rapid on the initial rise, and therefore the HM reacts faster as a result to close the damper sooner (before target is reached) rather than later. If the initial rise in temp is slow the HM may keep the output on longer, perhaps even after target temp is reached, which can lead to overshoot.
Obviously this is all heavily influenced by your PID settings....
 
Last edited:
On my ceramic Kamado I’ve experienced what YevgenB was describing, and for me, turning down the startup speed seemed to help.
 
That how it looks like:
SNKppXW.jpg


Funny thing - I let it stay and it recovered after one or two hours by itself. But it took almost two hours to get back. Maybe I started it wrong? I put starter cotton swab with alcohol, wait for 5-10 minutes than closed it with HM turned on and vents opened, than closed it after temp reached 120-150 and let it do it's own stuff. I have a feeling that charcoal can be too small and restricts the air from the bottom, but I never had this problem without HM.
 
Last edited:
Could you tell me how to see the information? No matter what i set LOGGING to (from debug, info ....) I don't see ANYTHING like the log you posted.
It should show up in the System Log with whatever the default log settings are. It shows up once it starts detecting peaks in the pit temperature, which you'll see when you hover your mouse on the pit temperature in the graph. The last high and low peak are listed in the tooltip when the mouse is near to them. There are some conditions for the duration of the cyclic period and peak-to-peak temperature delta before it counts as a cycle so be sure the cycles aren't too fast (more than a minute or two?) or too small (less than 2 degrees?).
 
I have an issue with my Kamado Joe Classic and Microdamper setup where it maintains temperature ok with a degree or two f. But I have found that due to the efficiency of the Kamado the Microdamper spends a lot of its time closed and my most recent smoke came out very bitter.

Top vent daisy wheel open 60% P:3.5 I:0.0038 D:7.002

Fan on 100% start up. Damper fully open at 70% and the fan on above 30%

Does anyone with a similar set up ie Kamado BGE and Microdamper have any settings to share as I am smoking a brisket today and have left off the damper and fan. Thanks guys.
 
Since the KJ is so efficient ( I love mine too ) why not try doing something like:

damper fully open at 40%
fan on above 41%
 
Hi Steve, yes I changed it yesterday to Fan on Start up max 50% and fan max 50%. Fan on above 65% damper full open at 60% I left the 5% between the damper and fan to allow for the temperature to oscillate before bringing the fan on straight away.

Slight adjustment of the PID settings and it held within 1 deg F all day never less than 25% damper both sides. Brisket was excellent.
 

 

Back
Top