PID heater control with SSR - Page 1
Forum section: electronics / projects

author: davorin
author_rank: Unknown
timestamp: March 07, 2025, 11:10:15 am
content: Good afternoon (o;Doing a simple PID controller for a pizza oven based on an ESP32 module.Have a 10msec timer setup counting from 0 to 255 for switching on/off a SSR based on a PWM value.So the PID loop is 2.56seconds and gives me this output targeting 100°:Could the ripple be reduced when going for a smaller period like 1.28seconds and PWM values from 0 - 127?

author: Kleinstein
author_rank: Super Contributor
timestamp: March 07, 2025, 11:40:34 am
content: The ripple is slower than the mentioned 2.5 s period.There are different SSRs and when switching AC this can make a difference. The SCR based one can only turn one an than stay on for the rest of the half period. This way the phase between mains and the PWM signal can make a difference. To a lesser degree also with a MOSFET based SSR the phase can make a difference on how much power is actually coming to the heater. If the timing is not exact and with mains frequency a bit of nominal there can than be a slow beat frequency.With relatively high power there are regulations on how much PWM / phase angle modulation is allowed.Another point (especially the first overshoot) could be the PID response, with a rather high gain or not ideal parameters.

author: mikerj
author_rank: Super Contributor
timestamp: March 07, 2025, 12:14:30 pm
content: Like Kleinstein, I suspect this is a PID tuning problem. Did you try tuning the PID as proportional only to start with? If you can get a reasonable transient response with only a P term and it settles (with the expected error from proportional only control) without the ripple then it's not the PWM period causing the issue.

author: davorin
author_rank: Unknown
timestamp: March 07, 2025, 12:17:57 pm
content: I used a PID autotune library for Arduino to get those Kp, Ki and Kd values...Odd is that the tuning library switches the SSR only fully on or off during the ten cycles.

author: mjkuwp
author_rank: Unknown
timestamp: March 07, 2025, 12:20:14 pm
content: You should have a faster loop and change the PID tuning. How about a ~1 second period for simplicity. You can forget that auto tune stuff and just try tuning it manually.

author: davorin
author_rank: Unknown
timestamp: March 07, 2025, 12:38:20 pm
content: I guess you're right (o;Got now PWM values form 0 - 127 which corresponds to a 1.28sec period.Now with values of:Code:Kp=5.522058;Ki=0.311051;Kd=65.855247;I get:This seems to be a good explanation of PID and what those coefficients are affecting:https://www.zhinst.com/ch/en/resources/principles-of-pid-controllers

author: mjkuwp
author_rank: Unknown
timestamp: March 07, 2025, 02:15:29 pm
content: a heater is a unique system in that it can only drive in one direction. Because of this, I think it is important to avoid overshoot as you have to wait for natural losses to bring the temperature back down. You can decrease P or increase D; assuming D is arranged that it subtracts from the power when the temperature is rising, which it should be.this is a reference I like:https://www.wescottdesign.com/articles/pid/pidWithoutAPhd.pdf

author: davorin
author_rank: Unknown
timestamp: March 07, 2025, 02:24:48 pm
content: Hmm...that site hasn't a DNS A/AAAA record.I assume this is the same PDF:https://fabacademy.org/2014/students/shooshtari.ali/week16/images/PID-Without-a-PhD.pdf

author: davorin
author_rank: Unknown
timestamp: March 08, 2025, 10:16:02 am
content: Everywhere is documented that a lower Kp causes less overshoot.This is with Kp of 4.4:and this with Kp of 2:So a lower Kp causes more overshoot?

author: davorin
author_rank: Unknown
timestamp: March 08, 2025, 10:44:12 am
content: Okay back to Kp 4.4 and fiddling around with Ki and Kd.Seems not bad for reflow oven with Kp 4.4, Ki 0.02 and Kd 80:

author: voltsandjolts
author_rank: Unknown
timestamp: March 08, 2025, 12:04:03 pm
content: Quote from: mjkuwp on March 07, 2025, 02:15:29 pmYes, so OP can also adjust their system response by way of oven insulation, or lack thereof.If the oven has low loss, then a small vent hole may improve stability, by increased cooling effect.

author: davorin
author_rank: Unknown
timestamp: March 08, 2025, 01:12:40 pm
content: Not actually bad for a second run:

author: MathWizard
author_rank: Super Contributor
timestamp: March 09, 2025, 10:15:49 am
content: I'm just making my 1st PID in LTSpice with a step input, and just an LC tank as the output, and a feed back path. And yeah it's interesting trying to get the P path to oscillate on it's own with the different universal opamps. Now to try and get the other paths to oscillate.Some projects I could try this stuff in are, mod a toaster oven into a reflow oven, motor projects, an electronic load project, and build a better homebrew PSU.So it seems the goal of it is to make your transfer function act like a well behaved 2nd order ODE.

author: Kleinstein
author_rank: Super Contributor
timestamp: March 09, 2025, 04:02:53 pm
content: If it is about following a ramp profile it can help ta have not just the regular, but also give it some feed forward signal. As a simple version something like a term proportional to the ramp rate for a few seconds ahead. This way less settling is needed at the points when the slope changes in the profile.

author: KrudyZ
author_rank: Frequent Contributor
timestamp: March 11, 2025, 04:06:45 am
content: This looks to me like you have a transport lag between the heater and the temperature sensor.The controller doesn't know the actual temperature until some time later which is causing the instability.Try to analyze your setup from first principles and build a thermal model of the system (plant model).Once you have that you can derive a control scheme that compensates for the transport lag.Like others said heaters behave asymmetrically, cooling usually is slower than heating, so you need to account for that as well.

author: davorin
author_rank: Unknown
timestamp: March 11, 2025, 08:19:42 am
content: Well so far it works....just soldered yesterday an ESP32-PICO-MINI-2 for an internet radio project...and runs just fine (o;Just can't use the internal NTC from the Ninja pizza oven as it measures the temperature of the casing.Now just doing the mainboard replacement PCB...and leave the display as it is (o;

author: Kleinstein
author_rank: Super Contributor
timestamp: March 11, 2025, 08:28:22 am
content: The temperature profile looks good enough for reflow. There is anyway some additional delay from the oven temperature to the PCB temperature. If needed on could adjust the profile to get closer at the PCB.Having the original sensor for display and an extra sensor for the modified control is not a bad solution.A bit more enclosure for the SSR part is still a good idea.

author: davorin
author_rank: Unknown
timestamp: March 11, 2025, 08:31:35 am
content: Well the original mainboard uses 3 Triacs for the upper IR tubes and a relay for the lower 3 (they're connected in parallel).So I'm going with optocoupler/triac as well...I also intend to add a better user interface where the different setpoints could be adjusted with the rotary encoder.Some info I already published athttps://github.com/richardklingler/ninjareflow

author: IconicPCB
author_rank: Super Contributor
timestamp: March 12, 2025, 11:19:24 am
content: And now to throw some doubt into the mix.PID algorithm is bad juju in thermal processes in particular the integral coefficient will make the temperature oscillate. The new kid on the block Take Back A Half may prove to be the better algorithm.Seeing as how You have reasonable performance presently try to identify demand signal values at cardinal points along the profile an use that as intermediate set points such that what ever algorithm You use you do not lag with the estimated demand but rather You pull back the demand signal between setpoints which can now be spaced much closer together along the trajectory. To test, see how the oven handles various thermal loads now with the PID algorithm and then try the trajectory approach and see how it responds to various thermal loads.