4/3/2012 8:25 PM  
Joined: 9/6/2008 Last visit: 8/4/2023 Posts: 177 Rating: (1) 
Hi All I have been asked if it would be possible to implement a Laplace transform within a S7400.(not PCS7) From my understanding theequation is as such: T_{N .}s + 1 Z(s) = K  (T_{D1 .}s + 1) . (T_{D2}_{.}s + 1) with gain K, time constants T_{N}, T_{D1}, T_{D2} and the complex Laplace variable s. I myself are new to this?? Any ideas Regards Philip 
4/4/2012 4:59 AM  
Joined: 1/28/2009 Last visit: 4/1/2024 Posts: 6836 Rating: (1359)

Hello, One possible method to find solution in time domain is to convert the Laplace expression to a second order differential equation and solve it numerically. Z(s)= Y(s)/R(s) There are methods such as Euler and RungeKutta which you can find detail in academic books or some tutorial via web. I have prepared some solutions for an arbitary ordinary differential equation which hopefully will post the first draft in "Expert Only Conference" this week. For a second order differential equation, you need to use state space representation to solve it.(X1,X2 definition) This is solution to: (C+Bs+As^{2 })*Y=F^{ } [code] FUNCTION_BLOCK FB3 // Block Parameters VAR_INPUT // Input Parameters F:REAL; A:REAL:=1.0; B:REAL:=1.0; C:REAL:=1.0; INTERVAL:TIME:=T#1S; END_VAR VAR_IN_OUT REST:BOOL:=FALSE; END_VAR VAR_OUTPUT // Output Parameters Y:REAL; END_VAR VAR_TEMP // Temporary Variables END_VAR VAR // Static Variables // FNEW:REAL:=0.0; X1:REAL:=0.0; X2:REAL:=0.0; X1OLD:REAL:=0.0; X2OLD:REAL:=0.0; DELTA1:REAL:=0.0; DELTA2:REAL:=0.0; T_INTERNAL:REAL:=1.0; END_VAR // Instruction Section T_INTERNAL := (DINT_TO_REAL(TIME_TO_DINT (INTERVAL)))/1000.0; IF REST=1 THEN X1:=0.0; X2:=0.0; X1OLD:=0.0; X2OLD:=0.0; REST:=0; ELSE DELTA2 :=(F (C*X1OLD)  (B*X2OLD))/A; X2:= X2OLD + (DELTA2 * T_INTERNAL); DELTA1 :=X2; X1 := X1OLD + (DELTA1 * T_INTERNAL); X2OLD:= X2; X1OLD:=X1; Y:=X1; ; END_IF; ; END_FUNCTION_BLOCK[/code] Best regards, Hamid Hosseini 
Last edited by: hdhosseini at: 4/4/2012 7:28 AM// typo 

This contribution was helpful to4 thankful Users 
4/4/2012 7:45 AM  
Posts: 2348 Rating: (263)

Well, solving equations on PLC is something exotic, actually this task should be performed not on PLC. hdhosseini, could you please write some comments to your FB?) What it takes and what the result. 
4/4/2012 8:29 AM  
Joined: 1/28/2009 Last visit: 4/1/2024 Posts: 6836 Rating: (1359)

Hello Aret, I am preparing a detailed document to illustrate 2 wellknown methods for different equations.It is necessary to know the Euler's method and then explain the flow of the program. I will post the first draft in "Expert Only Conference" theoretical background plus SCL program.(waiting for your comments there) About solving Differential Equations in PLC, this is the important part of control functions.There are some FBs for first and second order differential equations in Modular PID control package. Best regards, Hamid Hosseini 
Last edited by: hdhosseini at: 4/4/2012 10:35 AM// typo 

4/6/2012 9:32 AM  
Posts: 2348 Rating: (263)

Im a bit familiar with numerical methods of solving equations But though they should contain 1 cycle at least. Or you use cyclic nature of OB1 instead thus performing 1 operation per scan? 
4/6/2012 10:45 AM  
Joined: 1/28/2009 Last visit: 4/1/2024 Posts: 6836 Rating: (1359)

Calculation should be done in equal interval because time interval between 2 successive calls is used in the algorithm and for accurate estimation, it should be constant and known.All these feasible in OB3X ,"OB3X_EXC_FREQ " can be converted to time for being used as "delta t" in calculation. See the attachment. Best regards, Hamid Hosseini 
4/9/2012 10:15 AM  
Joined: 9/8/2009 Last visit: 7/17/2023 Posts: 1410 Rating: (150) 
You can also look for Simulink PLC Coder, it converts simulink blocks to SCL, if you plan to use such blocks more frequently, another option is to look under Matlab RealTime Target, you will find a C source of block. I would also suggest you to find appropiate function in Zplane, it would be much simpler for plc to compute, instead using numerical metods to compute in Splane. P.S.. Is this a real world problem, or its just some school exericise? If its real then explain what kind of filter/process is this, since a numerator of your transfer functionisn't quite good for computing, it would be better to change something to avoid problems. If I did no mistake then your transfom function is this: F(s)= [ ((1Tn/Td1) / (1Td2/Td1)) * (1/(Td1*s+1) ] + [ ((1Tn/Td2) / (1Td1/Td2)) * (1/(Td2*s+1 )] If viewed in equation editor is much more easy to understand and it is just a sum oftwo low pass filters, each consisting with its gain and its frequency. you can implement it very easy, look for first order filter implementation on mcu or plc. 
Last edited by: Marko Bursic at: 4/9/2012 11:35 AMLast edited by: Marko Bursic at: 4/9/2012 10:59 AM 

This contribution was helpful to2 thankful Users 
4/10/2012 9:13 AM  
Joined: 9/6/2008 Last visit: 8/4/2023 Posts: 177 Rating: (1) 
Hi Marko Thanks for reply. This is a real world problem. It is a feed forward issue where this chemist has come up with this equation. He is trying to predict the future usage of Carbon Dioxide by a plant in order to feed it to the CO2 generation plant. Currently the guys on site are trying to implement this predictive usage using a neural model by feeding it all the variables surrounding this usage and coming up with a 'best fit' result. The chemist/engineer is wanting to use this laplace equation he has come up with as he feels it is the better option. I just have no idea how to implement this via PLC. Regards Philip 
4/11/2012 4:26 PM  
Joined: 9/8/2009 Last visit: 7/17/2023 Posts: 1410 Rating: (150) 
I suggest to you and your chemystrist to use Ztransform, instead of using Laplace, it's made for use with hold/sample equipment (PLCs or DAQ products) and it's also easier to transform back in time domain. Things you can do with plc is limited. First you would have to determine sample time, that should be a 1/10th of dominating time of the process, and then determine the order number of model, this depend on order of real process, based on your laplace function I would say that is second oreder. Once you have set sampling time and order, you can automaticaly detect process transfer function by using some tecniques in matlab: Adaptive RLSM with exponential forgetting,....you need what is the exctitation (input) of system and what sytem outputs in time. I have also an implementation of this in scl, but never tested on real process, it needs also to determine some initial conditions. You can see the paper and matlab code for this: STCSL library for Simulink, you will find browsing the internet. 
This contribution was helpful to1 thankful Users 
4/11/2012 6:17 PM  
Joined: 1/28/2009 Last visit: 4/1/2024 Posts: 6836 Rating: (1359)

Hello again , I have finished my previously proposed code for your requirement. I have tested the result of my codes with SIMULINK and they were identical, as you can see in attachment.Note,You have 5 adjustable parameters that can generate a totally flexible transfer function for you.I will upload the project as soon as possible, you can use the function (FB300) even you are not familiar with SCL. Please note: F> as input signal Y> as output signal A,B,C,D,E as coefficient of Laplace transform as shown in attachment. REST> to reset calculation Interval> Time between to succesive OB3X calls (T#100mS) [code]FUNCTION_BLOCK FB300 // Block Parameters VAR_INPUT // Input Parameters F:REAL; A:REAL:=1.0; B:REAL:=1.0; C:REAL:=1.0; D:REAL:=1.0; E:REAL:=1.0; INTERVAL:TIME:=T#1S; END_VAR VAR_IN_OUT REST:BOOL:=FALSE; END_VAR VAR_OUTPUT // Output Parameters Y:REAL; END_VAR VAR_TEMP // Temporary Variables END_VAR VAR // Static Variables // FNEW:REAL:=0.0; X1:REAL:=0.0; X2:REAL:=0.0; X1OLD:REAL:=0.0; X2OLD:REAL:=0.0; DELTA1:REAL:=0.0; DELTA2:REAL:=0.0; T_INTERNAL:REAL:=1.0; FOLD:REAL:=0.0; FNEW:REAL:=0.0; END_VAR // Instruction Section T_INTERNAL := (DINT_TO_REAL(TIME_TO_DINT (INTERVAL)))/1000.0; IF REST=1 THEN X1:=0.0; X2:=0.0; X1OLD:=0.0; X2OLD:=0.0; FOLD:=0.0; FNEW:=0.0; //REST:=0; Y:=0; ELSE FNEW:= F; DELTA2 :=((((D*(FNEWFOLD))/T_INTERNAL)+(E*FNEW)) (C*X1OLD)  (B*X2OLD))/A; X2:= X2OLD + (DELTA2 * T_INTERNAL); DELTA1 :=X2; X1 := X1OLD + (DELTA1 * T_INTERNAL); X2OLD:= X2; X1OLD:=X1; Y:=X1; FOLD:=FNEW; ; END_IF; ; END_FUNCTION_BLOCK [/code] Best regards, Hamid Hosseini AttachmentLAPLACE_FORUM.zip (614 Downloads) 
This contribution was helpful to9 thankful Users 
Follow us on