-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTimerP.scl
211 lines (179 loc) · 6.33 KB
/
TimerP.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// Name: FB1810
// Symbolic Name: TimerP
// Symbol Comment: Impulsefunction and delayed On/Off Timer
// Family: TIME
// Version: 2.1
// Author: AdvLib80
// Last modified: 10/24/2011
// Use: UDT15,UDT16,FC260
// Size: 980 byte
FUNCTION_BLOCK FB11810
TITLE ='Impulsefunction and delayed On/Off Timer'
AUTHOR : AdvLib80
FAMILY : 'TIME'
NAME : TimerP
VERSION : '2.1'
VAR_INPUT
SampleTime { S7_visible := 'false'; S7_link := 'false'; S7_sampletime := 'true'; S7_param := 'false' }: REAL := 1.000000e-001; //Sampling Time [s]
Ti { S7_edit := 'para'; S7_dynamic := 'true' }: REAL ; //Time [s]
Mode { S7_edit := 'para'; S7_dynamic := 'true' }: INT := 2; //0=Pulse,1=ExtP,2=OnDel,3=RetOn-D,4=Off-D
Reset { S7_dynamic := 'true' }: STRUCT //1=Reset
Value : BOOL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
In { S7_dynamic := 'true' }: STRUCT //Value input
Value : BOOL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
END_VAR
VAR_OUTPUT
ErrorNum { S7_visible := 'false'; S7_dynamic := 'true' }: INT := -1; //Error number
Out { S7_dynamic := 'true' }: STRUCT //Output
Value : BOOL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
InvOut { S7_dynamic := 'true' }: STRUCT //inverted output Out
Value : BOOL := TRUE; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
TimeRemaining { S7_dynamic := 'true' }: STRUCT //Time remaining [s]
Value : REAL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
END_VAR
VAR
SxFirstStart : BOOL := TRUE; //Initial run.
SxEdgeHlp : BOOL ; //pos. edge on input In.Value
SxResetHlp : BOOL ; //output was reset by reset comand
SxNoTiErr : BOOL ; //No Error
SxModeHlp : INT ; //Merker fьr Mode
SrPrevTi : REAL := -1.000000e-002; //previous value of Ti
END_VAR
VAR_TEMP
nTiErr : INT ;
END_VAR
BEGIN
IF SxFirstStart // first start
THEN
ErrorNum:=0;
SxResetHlp:=true;
SxFirstStart:=false;
END_IF;
IF Reset.Value // reset
THEN
SxResetHlp:=true;
TimeRemaining.Value:=0.000000e+000;
Out.Value:=false;
ELSE // normal work
IF Ti < SampleTime // wrong time set
THEN
ErrorNum:=11;
TimeRemaining.Value:=0.000000e+000;
Out.Value:=false;
ELSE
IF REAL_TO_DWORD(Ti)<>REAL_TO_DWORD(SrPrevTi) // if time changed
THEN
SrPrevTi:=Ti;
nTiErr:=0;
Ti:=ChkREAL(In :=Ti,ErrNum :=nTiErr); // check if time is good number
IF nTiErr = 1 OR nTiErr = 3 THEN ErrorNum:=33; ELSE ErrorNum:=0; END_IF;
SxNoTiErr:=ErrorNum = 0;
END_IF;
IF TimeRemaining.Value>=SampleTime // calculate rest of time
THEN
TimeRemaining.Value:=TimeRemaining.Value-SampleTime;
ELSE
TimeRemaining.Value:=0.000000e+000;
END_IF;
IF Mode>4 OR Mode<0 // check if mode is correct
THEN
ErrorNum:=1;
ELSE
IF SxNoTiErr THEN ErrorNum:=0; END_IF;
SxModeHlp:=Mode;
END_IF;
IF NOT SxEdgeHlp AND In.Value // front on the input
THEN
IF SxModeHlp < 4
THEN
TimeRemaining.Value:=Ti;
SxResetHlp:=false;
END_IF;
END_IF;
CASE SxModeHlp OF //0=Pulse,1=ExtP,2=OnDel,3=RetOn-D,4=Off-D
0 :
IF In.Value
THEN
IF TimeRemaining.Value>0.000000e+000
THEN
Out.Value:=true;
ELSE
Out.Value:=false;
END_IF;
ELSE
TimeRemaining.Value:=0.000000e+000;
Out.Value:=false;
END_IF;
1 :
IF TimeRemaining.Value>0.000000e+000
THEN
Out.Value:=true;
ELSE
Out.Value:=false;
END_IF;
2 :
IF In.Value
THEN
IF TimeRemaining.Value>0.000000e+000
THEN
Out.Value:=false;
ELSE
Out.Value:= NOT SxResetHlp;
END_IF;
ELSE
TimeRemaining.Value:=0.000000e+000;
Out.Value:=false;
END_IF;
3 :
IF TimeRemaining.Value>0.000000e+000
THEN
Out.Value:=false;
ELSE
IF SxResetHlp
THEN
Out.Value:=false;
ELSE
Out.Value:=true;
END_IF;
END_IF;
4 :
IF NOT In.Value AND SxEdgeHlp
THEN
IF Ti<=SampleTime
THEN
OK:=false;
TimeRemaining.Value:=0.000000e+000;
Out.Value:=false;
ELSE
TimeRemaining.Value:=Ti;
END_IF;
END_IF;
IF TimeRemaining.Value>0.000000e+000
THEN
Out.Value:=true;
ELSE
Out.Value:=In.Value;
END_IF;
ELSE: // wrong mode
ErrorNum:=1;
TimeRemaining.Value:=0.000000e+000;
Out.Value:=false;
END_CASE;
END_IF;
END_IF;
SxEdgeHlp:=In.Value;
InvOut.Value:= NOT Out.Value;
Out.ST:=In.ST;
IF ErrorNum = 33 AND In.ST <> B#16#0 THEN Out.ST:=B#16#28; END_IF;
InvOut.ST:=Out.ST;
END_FUNCTION_BLOCK