Page 1 of 1

PID algorithm for heater control

PostPosted: Wed Sep 17, 2014 1:34 pm
by AlanM
As far as I know every controller out there just switches heaters on and off. On if the temp is below the low set point, off if it's above.

Would anyone be interested in a function for Reef Angel that would use a PID type algorithm to try to keep the temp fixed at a set value instead of working in a sawtooth type pattern where it ramps up, then drops, then ramps up, etc.

It would probably be along the lines of this one: http://playground.arduino.cc/Code/PIDLibrary

I'd also maybe add some sampling and averaging in there for the measured temperature to make it less noisy too.

One consequence would be that it would cycle the heater on and off much more often, adding small amounts of heat to keep it riding around a fixed temp. Would that damage the relays? I think the heaters would be fine with it. In fact it would be better on them if they didn't run full-out for long periods of time.

What do folks think?

Re: PID algorithm for heater control

PostPosted: Wed Sep 17, 2014 2:00 pm
by lnevo
I have a .5 degree hysteresis and yes I get a sawtooth pattern, but I think based on what i read on the link that it would always be the case and that other "unpredictable" variables like outside temperature, evaporation rates, etc would make prediction tricky. It would be cool, I'm interested in seeing if there's a real benefit and would use it for sure if that were the case. The only thing is that my heater beeps when it turns on, so if it beeps too much, I'd have to change back...

Re: PID algorithm for heater control

PostPosted: Wed Sep 17, 2014 2:15 pm
by AlanM
haha. Beep beep beep beep beep beep beep.

I modified my espresso maker for PID control rather than the snap-action button thermostat it was using previously and the PID I used, a Fuji PXR3, had a cycle time of 1 second, so it would cycle the heat on and off each second. Probably not really what you want.

Re: PID algorithm for heater control

PostPosted: Wed Sep 17, 2014 2:43 pm
by rimai
PID is a method to control a variable output and not a relay.
Although you can fake it to use a relay, it would nothing more improved than using a really small hysteresis IMO.

Re: PID algorithm for heater control

PostPosted: Wed Sep 17, 2014 7:18 pm
by AlanM
Right. We used it with the espresso machine on a solid state relay and cycled it on and off. They had a version which did variable output, but we didn't use that one.

Re: PID algorithm for heater control

PostPosted: Thu Sep 18, 2014 4:51 am
by lnevo
How about a variable output controlled heater? Can we do something with PWM or I2C and make a more efficiently controlled heating element?

Re: PID algorithm for heater control

PostPosted: Thu Sep 18, 2014 8:22 am
by rimai
The idea of the "fake" PID that I mentioned above is some sort of PWM variation.
You basically put the heater on a PWM signal, but at a very slow frequency. PWM we use is around 500Hz, which means one pulse every 2ms. If you increase this 2ms to let's say 5s, you would get 0.2Hz PWM signal.
So, the heater would be controlled by a PWM signal at a very slow frequency and thus you can make it so it looks like a variable output.

Re: PID algorithm for heater control

PostPosted: Thu Sep 18, 2014 5:23 pm
by AlanM
rimai wrote:The idea of the "fake" PID that I mentioned above is some sort of PWM variation.
You basically put the heater on a PWM signal, but at a very slow frequency. PWM we use is around 500Hz, which means one pulse every 2ms. If you increase this 2ms to let's say 5s, you would get 0.2Hz PWM signal.
So, the heater would be controlled by a PWM signal at a very slow frequency and thus you can make it so it looks like a variable output.


Yep, that's what my espresso machine did. Longer "pulses" when it called for more of a delta. Actually, PID was good for holding a steady temp, but it really shined when you want to do a delta in temp, like from coffee brewing temp to milk steaming temp, without vastly overshooting the temp you were looking for. It would begin shutting off the heater ahead of reaching the set point so that you would converge on the right temperature quickly.