-
Notifications
You must be signed in to change notification settings - Fork 6
/
SIG_SMTH.scl
159 lines (155 loc) · 5.41 KB
/
SIG_SMTH.scl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Name: SIG_SMTH
// Symbolic Name: SIG_SMTH
// Symbol Comment: Signal Smoothing
// Family: CONTROL
// Version: 7.1
// Author: TECHN71
// Last modified: 03/14/2008
// Use: UDT12, FC260, SFC6
// Size in work memory: 986 bytes
// Object name: SIG_SMTH
// Signature: generiert vom SCL Übersetzer Version: SCLCOMP K05.03.02.01_01.03.00.01 release
{
Scl_ResetOptions ;
Scl_OverwriteBlocks:= 'y' ;
Scl_GenerateReferenceData := 'y' ;
Scl_S7ServerActive:= 'y' ;
Scl_CreateObjectCode:= 'y' ;
Scl_OptimizeObjectCode:= 'y' ;
Scl_MonitorArrayLimits:= 'n' ;
Scl_CreateDebugInfo := 'n' ;
Scl_SetOKFlag:= 'n' ;
Scl_SetMaximumStringLength:= '254'
}
FUNCTION_BLOCK FB1144
TITLE ='Signal Smoothing'
{ S7_alarm_ui := '0'; S7_m_c := 'false'; S7_tasklist := 'OB100' }
AUTHOR : TECHN71
FAMILY : CONTROL
NAME : SIG_SMTH
VERSION : '7.1'
//revers by komatic
VAR_INPUT
PV { S7_dynamic := 'true' }: REAL ; //Analog input (process value)
TimeConstant { S7_visible := 'true'; S7_dynamic := 'true' }: REAL := 1.000000e+001; //Filter time constant [s] for Butterworth
OutlThreshold { S7_dynamic := 'true' }: REAL := 1.000000e+001; //Threshold of the outlier detection
OutlCycles { S7_visible := 'true' }: INT := 3; //number of cycles to hold outlier
SampleTime { S7_visible := 'false'; S7_link := 'false'; S7_sampletime := 'true'; S7_dynamic := 'true' }: REAL := 1.000000e+000; //Sample Time [s]
OutlDetOn { S7_dynamic := 'true' }: BOOL ; //1: Outlier detection on
FilterOn { S7_dynamic := 'true' }: BOOL := TRUE; //1: Filter on
Restart { S7_dynamic := 'true' }: BOOL ; //1: Reset filter algorithm
END_VAR
VAR_OUTPUT
CleanPV { S7_dynamic := 'true' }: REAL ; //output value
OutlDetected { S7_dynamic := 'true' }: BOOL ; //1: Outlier detected
ErrorNum { S7_dynamic := 'true' }: INT ; //Parametrization Error
END_VAR
VAR
xx : ARRAY [1 .. 2 ] OF REAL := 2 (0.000000e+000) ;
b0 : REAL ; //internal coefficients of butterworth filter
b1 : REAL ;
b2 : REAL ;
aa1 : REAL ;
aa2 : REAL ;
TimeConstantOld : REAL ;
SampleTimeOld : REAL ;
PV_DelieredOld : REAL ;
OutlCount : INT ;
END_VAR
VAR_TEMP
stcTOP_SI : STRUCT
EV_CLASS : BYTE ; // Bits 0 to 3: Event ID· Bits 4 to 7: Event class
EV_NUM : BYTE ; // Event number
PRIORITY : BYTE ; // Number of the priority class (meaning OF B#16#FE: OB NOT available or locked)
NUM : BYTE ; // OB number.
TYP2_3 : BYTE ; // Data ID 2_3: identifies the information entered in ZI2_3
TYP1 : BYTE ; // Data ID 1 : identifies the information entered in ZI1
ZI1 : WORD ; // Additional information 1
ZI2_3 : DWORD ; // Additional information 2_3
END_STRUCT ;
stcSTART_UP_SI : STRUCT
EV_CLASS : BYTE ; // Bits 0 to 3: Event ID· Bits 4 to 7: Event class
EV_NUM : BYTE ; // Event number
PRIORITY : BYTE ; // Number of the priority class (meaning OF B#16#FE: OB NOT available or locked)
NUM : BYTE ; // OB number.
TYP2_3 : BYTE ; // Data ID 2_3: identifies the information entered in ZI2_3
TYP1 : BYTE ; // Data ID 1 : identifies the information entered in ZI1
ZI1 : WORD ; // Additional information 1
ZI2_3 : DWORD ; // Additional information 2_3
END_STRUCT ;
l : REAL ;
nenner : REAL ;
PV_Deliered : REAL ;
PV_Filtered : REAL ;
rTimeConstant : REAL ;
rSampleTime : REAL ;
i : INT ;
nTemp : INT ; //Temporary variable, Error SFC/SFB call
END_VAR
BEGIN
nTemp:=RD_SINFO(TOP_SI := stcTOP_SI
,START_UP_SI := stcSTART_UP_SI
);
IF (stcTOP_SI.NUM=B#16#64 OR Restart) OR
(TimeConstant<>TimeConstantOld) OR
(SampleTime<>SampleTimeOld)
THEN
ErrorNum:=0;
Restart:=false;
OutlCount:=OutlCycles;
rSampleTime:=SampleTime;
IF rSampleTime<1.000000e-003 THEN
rSampleTime:=1.000000e-003;
ErrorNum:=2;
END_IF;
rTimeConstant:=TimeConstant;
IF rTimeConstant<5.0*rSampleTime THEN
rTimeConstant:=5.0*rSampleTime;
ErrorNum:=74;
END_IF;
PV_Filtered:=PV;
xx[2]:=(1.0-b0)*PV;
xx[1]:=(-aa2)*xx[2] + (b2-b0*aa2)*PV;
l:=1.0/(TAN(3.141592*rSampleTime/rTimeConstant));
nenner:=l*2.41421356+1.0+l;
aa1:=(1.0-l)*2.0/nenner;
aa2:=((1-2.41421356*l)+l)/nenner;
b0:=1.0/nenner;
b1:=b0*2.0;
b2:=b0;
PV_Deliered:=PV;
ELSE
IF BYTE_TO_INT(stcTOP_SI.NUM)>=30 AND BYTE_TO_INT(stcTOP_SI.NUM)<=38 THEN
PV:=ChkREAL(In := PV,ErrNum := nTemp);
IF nTemp=1 OR nTemp=3 THEN
ErrorNum:=32;
PV:=PV_DelieredOld;
END_IF;
IF OutlDetOn THEN
OutlDetected:=OutlCount>=0 AND ABS(PV-PV_DelieredOld)>ABS(OutlThreshold);
IF OutlDetected THEN
OutlCount:=OutlCount-1;
PV_Deliered:=PV_DelieredOld;
ELSE
OutlCount:=OutlCycles;
PV_Deliered:=PV;
END_IF;
ELSE
PV_Deliered:=PV;
END_IF;
PV_Filtered:=b0*PV_Deliered+xx[2];
xx[1]:=(-aa2)*xx[2] + (b2-b0*aa2)*PV_Deliered;
xx[2]:=(xx[1]-aa1*xx[2]) + (b1-b0*aa1)*PV_Deliered;
IF FilterOn THEN
CleanPV:=PV_Filtered;
ELSE
CleanPV:=PV_Deliered;
END_IF;
ELSE
ErrorNum:=1;
END_IF;
END_IF;
TimeConstantOld:=TimeConstant;
SampleTimeOld:=SampleTime;
PV_DelieredOld:=PV_Deliered;
END_FUNCTION_BLOCK