PID process control theory vs practice

Pandiani

Lifetime Supporting Member
Join Date
Apr 2005
Location
Tz
Posts
718
Hello, guys

I have a coulpe of questions and I hope you'll be able to help me.
I'm a student of electrical engineering and I must admit that it's
very hard for me to understand some things. I had course from
control systems where we learned software MATLAB in which we
simulate control systems and designed PID controllers.
For example if you see picture you can notice that we represent
system with it's transefer function. In theory everything works fine.
However, on the last year of study we learned something about PLC
controllers and also my teacher said that PID controller can also
be designed in STEP 7 (we didn't learn how)
My question is how to represent process (or system) in STEP 7.
I opened example with PID in Step 7 but must admit that mani thing I don't
understand.
For example in MATLAB we have transfer function 1/(s+1) and that transfer
function represent system. In STEP 7 we don't have that representation
I noticed time_lag variables and think that 1/(s+1) can be represent
by setting gain to 1 and time lag to 1 s. Now I can add FB41 for continuous
controll and set P to 1 and 0.5 (1+2/s). I hope I understand that.
I know that most people here are from practice but I hope you can help me.

Can anyone explain why PID is placed in OB35 and how process is simulated with DB100?
I know that this is tough question but I feal that I need a little to understand what is going on.
Is it possible to simulate controller on similar way like in MATLAB (to see response on the step)?

Do you know any good links where I can find explanations how to use PID with STEP7?

I hope someone here will be able to help me.
Thanks
 
Well, yes for example using zero order hold. I can design PID controller in MATLAB where transfer function is given as Laplace transform (for instance 1/(s+1) in continuous domain). However I don't know how to make PID using STEP 7. I suppose that all PID parameters in FB41 in Step 7 are in continuous (s) domain.
However I have only manual about "STEP 7 - PID Control" in which there are very little explanations how to do it practicaly. I assume my input to the controller will be from analog input say PIW 288. Then since it is analog every value will be between 0 and 27684 (or something like this, cannot remember exactly). Now I found that PID is placed in OB 35 and I don't know why. Also there is sample project in STEP 7 PID-Temp, but it's hard for me to understand how process is represented in DB100 and FB100.
If you can clarify this I'll be very grateful.
Like I said, I can do a lot of things using MATLAB. I have set point (step signal), a process with transfer function (say 1/(s+1)) and I simply add PID controller and adjust parameters (in my example PI) controler. But that is only a mathematical fiction. In STEP 7 I need to figure out how to do it in real world, and there are a lot of parameters and Siemen's explanations are very poor.

Thanks
 
Last edited:
I use Step 7 and occasionally program PID loops.
Now, be careful of what I tell you because I have definately picked up some bad habits since I left university.
1, Most PID control I've seen works on the "Suck it and see" theory of control. In this, you setup some random values in your PID controller, and adjust until your control is OK. This is usually fine, but can lead to some trouble.
2, Doug's advanced theory on "Suck it and see". I usually start by disableing the I and D components of the PID control. I then adjust the P component until I get the response that I want. At this point, there is a residual error, so I enable the I component, and add no more than I need to to get a good response. I have never used the D component and found it un-necessary for what I want to do, and too many people completely stuff up this setting, so generally you are better off without it.

I can get away with the above methods, since the plants I work on generally only use PID for simple valve and air damper control. Also, the servo drives I use only come with PI control, so no problem there either.

Now, to step 7.

PLC run on continuous scanning, and will automatically scan as fast as possible. If you change the size of your code, the scan time will change. Also, if you have some sub-routines or use MCR commands, your scan time can change from scan to scan. Digital control theory requires(*) that sampling and control occur at a fixed frequency, therefore classic PLC scanning does not fit well with PID control. For that reason, there has to be some way of fixing the scan frequency. The following methods I have seen adopted by various PLC manufacturers and programmers. All of these methods are available on the S7.
1, Timers, you simply use a timer and fix the period of your control block. This usually only works if you have a low scan time and timers capable of handling the period you want. You then enable the PID block only when the timer is done, and reset the timer after one scan. This can be considered a "Quick and dirty" method, with all the problems associated with quick and dirty methods.
2, Fixed scan times. Some PLCs will allow you to fix the scan time. Naturally, the fixed scan time has to be higher than the free running scan time. This can have a problem if you are mixing process control with machine control, since machine control generally works best with the fastest possible scan time.
3, Interrupt functions. This is what your OB35 is. In this, your standard PLC program is free running, giving you the fastest scan time. At a fixed period, the program is interrupted, and the PID block is scanned. If you have a lot of PID blocks, it is common to work out a scheme for staggering them so that they don't all scan at once and interrupt the free running scan too much.
4, Special PID card, this card has a built in processor and looks after all functions, allowing the PLC to scan normally. The PLC can read and write values to the card, but does not actually do the PID function.

Finally, process transfer functions are supplied by the process itself. If I need to simulate the process on board the PLC, I will generally build it out of the mathematical and control functions available in step 7. Usually I will simulate a transfer function with a "Lag" control block with a time constant roughly approximating that of the bit of equipment I'm simulating.

Hope this helps,

Doug

(*) I have seen some theory that states that the frequency need not be fixed, as long as you can measure the time since the last scan and your functions automatically adjust for the changes in scan. Needles to say, the maths is more complicated and the previously discussed methods work just as well.
 
Last edited:
I understand the confusion.

I don't see the confusion. However there are many forms of PID. PLCs usually use a form that is optimal for slow processes. Most text books use gains instead of time constants.

The documentation sucks. They should say which form of PID they use. It is evident that the integrator and differentiator gains are time constants instead of frequencies. There is also a low pass filter on the differentiator so noise will not be amplified.

Search for the ISA form of PID.
 
Thank you all for replies I'll read it and try to understand.
However my basic problem is that in MATLAB I have process in form of transfer function say 1/(s+1) but in reallity for example if I nedd to maintain a constant level in some tank I don't know the transfer function of that process, so it's trial and error. I don't know how to make step from theory (example PI controller in form: 1 + 2/s is controlling process 1/(s+1) with fedback just like in pictures in attachment). In school we had simple processes, we erote dif. equations and use Laplace transform to get trabsfer function, and then we use MATLAB to design PID controller, but in reallity it's much more complicated.
Is it possible to simulate process 5/(s+5) in STEP 7 and to validate that PID controller is doing the right thing?
For example If I need to simulate process 5/(s+2) is it OK to make func. block and instance datablock with gain 2.5 and time constant 0.5 (5/(2(0.5s+1))). Will that datablock represent process.
Thank you very much for your effort, I'm very grateful
 
Last edited:
Answer My Questions!!!

I hate playing 20 questions and I really hate it when my questions are ignored! Ask specific questions.

Pandiani said:
However my basic problem is that in MATLAB I have process in form of transfer function say 1/(s+1) but in reallity for example if I nedd to maintain a constant level in some tank I don't know the transfer function of that process, so it's trial and error.
I use least squares system identification to identify the system. It provides coefficients ( A and B ) for a difference equation.

y(n) = A1*y(n-1)+A2*y(n-2)+B1*x(n-1)+B2*x(n-2)

This equation is for a two pole system. You must assume the system is linear to use this simple difference equations. I do hydraulic simulations and they are non-linear. This requires solving a system of non-linear differential equations using iterative numerical methods such as Runge-Kutta.

Finding the transfer function for system is the first and most difficult part of auto-tuning.

Pandiani said:
I don't know how to make step from theory (example PI controller in form: 1 + 2/s is controlling process 1/(s+1) with fedback just like in pictures in attachment)
In this case the gain for the PID is 1 and the integrator time constant is .5. The differentiator time constant would be 0 and the differentiator's low pass filter doesn't make any difference but it should be about 10 to 16 shorter than the differentiator's time constant.

Pandiani said:
. In school we had simple processes, we erote dif. equations and use Laplace transform to get trabsfer function, and then we use MATLAB to design PID controller, but in reallity it's much more complicated.
Yes. In reality you don't know the transfer function and if you don't know the transfer function for the system you are tuning you can't compute the gains for the PID. Search for system identification.

Pandiani said:
Is it possible to simulate process 5/(s+5) in STEP 7 and to validate that PID controller is doing the right thing?
Yes. It would take an equation similar to the one above. It may be shorter or longer depending on how many poles it has.

Pandiani said:
For example If I need to simulate process 5/(s+2) is it OK to make func. block and instance datablock with gain 2.5 and time constant 0.5 (5/(2(0.5s+1))). Will that datablock represent process.
YES!!!!! Do you know how to find the transfer function of a unkown system? Do you know how to convert a transfer function in the s domain to the z domain?

See my FTP site.
ftp://ftp.deltacompsys.com/public/PID/
ftp://ftp.deltacompsys.com/public/PDF/
 
Last edited:
Peter Nachtwey said:
I hate playing 20 questions and I really hate it when my questions are ignored! Ask specific questions.

OK, I'm very sorry because you got angry. I apologize.

Peter said:
YES!!!!! Do you know how to find the transfer function of a unkown system? Do you know how to convert a transfer function in the s domain to the z domain?
I don't know how to find the transfer function of unknown system. I'll check your files.
I do know how to convert between s and z domain. For example if process is given in continuous (s) domain with G(s) then, there are couple of ways to convert it to z domain.
1. H(z)= G(s) when s=(z-1)/T (T sampling time)
2. H(z)= G(s) when s =(z-1)/(Tz)
3. H(z)= G(s) when s =2(z-1)/T(z+1) (trapezoidal)
4. H(z)= ((z-1)/z)*Ztransform(invLaplace(G(s)/s))

And I promise I'll try to aske a specific question but please, Peter, try to understand, I don't have a single day experience in practice. In school we use Modern Control Systems (Dorf, Bishop) and most system are given in s domain when design PID controllers. There are very little examples how to describe system with dif equations and then to convert to Laplace transform.

I'l be back with specific question soon, I hope you'll want to help me.

Thanks
 
A little more specific

Okay, let's go step by step.
I have a process that is given with transfer function G(s) = 1/(s+1)
I need to design PI controller C(s) = 1+2/s that is C(s) = (s+2)/s. If I convert this to a z domain (using zoh) I have H(z) = (z-0.8)/(z-1) (sample time is 0.1)
Now first question:
1. Why you asked me if I know to convert to z domain?

I need to design PID controller to control process G(s).
I need to do the following things:
-create FB100 and associated datablock DB100.
Second question:

2.Now are the parameters in s domain or in z?

I think in s domain, because this is a continual process, so in my datablock there will be gain 1 and time constant 1. I think I don't need to convert process transfer function in discrete form.
Next I need to use FB41 (continuous PID) and to create DB 41.
Now there is third question:

3. What parameters to to use with PID?

if I need to use discrete form then H(z) = (z-0.8)/(z-1) will be in form of equation: x(k)-0.8x(k-1) = y(k)-y(k-1) ==> y(k) = y(k-1)+x(k)-0.8x(k-1).
But, If I need to work with continual process and have continuous controll
4. why bothering with conversion to discrete form?

I must admit that I'm little confused because in your last reply you said YES!!!!, on my question about continuous PID, but still asked me if I know how to convert.

Thanks for help, and I'm looking forward to your reply
 
Analog circuits work in the s domain, Digital circuits work in the z domain.

Pandiani said:
1. Why you asked me if I know to convert to z domain?
Computers work in discrete time increments in the z domain, not in the continous s domain. Eventually calculations must be done in the z domain unless you are using analog circuits.

Pandiani said:
2.Now are the parameters in s domain or in z?
The parameters for the PID are s domain parameters. The S7 converts the s domain parameter for use in the difference equation. However, you must realize there are many different forms of PID and your text book may have only exposed you to one.

Pandiani said:
3. What parameters to to use with PID?

K the controller gain
Ti the integrator time constant
Td the derivative time constant
T the control update period.
u(n) is the controller output at scan n.
e(n) is the error between the SP-PV at scan n.

I believe the S7 uses the ISA version of the PID.

u(n) = K * ( e(n) + (Sum e(n))*(T/Ti) + (e(n)-e(n-1))*(Td/T) )

Notice that the integrator and derivative time constants are just another form of gain. Time constants are used with PIDs for slower responding systems.

Your controller 1+2/s has
K=1
Ti=.5
Td=0

The PID controller converts the K, Ti and Td to work in the z domain so you don't have to worry about that.

Pandiani said:
if I need to use discrete form then H(z) = (z-0.8)/(z-1) will be in form of equation: x(k)-0.8x(k-1) = y(k)-y(k-1) ==> y(k) = y(k-1)+x(k)-0.8x(k-1).
But, If I need to work with continual process and have continuous controll
You said your sample time is .1 seconds. Computers can't do continous control, only analog circuits can.

Pandiani said:
4. why bothering with conversion to discrete form?
Because digitial computers work in discrete time increments like you .1 second controller update time. Check this out.
ftp://ftp.deltacompsys.com/public/PDF/Mathcad%20-%20TempPID.pdf

Pandiani said:
I must admit that I'm little confused because in your last reply you said YES!!!!, on my question about continuous PID, but still asked me if I know how to convert.
I can see you are confused. I think I can help you. Write the following 1000 times.

Analog circuits work in the s ( continous ) domain. Digital circuits work in the z ( discrete ) domain.
 
Originally posted by Peter Nachtwey:

I can see you are confused. I think I can help you. Write the following 1000 times.

Analog circuits work in the s ( continous ) domain. Digital circuits work in the z ( discrete ) domain.

Ouch!!!


I think Pandiani is suffering from information overload. When he first posted this question I thought he was trying to design a discrete time controller using 'native' function in the S7 (add, sutract, multiply, divide). It now appears he wants to figure out how to use FB100. That is a different thing.

However, it is important to realize early that digital filter implementations work in the z domain. That could save much heartache later.

Keith
 
kamenges said:
Ouch!!!
I think Pandiani is suffering from information overload.
I think it is a matter of understanding enough to ask the right questions.

kamenges said:
When he first posted this question I thought he was trying to design a discrete time controller using 'native' function in the S7 (add, sutract, multiply, divide).
Me too. It would be easy enough. The S7 makes it easy to roll your own and you can roll exactly the right PID for the application. I don't think I would mess with the S7 PID. I must also agree that there isn't much help in the on-line help for FB41. The descriptions are short and there is no formula showing how the PID works.

A student may only be exposed to one form of PID. Seeing a PID that uses timeconstants instead of gains may be confusing.

BTW, a PID should only require multiply and adds.

u(n) = u(n-1)+K0*e(n)+K1*e(n-1)+K2*e(n-2)

The trick to compute the constants K0,K1 and K2. To be proper one should limit the output.

u(n) = max(min(u(n-1)+K0*e(n)+K1*e(n-1)+K2*e(n-2),100%),-100%)

kamenges said:
It now appears he wants to figure out how to use FB100. That is a different thing.
I don't know what FB100 is. I will have to look.
 
Thank you all for replies. I very appreciate your effort, and I must say that I learned a lot on this forum. I agree that I asked to many questions in the same time, and in the end I din't know what I wanted to know in the first place. My original intention was to learn how to set up PID controller using FB41 in SIMATIC STEP 7. I played with MATLAB where I had a process with transfer function G(s)=1/(s+1) and I added PI controller to make sure that steady state error is zero and that I have good response time (with little overshoot). Then I start wondering how the same thing could be done in STEP 7, and all problems begun. I will try to make simple STEP 7 project in which I'll make PI controller and I'll try to simulate process G(s) to see if this controller is doing the right thing. It will take some time to do that, but I intend to return to the forum and post (or send to someone) STEP 7 project for your evalution.
Is that OK?
Thanks
 
Last edited:
Pandiani-

Your posts are certainly welcome. However, there is something to keep in mind about this and any other forum. It is very hard to reduce the content of a year-long class into a few posts on any forum. Forums work very well with very specific questions (Where do I enter the integration time value in FB41?) but not so well with open-ended concept questions (Why do PID filters work?).

I agree with your plan to write your own PI controller in Step7. For your purposes it will be more educational. As Doug_Adam said back in the fourth post you want to use OB35 to trigger your PI controller function block. OB35 is run on a strict interrupt time adjustable through the S7 processor setup screens. You will want the controller to run on a fixed time or your filter constants won't mean anything. Also, remember to convert from the s domain to the z domain after your design analysis is done. If you don't do that to normalize to the update time of OB35, again, your filter constants won't mean much.

Keep us updated.

Keith
 

Similar Topics

I am currently trying to implement a process control of the temperature of water going down a drain after it has gone through 2 radiators. I have...
Replies
6
Views
1,939
Good morning, I have a question and I don't really know what you would call this.... I have 2 tanks which I need to control the level or froth...
Replies
14
Views
7,732
Hello, I have got the following process I’m trying to control. I have a PID controller module purchased from the manufacture –...
Replies
7
Views
7,312
Hello guys. I have another interesting application, and I'd like some suggestions. What I need to achieve is a steady level at the height of a...
Replies
19
Views
9,323
Hi all, I'm working on a wastewater plant with oxidation ditch aerators. The aerators are on VFDs and the operators want the dissolved oxygen in...
Replies
45
Views
17,412
Back
Top Bottom