Proportional-Integral-Derivative controller(PID) on a Programable Logic Controller (PLC)
Proportional-Integral-Derivative controller (PID controller) is being implemented
digitally on a programmable logic Controller (PLC) considering that the input is
digital and the output is digital thus the continues signal from the transmitter is
sampled and converted periodically to a digital signal after that the digital PID takes
that digital input and control the behavior of the system using mathematical operations
rather than the continues method of relays and Op Amps.
This project was developed for my control course, where I designed a program to implement the PID
controller and generate the optimum gains for P, I, and D according to the system transfer function.
I have designed a program that mimic the operation of PLC on matlab and tested my program on it.
the results where fasinating.
3D simulation for the project
Programs Used
MatLab, STEP7 PLC Simulator
Line of code
Ladder Code that is to be placed in the PLC
network 1
////Initiating variables
////e0_C=vd110
////e1_C=vd120
////d2_C=vd130
LDN M0.0
MOVR 0.438583, VD110
MOVR 0.438384, VD120
MOVR 0.0, VD130
//////this branch is to move the input from the input register into our predefined register VD210
/////so replace WWWWWW by the input address.
LDN WWWWWWWWWW
MOVR VD3, VD210
LDN T34
MOVR VD110, VD310
*R VD210, VD310
MOVR VD120, VD320
*R VD220, VD320
MOVR VD130, VD330
*R VD230, VD330
LDN T35
+R VD320, VD310
+R VD330, VD310
MOVR VD310, VD200
+R VD190, VD200
LDN T36
MOVR VD120, VD130
MOVR VD110, VD120
MOVR VD200, VD190
LD T33
= M0.0
Mimic PLC
%sampleing parameters
dt=0.05;
t=0:dt:70;
ut=2;
%PID parameters
KP=0.438484;
KI=0.004;
KD=0;
%PID filter coffeciants
e2_C = (KD/dt);
e1_C = (KP+((2*KD)/dt)-((KI*dt)/2));
e0_C = (KP+((KI*dt)/2)+((KD)/dt));
%PID input IC
e2=0;e1=0;e0=0;
%PID output IC
m1=0;m0=0;
%Output Plant IC
w3=0;w2=0;w1=0;w0=0;wv=0;
%input Plant IC
a3=0;a2=0;a1=0;a0=0;
for i=1:1:(t(end)/dt)+1
e0 = ut - w0;
m0 = e2_C*e2 - e1_C*e1 +e0_C*e0 + m1;
a0 = m0;
w0 = 3.723e-5*a3+1.5466e-4*a2 + 4.014e-5*a1 + 0.8606*w3 - 2.7166*w2 + 2.856*w1;
w3=w2;w2=w1;w1=w0;
a3=a2;a2=a1;a1=a0;
e2=e1;e1=e0;
m1=m0;
y(i)=w0;
end
plot(t,y)