diff -r e2766e538d0e -r e00f8ff4de9a thermferm/pid.c --- a/thermferm/pid.c Mon Nov 04 13:19:27 2019 +0100 +++ b/thermferm/pid.c Sat Apr 25 20:31:31 2020 +0200 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2015..2016 + * Copyright (C) 2015..2020 * * Michiel Broek * @@ -41,26 +41,26 @@ { if (pid->Mode == PID_MODE_AUTO) { - double dTerm; + double dInput; if (pid->Type == PID_TYPE_HEAT) pid->Err = pid->SetP - pid->Input; else pid->Err = pid->Input - pid->SetP; + dInput = (pid->Input - pid->InputLast); + /* * Calculate the integral state with appopriate limiting. - * Use ErrLastLast as iState */ pid->iState += (pid->iGain * pid->Err); + pid->iState -= (pid->pGain * dInput); // Add Proportional on Measurement if (pid->iState > pid->iMax) pid->iState = pid->iMax; else if (pid->iState < 0) pid->iState = 0; - dTerm = (pid->Input - pid->InputLast); - - pid->OutP = (pid->pGain * pid->Err) + pid->iState - (pid->dGain * dTerm); + pid->OutP = pid->iState - pid->dGain * dInput; pid->InputLast = pid->Input; } else if (pid->Mode == PID_MODE_BOO) {