Something like this, starting from the algorithm from the BCS wiki:
Code:
pid_output = pTerm + iTerm - dTerm;
where
pTerm = pGain * err;
iTerm = iGain * iState;
dTerm = dGain * (curr_temp - previous_temp);
The pTerm is simply the difference in the setpoint and actual temperature multiplied by some factor. For example lets say the setpoint is 152 and the actual temperature is 150, and we are using the default gains, the pTerm would = (20 * (152-150)) = 20*2 = 40% duty cycle. The iTerm would = (0.5 * (152-150)) + previous_iTerm = previous_iTerm + 1% duty cycle. Let's forget about the dTerm for the moment.
You can see that the iTerm accumulates. If we started out at a real low temperature or we're climbing slowly, the iTerm *by it self* could grow to 200+% duty cycle or what ever. Lets say our actual temp is now at 153, the pTerm would calculate to (20*-1)=-20% duty cycle but without limits the iTerm could be at +1,000% duty cycle or even higher! In this situation it might take a really long time for the iTerm to come back down to a reasonable level. This is called windup. The integral clamp allows you to set upper and lower bounds to the iTerm and help mitigate windup.
Code:
pid_output = pTerm + iTerm - dTerm;
where
pTerm = pGain * err;
iTerm = iGain * iState;
if iTerm < lower_i_limit then
iTerm = lower_i_limit
else if iTerm > upper_i_limit then
iTerm = upper_i_limit
end if
dTerm = dGain * (curr_temp - previous_temp);