4/11/2012 6:17 PM | |
Joined: 1/28/2009 Last visit: 9/7/2024 Posts: 6846 Rating: (1365)
|
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*(FNEW-FOLD))/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 (657 Downloads) |
This contribution was helpful to9 thankful Users |
Follow us on