Beruflich Dokumente
Kultur Dokumente
2013
AIM
To implement the digital PID algorithm on a plant model using Turbo C and MATLAB.
REQUIREMENT(S)
1. MATLAB. 2. Turbo C Compiler. 3. Personal Computer.
THEORY
A proportional-integral-derivative controller (PID) is a generic control loop controller widely used in industrial control systems. A PID is the most commonly used feedback controller. A PID controller calculates an error value as the difference between a measured process variable and a desired set point. The controller attempts to minimize the error by adjusting the process control inputs. The PID controller algorithm involves three separate constant parameters, and is accordingly sometimes called three-term control: the proportional (P), the integral (I) and derivative (D). Heuristically these values can be interpreted in terms of time. P depends on the present error, I on the accumulation of past errors and D is a prediction of future errors, based on current rate of change. The weighted sum of these three actions is used to adjust the process via a control element called actuators which will vary depending on the application.
The PID control scheme is named after its three correcting terms, whose sum constitutes the manipulated variable (MV). The proportional, integral and derivative terms are summed to calculate the output of the PID controller. Defining u(t) as the controller output, the final form of the PID algorithm is
d dt
e(t)
(1)
Digital PID controller can be written in two ways as, 1. Position form. 2. Velocity form. Position form of PID controller The controller algorithm for position form of PID controller is given by,
u(n) = K p e(n) +
Kp Ts Ti
n i=0 e(i) +
Kp Td (e(n)e(n1)) Ts
+ u0
(2)
Velocity form of PID controller The controller algorithm for velocity form of PID controller is given by,
K p Ts e(n) Ti (3)
PROGRAM
1. MATLAB Coding to Create and Discretize the Transfer Function clc close all; clear all; num=5.009; den=[1 0.895 5.009]; sys=tf(num,den) dis=c2d(sys,0.3,'tustin') %continuous to discrete
2. Main program code (main.c) in Turbo C complier #include<stdio.h> #include<conio.h> #include"openloop.c" #include"input.c" #include"velocit.c" void main() { clrscr(); printf("\nPID CONTROLLER IMPLEMENTATION VELOCITY FORM"); printf("\n\t\t\t\t1.OPEN LOOP RESPONSE"); openloop(); printf("\n\t\t\t2.CLOSED LOOP RESPONSE"); input(); closedloop(); getch(); }
3. Sub program code (openloop.c) in Turbo C complier #include<stdio.h> #include<conio.h> FILE *z1; struct prog { int ref[500]; double h[500],g[500]; float t; }j; void openloop() { int n; j.h[2]=j.h[1]=j.h[0]=0; j.t=0.24; z1=fopen("OPPX","w"); for(n=0;n<500;n++) { } for(n=2;n<500;n++) { j.g[n]=(0.09038*j.ref[n])+(0.1808*j.ref[n-1])+(0.09038*j.ref[n-2]); j.h[n]=j.g[n]+(1.423*j.h[n-1])-(0.7847*j.h[n-2]); } for(n=0;n<500;n++) { printf("\n"); printf("%f",j.h[n]); fprintf(z1,"%f",j.h[n]); fprintf(z1,"\n"); } fclose(z1); } j.ref[n]=1;
10
4. Sub program code (input.c) in Turbo C complier #include<stdio.h> #include<conio.h> struct input {int r,ref[500]; double h[500],c[500],u[500],e[500],g[500]; float kp,ti,td,t; }k1; void input() { printf("\n Enter kp Value : "); scanf("\n %f",&k1.kp); printf("\n Enter Ti Value : "); scanf("\n %f",&k1.ti); printf("\n Enter Td value : "); scanf("\n %f",&k1.td); } 5. Sub program code (VEL.CPP) in Turbo C complier #include<stdio.h> #include<conio.h> FILE *z2; void closedloop() { int n; k1.r=1; k1.t=.24; z2=fopen("VELLX","w"); for(n=2;n<500;n++) { k1.c[n]=k1.h[n-1]; k1.e[n]=k1.r-k1.c[n]; k1.u[n]=k1.u[n-1]+(k1.kp*(1+(k1.t/k1.ti)+(k1.td/j.t))*k1.e[n])((k1.kp*(1+(2*k1.td)/j.t))*k1.e[n-1]+((k1.kp*(k1.td/k1.t))*k1.e[n-2])); k1.g[n]=(0.09038*k1.u[n])+(0.1808*k1.u[n-1])+(0.09038*k1.u[n-2]); k1.h[n]=k1.g[n]+(1.423*k1.h[n-1])-(0.7847*k1.h[n-2]);
11
SIMULATION RESPONSE:
1.5
0.5
50
100
150
200
250
300
350
400
450
500
TIME (sec)
12
} printf("\n"); for(n=0;n<500;n++) { printf("\n"); printf("%f",k1.h[n]); } for(n=0;n<500;n++) { fprintf(z2,"%f",k1.h[n]); fprintf(z2,"\n"); } fclose(z2); } 6. MATLAB coding to read the file from Turbo C compiler and Plot the response clc close all; clear all; load C:\TurboC++\Disk\TurboC3\BIN\oppx; figure(1) plot(oppx) title('OPEN LOOP RESPONSE','FontSize',16,'FontName','Times New Roman'); % Create title xlabel('TIME (sec)','FontSize',14,'FontName','Times New Roman'); % Create xlabel % Create ylabel
title('CLOSED LOOP RESPONSE','FontSize',16,'FontName','Times New Roman');% Create title xlabel('TIME (sec)','FontSize',14,'FontName','Times New Roman'); % Create xlabel ylabel('SYSTEM OUTPUT','FontSize',14,'FontName','Times New Roman'); % Create ylabel
13
50
100
150
200
250
300
350
400
450
500
TIME (sec)
Fig.3. Closed Loop Response of the Second Order System
14
OUTPUT
Transfer function of second order under damped system [2] on page no. 36.
INFERENCES
1. A second order system with complex poles is always a under damped system 2. By tuning the controller parameters, the peak overshoot is eliminated in closed loop system.
REFERENCE
[1] Katsuhiko Ogata, Modern Control Engineering, Prentice Hall of India, Fourth Edition, New Delhi, 2002. [2] Jing-Chung Shen, New tuning method for pid control of a plant with Under-damped response, Asian Journal of Control, Vol. 2, No. 1, pp. 31-41, March 2000. [3] http://issuu.com/xcelljournal/docs/xcell_journal_issue_81/38 [4] www.xilinx.com/support/documentation/application.../xapp1163.pdf
RESULT
Thus a digital PID controller is implemented on a plant model using Turbo C complier and MATLAB.
15