I have written a program in mikroC that performs the task (PID control algorithm), but the result was not correct. The step response of the system was not as that theoritcally expected
Here is the code
float measured,desired;
float error,kp,ki,ek_1,uk,uk_1,T,ta,k,ts,a,b;
unsigned int uk_o;
unsigned char mV[6];
void main()
{
TRISA=0xFF;
TRISC=0;
TRISD=0;
ADCON1=0x80;
//// First order system parameters and calculation of PI parameters
T=1;
ts=5;
k=1;
ta=10;
kp=5*ta/(k*ts);
ki=5/(k*ts);
ek_1=0;
uk_1=0;
Lcd_init(&PORTB);
lcd_cmd(LCD_CURSOR_OFF);
Lcd_out(1,1,"Desired=");
Lcd_out(2,1,"Measured=");
while(1)
{
desired=Adc_read(0);
measured=Adc_read(1);
//WordTostr(desired,mV);
//Lcd_out(1,9,mV);
//WordTostr(Measured,mV);
//Lcd_out(2,10,mV);
error=(float)((desired-measured)*5000/1024);
uk=kp*error+ki*(error+ek_1)*T; // Positional form of a PI
if(uk>5) uk=5;
if(uk<0) uk=0;
//uk=(uk_1+(kp+ki*T)*error-kp*ek_1); // Velocity form
ek_1=error;
uk_1=uk;
uk_o=(int)(uk*1024/5000);
PORTC=uk_o;
PORTD=uk_o/4;
}
}
and this is a file that represents the circuit diagram
I want to know what is the error