Hi Sir,
This is my PID loop.#define dt 0 //100ms loop time
#define Kp 0.5
#define Kd 0.0
#define Ki 0.0//0.0005
static float pre_error = 0;
static float integral = 0;
float error;
float derivative;
float output;
void PID (float setpoint,float actual_position)
{
//Caculate P,I,D
error = (actual_position-setpoint);
//In case of error too small then stop intergration
if(abs(error) > epsilon)
{
integral = integral + error*dt;
}
derivative = (error - pre_error)/dt;
output = Kp*error + Ki*integral + Kd*derivative;
//Saturation Filter
output = ( output < 0) ? 0: output;
output = ( output > 100) ? 100: output;
//Update error
pre_error =error;
PWM_change(output);
USART_Transmit_String("\r\nADC=,");
convert(actual_position); // ADC value
USART_Transmit_String(",PID=,");
convert(output); // PID output
}
I have used Single hall effect sensor. How can I tune my PID ? I think 0.5 proportional gain is constant to get 0 to 40 % duty cycle. My Ton + Toff =0.12 ms .Whats i do to tuning my PID.
thanks in advance