HI!!
I declared 3 global var, i call it inside diferent task and every execution this var should be updates but not to do it. I have a 8051 under evaluation board. Maybe can be a problem of my small micro? What do u think about this?
Thanks
I see some serious problems with your implementation. I think your integrator is totally wrong - you do not even accumulate the error! it should be something like this:
double UpdatePID(SPid * pid, double error, double position) { double pTerm, dTerm, iTerm; pTerm = pid->pGain * error; // calculate the proportional term // calculate the integral state with limiting pid->iState += error; if (pid->iState > pid->iMax) pid->iState = pid->iMax; else if (pid->iState < pid->iMin) { pid->iState = pid->iMin; iTerm = pid->iGain * iState; } dTerm = pid->dGain * (position - pid->dState); pid->dState = position; return pTerm + iTerm - dTerm; }
sorry, you do accumulate the error but I still think your implementation is not correct.
Thanks for your reply. But i think that the problem is not the implementation because is a simple acumulate. I dont understand why this var not acumulate the old value.