# Tuning PID (Arduino pid, full HLT volume).



## mr_wibble (18/8/14)

So ... I've built this nifty little HLT controller.

Plugged into a domestic kettle it rises quickly to temperature, and holds it within ±0.5°C. Everything is awesome, would make a great Hx.

But with a 40 litre hot water talk, and a Keg King 2400 (2200?) watt element, it never quite reaches set temperature... always sitting a couple of degrees below.

I tried the autotune library ... it just produced stupid values after 20 minutes of running.

Does anyone think that maybe I could manually tune it ... but how do you know when it's reaching oscillation point?
That could take fricken hours ... so long that probably the ambient temperatures might come into play.

Currently: Kp = 500, Ki = 0, Kd = 0.45

I wonder if insulating the tank would help it push up to the actual set-point ... ?

Ideas?


----------



## dblunn (18/8/14)

Hi, with proportional only control there is always a small error, this error value drives the output. So to correct for the small error you add an integrating term (the I in PID) which over time removes the error caused by the P term. Your values have Ki set to 0, that could be your problem. Also, big a Kp term make it more unstable (oscillates) so maybe tone the Kp down a bit too. The differential term (Kd) comes into play with fast acting systems, heating water is usually pretty slow so this term is not so important.
Dave


----------



## gc.camel (19/8/14)

Is the output on 100% and it's failing to reach the setpoint? Is there enough power in the heating element to get to your setpoint?

Insulating the vessel will help with heat loss and speed up the rate of warming up the tank.

I use the Ziegler Nichols Method to tune PIDs. Very easy if you can plot the temperature. Otherwise you need to sit and watch with a pen and paper!

http://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method

Essentially you zero the I and the D and change the P until the oscillation peaks are constant. This 'ultimate' value of P can then be used to derive your P,I,D values.

The only downside, as mentioned above, water can be incredibly slow. You have to wait for it to heat up and cool down several times. You could be there all day!

Cheers


----------



## SBOB (19/8/14)

Good ol PID tuning.. its a dark art 

Going on the two previous comments i would first
- ensure it actually reaches a setpoint when outputting at 100% .. no point trying to tune it if the issue is it cant reach the temp
- start with some numbers that are more easily 'scale-able' and for tuning.. So something like Kp=100,Ki=0.01,Kd=0.1, and go from there..then you can see what it does and make an 'educated' decision about which term needs adjusting and move it by some standard factor (e.g. Kp is too low and its acting to slowly, bump it to Kp=200 and monitor changes)..
(this assumes you want to just get 'close enough is good enough', otherwise you will need to do something like gc.camel's suggestion and that isnt a quick exercise  )


----------



## mr_wibble (19/8/14)

Thanks for the tips.

It manages to get to temperature no problem.
I was running it manually, and forgot about it, went to sparge and the HLT was at 87C and rising.

I'll sit down with it over the weekend and try to plot it out.
(or make a data logger)


----------



## 431neb (8/11/14)

I've had less accurate mash temps with my setup too. I'm running a keg king element in the MLT under a falsie and controlling it with a Sestos PID. After resetting all the values back to the factory settings and running the following….

Ctrl = 3
run = 1
ctl <= 4
CF = 2

( as described by QldKev here http://aussiehomebrewer.com/topic/69850-sestos-pid/ )

…and autotuning 40 l of water, I was getting swings of a few degrees in the mash that followed.

I can't be bothered diagnosing why. All the parameters confuse the shit outta me.


----------



## Mardoo (8/11/14)

gc.camel said:


> The only downside, as mentioned above, water can be incredibly slow. You have to wait for it to heat up and cool down several times. You could be there all day!


Does this need to be done with the volume you wish to control? Could it be done with, say, 2 liters to speed things up? I'm only just learning about PID's, so if you could talk loud and slow I'd appreciate it


----------



## mr_wibble (10/11/14)

No I don't think so, because the rate of change on 2 litres of water is not the same as on 10/20/40... etc. The whole point of the PID algorithm is to watch the error margin on the rate of change, and then act accordingly.

Working on a kettle-sized tank, my controller worked perfectly (2 litres), but on 40 it never gets to final temperature.

Recently I used my controller to sous-vide cook pork knuckles for 8 hours. With the HLT wrapped in a heavy cotton doonah(sp?) it did get within range after *some* hours.

I say *some* hours, because I only checked it in the last 6 hours or so. I ended up just setting it to 77C rather than 75C. It was at 75C in 1/2 an hour, and stayed there.


----------

