Controllo PID

Non sn stato a riportare tutte le variabili, ma solo la funzione che calcola il PID. stampa a video solo il valore 100 e un altro valore che tende ad aumentare fino a che raggiunge il limite 255 e dopo questa cosa si alternano infiniti 100 con qualche 255 in mezzo. Che cosa sto combinando?

unsigned long lastTime;
int SampleTime=100; //0.1 sec

int updatePid(float mySetpoint, float x){

   unsigned long now = millis();
   
   unsigned long timeChange = (now - lastTime);
   if(timeChange>=SampleTime)
   {
      /*Compute all the working error variables*/
      float error = mySetpoint - x;
      ITerm+= (ki * error);
      float dInput = (x - lastInput);
 
      /*Compute PID Output*/
      int output =kp * error + ITerm- kd * dInput;
      	  
      /*Remember some variables for next time*/
      lastInput = x;
      lastTime = now;

                
                //if( vel >= 255/2 )  vel = 255/2;        // in fase di test  
                if(output>=245){output=255;}        
                if(output>=255){output=255;}
                if(output<=0)  {output=0;}
                if(output <= 5 && output > 0) {vel = 0;}
                return output;
   }}
100
100
100
100
100
100
100
100
44
100
100
100
100
100
100
100
100
125
100
100
100
100
100
100
100
100
129
100
100
100
100
100
100
100
100
132
100
100
100
100
100
100
100
100
135
100
100
100
100
100
100
100
100
138