# Writing Code for PID Control - I Term?

I'm currently working on writing PID control code for the first time. The application is temperature control.

I'm not sure how to implement the I term, which is supposed to be the sum of the error over time * I gain. This makes the I term huge and ever growing, which doesn't seem correct.

I fixed this by creating an array of the last 10 errors, then take an average of that...

Am I on the right track? It does seem to be working correctly if I simply calculate out the terms.

vristang: This makes the I term huge...

Not necessarily.

...and ever growing

Correct. Assuming the PV does not change in a timely manner relative to the I term.

The key word you will need for Google is "anti-windup".

I fixed this by creating an array of the last 10 errors, then take an average of that... Am I on the right track?

I vaguely recall that averaging can be performed to take the edge off adjustments from the D term but I don't recall anyone using averaging for anti-windup.

Sounds a bit like you have the I term too large.

thanks for the response.

My application is a fairly slow to respond temperature system. As such, it looks like I will be pretty large, until feedback overshoots significantly... The I-gain setting/parameter I'm using (adjustable by the end user), is set to 1/10th the value of P-gain... which is inline with what I have used as an operator on other PID systems.

I'll do a little more digging using the term anti-windup...

Below is a response I posted in another conversation, so I figured I would paste it in here... might help clarify what I am trying to do.

When I activate the system the temp is approximately room Temp, and command temp is approximately -50F. As the cooling system forces the temperature down, the error decreases.

Here is how I am currently calculating terms for P, I, and D.

Error = Command Temp - Current Temp IState = Average of last 10 Error values MaxTimeOn = Operator defined parameter specifies max time to allow cooling system activation before recalculating on time again.

P = pgain * (Error) I = igain * IState D = dgain * (LastError - Current Temp)

I then calculate cooling system ON time as follows... PIDValue = P + I - D OnTime = PIDValue * MaxTimeOn

I'm comfortable with the P and D calculations, I just don't know about the I calculation.

From the wiki page on integral windup http://en.wikipedia.org/wiki/Integral_windup:

This problem can be addressed by: Initialising the controller integral to a desired value Increasing the setpoint in a suitable ramp Disabling the integral function until the to-be-controlled process variable (PV) has entered the controllable region Preventing the integral term from accumulating above or below pre-determined bounds

I had found the above reference to wiki...

However, I decided to try the rolling average method I described above.

So far, it seems to be working well in my application.