-2

Implementing this pid code that I have, mainly what info I need to pass into the function. There are six variables to pass but I don't really know what to enter. A bit of background, I am automating my home brewery, and although it is all up and running, the temperature control of the RIMs is all over the place. For those not familiar with what a RIMs is, it is a way of ensuring the grains that are being soaked are kept at a very constant temperature. It does this by using a pump and a heating element to heat fluid taken from the bottom of the soaking vessel and passing it past the heating element and heating the fluid as it goes if needed. The code I have running at the moment is dumb so I need to replace it with something more intelligent, like a PID! To heat the heater element Plan on using a simple function called every second that will change the amount of time the element is powered from 100ms to 1000ms depending on how much correction to the temperature is needed.

Ok, so I have the code, its just how to use it! I want to get it up and running in a stand alone windows form project using vb.net. I know I need to play with the PID values so it suits my application, but what to enter to get me started?

Many thanks for any help!

Public Function PID_output(ByVal process As Double, ByVal setpoint As Double, ByVal Gain As Double, _
                        ByVal Integ As Double, ByVal deriv As Double, ByVal deltaT As Double)

 Dim Er As Double
 Dim Derivative As Double
 Dim Proportional As Double
 Static Olderror As Double
 Static Cont As Double
 Static Integral As Double
 Static Limiter_Switch As Double

 Limiter_Switch = 1

 Er = setpoint - process

 If ((Cont >= 1 And Er > 0) Or (Cont <= 0 And Er < 0) Or (Integ >= 9999)) Then
     Limiter_Switch = 0
 Else
     Limiter_Switch = 1
 End If

 Integral = Integral + Gain / Integ * Er * deltaT * Limiter_Switch

 Derivative = Gain * deriv * (Er - Olderror) / deltaT

 Proportional = Gain * Er

 Cont = Proportional + Integral + Derivative
 Olderror = Er

 If (Cont > 1) Then
     Cont = 1
 End If
 If (Cont < 0) Then
     Cont = 0
 End If

Return (Cont)

End Function 
Jonas
  • 121,568
  • 97
  • 310
  • 388
  • In your context PID == [http://en.wikipedia.org/wiki/PID_controller](http://en.wikipedia.org/wiki/PID_controller) not Process Identifier. – Chris O Sep 18 '13 at 18:52
  • Oops. That's probably why there are so many variables to pass? I expect to pass current temp, goal temp, p,I,d and get back a figure to set the heaters power level. – user2791188 Sep 18 '13 at 19:40

1 Answers1

0

Using PID for heating process is a bit trickier than typical PID applications. The reason is; when you need to heat probably you start energizing a heater. The power of that heater is the key to how much energy you can pump into the system so that how fast you can heat it up. However, when it comes to cooling, cooling is normally achieved by the nature of the environment. What I'm trying to say is: the system is not symmetrical.

May I offer you to use different control set according to the "direction" of your control. If the process is cooler than your setpoint, then use controller 1. But, if system is hotter that your setpoint, use controller 2.

For system 1, I definitely advise to use D term because D term is a kind of limiter of how fast your controller is building up the heat on progress. The worry is; many heat control systems have a considerable thermal inertia and lag (delay) of reading back the feedback. This often results in high overshoot (progress is reaching and passing the setpoint with considerable amounts). If exaggerated, will forever oscillate (fluctuate) :)

Also, for cooling effect, say environment is 20deg. Now, if your setpoint is 100 this is something, if your setpoint if 1000 this is totally different. because the Delta T will be different (80 and 980 degrees respectively) and the system response of "trying to get cool" will be a function of Delta T.

Cooling progress is not linear but exponential (like a capacitor discharging over a constant resistor). If your setpoint shall not be changing every day, then you are fine. But if otherwise, you'd better divide your setpoint space into regions and use different controller parameters for different setpoints too.

Where to start: There are different PID tuning thumb of rules. Look at Ziegler Nichols method. But basically, get your progress cool (initial conditions) then give it full throttle heating power and record the time-heat graph. This graph is called step response and will be estimating the thermal inertial and the system lag for you. This will tell you the typical starting PID values when you check Ziegler Nichols method.

Ranger
  • 1
  • 1