Thursday, August 8, 2013

tuning PID for arduino sousvide

Often I came across people asking me on how to tune a PID setup. The setup I come across are mostly to regulate temperature, but with very different heating appliances. It really took me sometime to do the step by step on tuning and the process can be quite tedious. No 2 home made sous vide cooker are the same. Using the exact same setup as another with the exact same PID values the end results maybe vary. Hence, tuning is required.

Recently i came across the PID auto tune library on the arduino website. It is a nifty library to help to tune the PID with a command send via serial line, wait for some period of time (mine took 4 hours and still counting), then the auto tune will return 3 parameters: P , I and D that are suitable for controlling the close loop system at hand. I have used the auto tune with my arduino sous vide setup, code is attach at the footer. Then it strikes me, why not just tune by hand. PID controller is not that difficult, as compared to the kalman filter AKA LQE (linear quadratic estimation) type of control system.

This links provide some details of the PID and demonstrates Zigler-Nichols method for tuning PID. Tuning by blindly guessing the P, I, D parameters,  can be quite difficult and unnecessarily tedious. I am interested on the how to tune by hand by observing the characteristic unknown system. A few PID features to bear in mind that gives a good close loop control. 0. the set point 1. the rise time, 2. the time to settle, 3. the error rate/compensation; that correspond one way or the other to the P, I and D parameters. 

What we want in our sous vide is a fast rise time to the set point, e.g rise to the ideal temperature quickly; fast settling time, e,g the temperature do not fluctuates too much when approaching the set point. As a general guide line, an increase of P value will decrease the rise time; an increase of D value will decrease the settling time. Sounds good isn't it? At some point, I would ponder. is PID is really needed for the sous vide or a PD is generally sufficient?? As for increasing the I value, the error rate will decrease.

So, where to start tuning? Before starting to throw in random values into the code and spent the next few days trying to find the perfect value, let's make some educated inferences.

firstly, take note of the heating characteristic of your cooking vessel. I am using a slow cooker that comes with a ceramic pot. One particular characteristic of the slow cooker. The heat is dissipated slowly; the reverse is true to. heat is accumulated slowly. This feature is really forgiving for sous vide cooking since what we need is actually to maintain the temperature at a certain point and hopefully it will hold at +- 1degC precision.

I observed my slow cooker on full power to heat up would take 25secs per 0.1degC or 1min 0.24degC or 5min 1degC. This means that if I randomly enter a very large P value it will still take 5 mins to heat up 1degC, but the reverse of this; turning off the power for 5 minutes will lose 1degC is not true.. As compared to a setup that uses heating coils; randomly throwing in a very large P value will have an effect that is devastating for the sous vide. slow cooker is much forgiving with large P value than the heating coil. Dissipation of heat is affected by room temperature, cold room heat dissipate faster.

Next few paratemers, the time taken to settle, amount over shooting the set point, and error recovery. this 3 parameters are different, but somewhat related to the input parameter. If the input device is not reliable with values read in fluctuates wildly, no amount of tuning can save that. So, it is very important to ensure that the temperature acquisition device is constantly stable for a reliable PID tuning. temperature reading with precision of 1 decimal places is good enough for PID used in sous vide cooking. The precision will affect the computation of the error rate.

Here comes the tuning by hand modus operandi
Set a large P value lets say 500, a very small I value let say 1 and choose a mid value for D let say 100. Observe the time taken to reach the set point. Observe the amount of degC overshoot from the setpoint and also observe how long it takes to throttle (turning on and off of the SSR) the current, finally observe how long it takes to settle at the set point.  Always start with P value. If it takes very long to reach set point, increase P. then the D value. If it takes very long (i have decided +- 1degC for more than 5 minutes is very long; using the observation mentioned above) to settle at the set point, increase the D value. For a PID to settle within 1second time frame with my slow cooker setup is unrealistic and difficult to achieve. Finally the I value. If it overshoots by a large amount before throttling of current occur, increase I. Repeat this process until a satisfactory result is obtain.

Happy pouring cold water into the vessel, observe the temperature changes and modifying the P, I, D parameters.

2 comments:

Emmanuel Babu said...

hi

im building a dc-dc converter id llike to implementautotune...on arduino...can you please help me with the coding for the PID only...ive done the rest??

Emmanuel Babu said...

hi awaiting ur reply...