PID Code

Steve_D

Member
Join Date
Jul 2002
Location
Albury/Wodonga
Posts
92
Guys, no, Im not a uni student wanting to get my homework done but I also don't like to waste time (and refining) reinventing the wheel. So if any one can point me to a block of ladder code that does a basic PID loop (D not necessary)that would be great. The RTU I am programming has very limited capabilities and PID was an "option" but when pressed for it they admitted they didn't actually have one.
Its just to regulate a pump speed at a flow rate so it doesn't have to be too flash.
Thanks in advance.
 
Here you are:
This is my approach, in this case the pump has fixed speed 1750 rpm, flow is controlled by a control valve ( salida valvula), flow is measured thru an endress&hauser coriolis flowmeter ( flujo aceite), SP is 18000 kg per hour.
My P, I nad D values are : 0.21, 3.1 and 0 respectively.

In your case values may be different.

pide_flow.jpg
 
In my opinion you would be better off scrapping the PLC that doesn't suit your needs and replacing it with one that does. Unless you place a very low value on your time, the cost to write and debug ladder logic to act like a PID function block could easily exceed the the cost of hardware replacement.
 
Steve.
Even if your PLC doesn't do PID the drive might. I would check that there is not a built in PI or PID function in the drive you could use.
 
There are dozens of commercial, stand alone, single loop PID controllers, even a DIN rail mount version or two that could be used.
 
Guys, no, Im not a uni student wanting to get my homework done but I also don't like to waste time (and refining) reinventing the wheel. So if any one can point me to a block of ladder code that does a basic PID loop (D not necessary)that would be great. The RTU I am programming has very limited capabilities and PID was an "option" but when pressed for it they admitted they didn't actually have one.
Its just to regulate a pump speed at a flow rate so it doesn't have to be too flash.
Thanks in advance.

First, to answer your question, see this thread: http://forums.mrplc.com/index.php?showtopic=12208

It contains a PID I wrote in C many many years ago for an embedded controller. Its crude and I would do it much differently now, but it may help you to understand what you need to do to construct one of your own.

Second, how much is the customer willing to spend to pay you to program a PID from scratch in an inadequate controller -vs- spending for a controller with the PID instruction built in?
 
Some basic PID code from the web:
From http://en.wikipedia.org/wiki/PID_controller#Pseudocode:
previous_error = 0
integral = 0
start:
error = setpoint - actual_position
integral = integral + error*dt
derivative = (error - previous_error)/dt
output = Kp*error + Ki*integral + Kd*derivative
previous_error = error
wait(dt)
goto start

and from http://www.embedded.com/2000/0010/0010feat3.htm:

typedef struct
{
double dState; // Last position input
double iState; // Integrator state
double iMax, iMin;
// Maximum and minimum allowable integrator state
double iGain, // integral gain
pGain, // proportional gain
dGain; // derivative gain
} SPid;
double UpdatePID(SPid * pid, double error, double position)
{
double pTerm,
dTerm, iTerm;
pTerm = pid->pGain * error;
// calculate the proportional term
// calculate the integral state with appropriate limiting
pid->iState += error;
if (pid->iState > pid->iMax) pid->iState = pid->iMax;
else if (pid->iState
<
pid->iMin) pid->iState = pid->iMin;
iTerm = pid->iGain * iState; // calculate the integral term
dTerm = pid->dGain * (position - pid->dState);
pid->dState = position;
return pTerm + iTerm - dTerm;
}
 
Thanks Guys, unfortunately the device is a Radio Tranmission Unit that had very limited functionality, but thats what the client wants.
I appreciate all your help, thanks again!
 

Similar Topics

How can I test some PID code I have written for a SLC-500 in RSLogix500, without having an actual processor to test on. I have used Emulate500 to...
Replies
3
Views
1,846
I'm on site at a customer's facility. We're using solid-state relays to control heaters in two halves of a manifold and a heated hose supplying...
Replies
14
Views
4,240
If anyone could help it would be appreicated....Thanks....
Replies
0
Views
2,756
Hi Iam learning programing PID on rslogix5000 rev 20. Someone have any program example that have a PID temperature control loop using analog...
Replies
1
Views
1,619
Hello all, working on my first adventure into PIDs, done a lot of searching, learned alot, and now I would like you to check my logic to make sure...
Replies
5
Views
3,870
Back
Top Bottom