This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Global Var

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

Parents
  • 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;
    }
    

Reply
  • 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;
    }
    

Children