Demo entry 6640173

speed_PI_control

   

Submitted by anonymous on Sep 11, 2017 at 16:40
Language: C. Code size: 408 Bytes.

int speed_control(int Encoder,int Target)	//input encoder_value and set_target 
{  
	static int Bias,Pwm,Integral;
  Bias=Target-Encoder; 
	if(Flag_Stop==1)	//if Motor not running, Integral will reset.
		Integral=0;
	else	
	Integral+=Bias;
  if(Integral>1000)  	Integral=1000;          // Integral limit
  if(Integral<-1000)	Integral=-1000;
  Pwm=(int)(kp*Bias)+(int)(ki*Integral);
	return Pwm;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).