PID block algorithm in Simatic ?

sigreg

Member
Join Date
Oct 2006
Location
Silesia
Posts
5
Good day,

Im a young engineer with only 5 months experience, so forgive me please eventual "funny" questions.
In last month i did some automation system, task was not thought - a tank with one inlet is filling continously tank with water, a pump with frequency converter is a "outlet". Main task is to keep water level stable in case of inlet flow change. Of course i have level measuring devices and flowmeters, so algorithm was not too complicated and one build-in PID (cont_c) is working very well. PLC had to do some other tasks with many digital and analog I/O's so we used a S7-300 station.

But as we know, college "knowledge" is not full, and real school starts when we do start work, so i would like use this simple object for some experiments - mostly in matter of PID regulation. Just want to try other regulation methods in case of extremally fast inlet flow changes, or flow measuring disturbances.
I did in MATLAB a mathematical model of this object. One tank (perfect integrator), one pump (inertial object) and a PID. Im treating measuring devices as "perfect" in mean not having influence for regulation process. My mathematical pump is acting like real one - answering with flow changes for 0-100 signal calculated by PID. And now i have problem ... how to simulate Simatic CONT_C PID algorithm ? Build-in MATLAB PID is quite nice, but calculating outlet signal as normal floating flow numbers without any limits. Other thing is that i have Siemens manual with drawning how CONT_C PID works, but theres no details how exacly inegrate and derivate parts do work, and how calculated value is transformed to 0-100% PID outlet signal. Know anybody how to solve this problem to get full mathematical model of complete real object ?

Thank you in advance
Greg
 
No, not sure how it works, but one little snippet is if you put negative number in p band it works as reverse acting controller (not very useful to you but it's woth knowing).
 
Please, can you attach picture from matlab simulink on which is your model presented together with your transfer functions of each automation system component?
In attachment you can find informations about FB 41, continuous PID block. As you can see roughly transfer function is K(1+1/Tis+Tds), so you can use this form to simulate PID acting in working area. If you want to simulate real behavior in matlab you'll need to make PID block your self using, for example, saturation blocks to limit PID output and similar.
What version of Matlab do you use?
In ver 7.0 there is PID block with max and min output values.
 
Good day,

Thanks for your answers. It is general view of my matlab model:

model.JPG


As you see its not complicated. Signal described as 1. should be a value 0-100 as in real simatic PID to model behavior of complete real system. Yes, i suppose that i must make own PID, it will be not problem if i will know how simatic one does works. Unfortunelly i have Matlab 6.5 so must make limits by my own.

I thinked some about this problem yesterday, and have some interresting conclusions. In pdf file attached two posts above is a schematic diagram of PID algorithm. As we can see, theres possible to attach as input PV_PER a process variable in I/0 format (0-27648). Then this value is calculated using this formula :

PV_PER*(100/27648)

It does mean that in normal conditions when input signal is not overranged, we get a value in range 0-100 as input. At output of PID block this 0-100 range is calculated back to 0-27648 range for peripheral output.
Interresting is that this 0-100 input value is in next step compared by +- block with SP_INT (a setpoint). SP_INT can be given in 0-100 format, or in phisical value, in my case a 2.8 m. For me it dont have sense ...

Example:
lets say that my levelmeter gives a 20000 (in i/o format) when level is equal 2,8 m. 20000 calculated into 0-100 format gives 72,33. Im providing a SP_INT input in phisical value a 2,8 m so level in tank is exacly what should be. But when we compare SP_INT and PV_PER in +- block we will get a -69,3 error value what is of course wrong, bcouse level is exacly what we want so error should be close to 0. If PID will try to regulate to make this error 0 of course level will be totally not correct.

So how it does work ? I have one idea .... maybe all input values are calculated at input to 0-100 range in some mysterious way ? If yes, how ? What will be "100" and what "0" ?

Its other question : how do PID know what exacly these do 20000 mean ? In two another levelmeters: one with range to 20 meters and another with range to 100 meters a i/o value of 20000 will mean totally another level.

Its really many questions about one simple block.

Thank you for your help in advance

Grzegorz
 
Sigreg,

as you can see, FB41 continuos PID block gives you opportunity to work with percent values for PV and controller output. This is how I see it (of course, I could be wrong, but there are a lot of gurus here who can correct me if I'm wrong).

To control process, you need analog I/O modules. Your analog module can be configured to read current or voltage signal (there are possibilities to use thermocouples and similar, but this is not the issue here). Module could be configured to expect current signal 4-20 mA or voltage -10...+10 V signal. Anyway, module reads these values as integer numbers between 0 and 27648. So if you want to use percent you need to use PV_PER input, because it calculate percent value according to formula: PV_PER*100/27648, hence 27648 will produce 100% value of signal. If this the case you need to use percent of SP (setpoint signal) also. You mustnot use physical value signal, but use percent input. So, whole story is just about scaling. You need to ensure that SP is in % if you use variant with scaling PV_PER and LMN_PER.

The question is how to simulate that in MATLAB? Well, that is fairly easy. Let's say you want to control process (level in tank), informations about level that is actually in tank is provided from some kind of transmitter. Let's say that transmitter is configured to provide standard current signal 4-20 mA and that your analog module is configured to accept current signals. This means that 4mA is 0 and 20 mA is 27648. We want to use FB41 PID block, so we need to use percent values in order to obtain appropriate control. Let's say that PIW 288 (just an example) is input channel to which PV is connected. That address must be connected to PV_PER input and PVPER_On must be 1 (in order to use percent).Now you must also ensure that SP_INT is between 0 and 100%. If Set Point value is adjusted outside PLC (some kind of current signal that is connected to analog module on address PIW 304, you will need to precalculate that value (0-27648) to 0 - 100% yourself, so PIW 304 must not be connected to SP_INT directly, it needs to be scalled first, otherwise bad control is to be expected.

Okay, that is first part of your question, now I will explain how to simulate PID block in Matlab, only part of calculating values. I'm sure you know how to use integrators and derivative terms, so I will not bother to explain the PID algorithm itself. Since you expected PV value as integer numbers, you'll need a block to convert it to percent value. I have created subsystem in Matlab, so it can be used everywhere where it is needed. On pictures Calculate precent you can see how it is done. I made generic block that expect both min and max values to be entered, but since analog module reads analog input as int number, min is 0 and max is 27648, so these values can be entered as constants inside subsystem. In that case there will be only one input and one output, but it is not really important now, is it?

Of course you'll need block to recalculate value again, when you have percent value (integer number that can be sent to output, for example, PQW316) which will be converted to current signal. For that purpose, I use Inv_Percent subsystem whose internal structure is shown in picture Inv_Percent_inside.jpg. For other blocks you can use standard Matlab blocks such as Saturation block, just examine Simulink library closely, there must be saturation block in Nonliner group or similar (in Matlab 7 it is under group Discontinuities), also I'm sure there is equivalent block for dead band. Try to do the rest by yourself.

http://www.plctalk.net/qanda/uploads/Calculate_Percent.jpg
http://www.plctalk.net/qanda/uploads/Calculate_Percent_inside.jpg
http://www.plctalk.net/qanda/uploads/Inv_Percent_inside.jpg

P.S. I use FB41, without any need to use percent inputs at all. I used scaling blocks FC 105 and unscalling blocks FC106 in Simatic standard library. I used voltage sensors so all my analog modules were configured to use -10/+10V signal. First I used all analog addresses in program and FC105 to scale inputs to real numbers in range (-10 ,+10), then I used PV_IN and SP_INT (PVPER_ON is 0, PV_PER is not used) and LMN output (not LMN_PER). I assign memory address to LMN output (for example MD40), used FC106 to convert value (-10 to +10) back to integer number and assign that address to analog output address (PQW316) and controller worked very well. Just, don't forget to place it in OB35 block.
 
Last edited:
Hello,

Thank you Pandiani, great post ! it is what i need.
In meantime i did some experiments with other S7-300 to check how PID CONST_C works, it is as you said - if we provide precentage SP, we should give all other data in percents too, not trying mix phisical values with "PER" bcouse is leading to false error calucaltions.
In my real working system with tank and pump im providing as PID input a phisical values in meters. Im reading values from AI module in other block, and converting them into meters and sending them to SCADA system and using in PID block. But now i have idea how i can do regulation faster and more accurate. It is my idea :

Example:
I must keep level equal 2.8 meter. And lets say now its 3.0 meter, so i have error 0.2 meter which will be corrected by PID algorithm. But what if i will use percentage values ? My levelmeter have range 0-5 meters, so 2.8m = 56% and 3m = 60%. After comparing these values are giving us error equal 4, its few times bigger than 0.2 so i think that i can get faster PID response and better quality of regulation. Is it correct ?

Anyaway, thank you again for your help very much !

Best Regards
Greg
 
I'm pretty much sure you won't get faster response overall, because again, it will be scalling of output. I have tested response and in both dynamics were the same. I used input step signal from 0 to 5. And min and max values are 0 and 10. This means that input change is from 0 to 50 %. Of course PID output is scalled so it can match percent but before signal is feed into process there is unscalling, so basically you didn't get any faster or changed response. Please see picture of model with percent precalculation. That signal goes to PID and output from PID is again scalled back to normal values. Since all elements in this model are linear there will be no overall change.

http://www.plctalk.net/qanda/uploads/Simulation.jpg
 
Okay, now it is time for you to explain your model. I'm pretty much good with theory and I'm a young engineer too. System identification is what i have found to be the hardest part of control, I simply don't know how to obtain transfer function from process, I have read some articles including that famous heat exchanger example from controlguru.com, but I don't get general picture (yet). For, example I don't understand your model. In every automation task I looked, error signal that is used to feed controller is obtained as ERR = SP – PV, where Sp is set point value, and PV is process variable. In this case, SP is 2.8m and PV is actual level in the tank.

1. Why do you form signal PV-SP instead of SP-PV?

2. How did you model your pump and tank, i.e. how did you determine you gain and time constant parameters?

If this task is assign to me, I would make model as shown in picture (school example)

PID is controller, Actuator is pump and object is actual level in the tank. Change in flow I would see as a disturbance.

Please explain to me why you didn't use this form, and what parameters did you use for PID and step change in flow?

Also, can you explain why did you convert flow from t/h to t/min? In other words, I need all parameters to successfully perform simulation in Matlab.

Looking forward to your answers.

Model_of_tank_level.jpg
 
Advanced Control - Level Control

I don't want to interfere. You guys are doing well. I just wanted to mark the thread with the words Advanced Control so we can find this thread again some time in future. This is a good example of how to approach a PID control application.

I too am interested in how sigreg determined the two individual transfer functions. The techniques I use would find the combined transfer function.

System identification is what i have found to be the hardest part of control, I simply don't know how to obtain transfer function from process, I have read some articles including that famous heat exchanger example from controlguru.com, but I don't get general picture (yet).
You assume a model and then find which parameters minimize the sum of square error between the SP and PV. This can be done manually with the help of Matlab but Matlab also has a fminsearch function that is the right way to do minimization. Minimization is a good technique to learn.
 
Thank you for your reply Peter, I didn't forget thread Advnaced control, but I'll need more time to learn and understand other things from that heat exchanger example (for example, derivate term and how to use it effectively).
Now, I will wait sigreg to answer my questions and explain me why he used sum block the way he used it.
 
Pandiani, your system diagram and sigreg's diagram are equivalent. Rotate the elements clockwise until the main tank is at the far right, the error sum block is at the far left and everything is on the top line. You will see they are the same.


Technically I think the pump transfer function gain should be negative. It causes the tank level to decrease as it's output increases. Since the gain is left positive, an easy way to get the correct response direction is to produce a 'non-standard' error. In so doing a high tank level will cause then pump to run faster.

Peter, this probably isn't in the scope of this thread, but since you brought it up:
Originally posted by Peter Nachtwey:

You assume a model and then find which parameters minimize the sum of square error between the SP and PV.

What model do I assume? Do I start simple (FOPDT) and go more complex if I don't get a reasonable fit? Do I look at a step response and take clues off of that? How do I know that my model is close enough? If I choose a first order model and my system is actually second order without a dominant pole, there is still a first order time constant that will get me 'as close as possible' to a fit. The fit will just be very poor.

Keith
 
Hello guys,

Im very glad bcouse your interrest with this tread, it will allow me and other "green ones" to learn many important things. Ok, let me answer for some your question.
How did i get transfer functions of tank and pump ?
Lucky me ... my object is not complicated. In fact i have there only three devices :
- tank
- pump with frequency converter
- PID regulator in S7-300

Of course its possible to find these functions in mathematical way, but for me a drawings and plots are more easy to understand than complex mathematical equations, and personally i do prefer observations and measurements (if its possible) more than math way. Unfortunatelly "measurement" way of objects identification is possible only when we have such object to own disposition and can make all needed tests.
Before i start explain my approach to all objects, i must say that my model still have some error which i have problem to find. In real object i used a step response Ziegler-Nichols method to find a PID parameters, in my mathematical model this method does not work.Its just not possible to get any oscillations using only P part of PID controller in my math model. From other way any integrating time is making my math object very unstable, where real object is working with integrating part of PID very good. So maybe when you will see how i did my object identifications you will find where i did mistake.

- PID
Now all is clean, we have good explanations how Simatic PID works in above posts

- Tank
What happens in tank, how it works ? If we turn on inlet and stop outlet tank will be slowly filling with water in time - one input and only one output - a level. Tank is "suming" a flow in time giving back level .. so we can treat it like perfect integration object. If we know how big flow is an inlet, and we do know a tank dimensions, we are able to calculate how fast tank will be filled. It is what i did, ive calculated how high level will be reached after known time with known and stable inlet flow. Then i did simple model of tank with flow value at inlet, integration "in tank" and level at output, and just found a gain which gives me correct level in correct time with specfied inlet flow. How i did found this gain ? Just by choosing values and observing my mathematical tank answers in time.

- Pump
Its a electrical "propeller" pump from Grundfos, driven by frequency converter, and frequency converter is regulated by PID block with 0-100 output range. What i did... first ive turned off pump, then turned it on to 100 % speed and i got a time which pump need to run from 0 to 100 % speed. Then ive checked what outlet flow value i will have at speed 10%, 20%, 30% and so on, which gived me some function of pump effectivency. These measurements was enought to know that pump is a 2th rank inertion object, but i decided to make my model simpler and used 1th rank inertion object. Then i choosed parameters as in tank case, i know how big flow i must have at given speed, i see my mathematical object answers for 0-100 input signal, so i know that parameters are good enought or no. After some time i got quite good answers.
And about pump gain - highter input signal makes pump run faster with bigger flow, so pump gain must be positive.

And its all. But as i said before - this model have some error ... i have one idea what it can be and ill try check it, maybe before that somebody will find what it is - in case if im wrong.

Best Regards
Greg
 
sigreg said:
Before i start explain my approach to all objects, i must say that my model still have some error which i have problem to find. In real object i used a step response Ziegler-Nichols method to find a PID parameters,
What PID gains did you end up with? If you have the model you shouldn't need to use Ziegler-Nichols.

in my mathematical model this method does not work.
Its just not possible to get any oscillations using only P part of PID controller in my math model.
The integrator from the PID, the integrator of the tank and the low pass pole of the pump means you have 3 poles. You should be able to increase the Kc to get the system to oscillate. I think you have done something wrong here.

From other way any integrating time is making my math object very unstable, where real object is working with integrating part of PID very good. So maybe when you will see how i did my object identifications you will find where i did mistake.
I will have time this weekend to show you.

- Pump
Its a electrical "propeller" pump from Grundfos, driven by frequency converter, and frequency converter is regulated by PID block with 0-100 output range. What i did... first ive turned off pump, then turned it on to 100 % speed and i got a time which pump need to run from 0 to 100 % speed. Then ive checked what outlet flow value i will have at speed 10%, 20%, 30% and so on, which gived me some function of pump effectivency. These measurements was enought to know that pump is a 2th rank inertion object, but i decided to make my model simpler and used 1th rank inertion object.
[/quote]
This is OK as long as the second pole is at a much ( 10 x ) higher frequency than the first. Then you are close enough.

And its all. But as i said before - this model have some error ... i have one idea what it can be and ill try check it, maybe before that somebody will find what it is - in case if im wrong.

All models have errors. Having a model is better than no model at all and the better the model, the easier it is to optimize the PID gains.

This week end I will show you my gains and response for your model.
 
Hmm, that story about sign of pump's gain begins to worry me. I'm not sure I completely understand this. Usually, sign of PID gain is chosen whether when CO (controller output) goes up PV should goes up or down. I think that pump is object "as is", so we cannot change it's parameters.
Please read file in attachment and comment.
I think that if pump is subtracting from the level, than there must be sign minus on sum block, but on the side toward "flow", not minus from pump output side.
On the uploaded picture you can see the scheme of this process (at least, how I see it).
Tank_level_control.jpg

Now, actuator is pump and here we can ask question about sign, but only the sign of Kp (proportional gain) of controller.
Let's clear these things together...
 
Last edited:

Similar Topics

HI.I REVIEWED A PROJECT DONE. THIS FB41 PID BLOCK WAS USED FOR THE PASTEURIZATION PROCESS. THE PROCESS I CAN'T UNDERSTAND IS THE ACTION. WHILE THE...
Replies
2
Views
1,109
Hello, I have a PID block in my program controlling pump speed in order to get a correct Differential pressure. The way I have it set up is the...
Replies
3
Views
1,258
Is there a way to create proportional logic for a control valve without using a PID function? I want to create a simple P controller without...
Replies
8
Views
2,622
So I have a PID block on CCW set up to control a motor. I have my variables input and the absolute error is changing but the CV is always 0. There...
Replies
1
Views
1,610
I want to change the setpoint of PID block in Codesys for every 1 hour. like that i have to give 48 setpoints for 48 hours. So how can I give 48...
Replies
2
Views
1,524
Back
Top Bottom