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
212
213
214
215
216
217
218
219
220
|
FUNCTION "TIMEDIFF" : TIME
TITLE = Compute TIME0 minus TIME1
VAR_INPUT
TIME0 : TIME;
TIME1 : TIME;
END_VAR
BEGIN
L #TIME0
L #TIME1
-D
UD DW#16#7FFFFFFF
T #RET_VAL
END_FUNCTION
FUNCTION "UPDATE_TIME" : VOID
BEGIN
CALL "TIME_TCK" (
RET_VAL := "TIME",
)
END_FUNCTION
ORGANIZATION_BLOCK OB 1
BEGIN
M001: CALL "UPDATE_TIME"
// Check 0.1s trigger time
U "CLOCK_0.1s"
FN "CLOCK_0.1s_EDGE"
SPBN M010
CALL "TIMEDIFF" (
TIME0 := "TIME",
TIME1 := "STAMP_0.1s",
RET_VAL := "DIFF",
)
L "DIFF"
__ASSERT>= __ACCU 1, T#50ms
__ASSERT<= __ACCU 1, T#150ms
L "TIME"
T "STAMP_0.1s"
L "COUNT_0.1s"
+ 1
T "COUNT_0.1s"
// Check 0.2s trigger time
M010: U "CLOCK_0.2s"
FN "CLOCK_0.2s_EDGE"
SPBN M020
CALL "TIMEDIFF" (
TIME0 := "TIME",
TIME1 := "STAMP_0.2s",
RET_VAL := "DIFF",
)
L "DIFF"
__ASSERT>= __ACCU 1, T#150ms
__ASSERT<= __ACCU 1, T#250ms
L "TIME"
T "STAMP_0.2s"
L "COUNT_0.2s"
+ 1
T "COUNT_0.2s"
// Check 0.4s trigger time
M020: U "CLOCK_0.4s"
FN "CLOCK_0.4s_EDGE"
SPBN M030
CALL "TIMEDIFF" (
TIME0 := "TIME",
TIME1 := "STAMP_0.4s",
RET_VAL := "DIFF",
)
L "DIFF"
__ASSERT>= __ACCU 1, T#350ms
__ASSERT<= __ACCU 1, T#450ms
L "TIME"
T "STAMP_0.4s"
L "COUNT_0.4s"
+ 1
T "COUNT_0.4s"
// Check 0.5s trigger time
M030: U "CLOCK_0.5s"
FN "CLOCK_0.5s_EDGE"
SPBN M040
CALL "TIMEDIFF" (
TIME0 := "TIME",
TIME1 := "STAMP_0.5s",
RET_VAL := "DIFF",
)
L "DIFF"
__ASSERT>= __ACCU 1, T#450ms
__ASSERT<= __ACCU 1, T#550ms
L "TIME"
T "STAMP_0.5s"
L "COUNT_0.5s"
+ 1
T "COUNT_0.5s"
// Check 0.8s trigger time
M040: U "CLOCK_0.8s"
FN "CLOCK_0.8s_EDGE"
SPBN M050
CALL "TIMEDIFF" (
TIME0 := "TIME",
TIME1 := "STAMP_0.8s",
RET_VAL := "DIFF",
)
L "DIFF"
__ASSERT>= __ACCU 1, T#750ms
__ASSERT<= __ACCU 1, T#850ms
L "TIME"
T "STAMP_0.8s"
L "COUNT_0.8s"
+ 1
T "COUNT_0.8s"
// Check 1.0s trigger time
M050: U "CLOCK_1.0s"
FN "CLOCK_1.0s_EDGE"
SPBN M060
CALL "TIMEDIFF" (
TIME0 := "TIME",
TIME1 := "STAMP_1.0s",
RET_VAL := "DIFF",
)
L "DIFF"
__ASSERT>= __ACCU 1, T#950ms
__ASSERT<= __ACCU 1, T#1s50ms
L "TIME"
T "STAMP_1.0s"
L "COUNT_1.0s"
+ 1
T "COUNT_1.0s"
// Check 1.6s trigger time
M060: U "CLOCK_1.6s"
FN "CLOCK_1.6s_EDGE"
SPBN M070
CALL "TIMEDIFF" (
TIME0 := "TIME",
TIME1 := "STAMP_1.6s",
RET_VAL := "DIFF",
)
L "DIFF"
__ASSERT>= __ACCU 1, T#1s550ms
__ASSERT<= __ACCU 1, T#1s650ms
L "TIME"
T "STAMP_1.6s"
L "COUNT_1.6s"
+ 1
T "COUNT_1.6s"
// Check 2.0s trigger time
M070: U "CLOCK_2.0s"
FN "CLOCK_2.0s_EDGE"
SPBN M080
CALL "TIMEDIFF" (
TIME0 := "TIME",
TIME1 := "STAMP_2.0s",
RET_VAL := "DIFF",
)
L "DIFF"
__ASSERT>= __ACCU 1, T#1s950ms
__ASSERT<= __ACCU 1, T#2s50ms
L "TIME"
T "STAMP_2.0s"
L "COUNT_2.0s"
+ 1
T "COUNT_2.0s"
// Stop test, if test time complete
M080: CALL "TIMEDIFF" (
TIME0 := "TIME",
TIME1 := "START_TIME",
RET_VAL := "DIFF",
)
L "DIFF"
L T#4s50ms
<D
BEB // Not completed, yet
// Completed. Check trigger counts.
L "COUNT_0.1s"
__ASSERT== __ACCU 1, 40
L "COUNT_0.2s"
__ASSERT== __ACCU 1, 20
L "COUNT_0.4s"
__ASSERT== __ACCU 1, 10
L "COUNT_0.5s"
__ASSERT== __ACCU 1, 8
L "COUNT_0.8s"
__ASSERT== __ACCU 1, 5
L "COUNT_1.0s"
__ASSERT== __ACCU 1, 4
L "COUNT_1.6s"
__ASSERT== __ACCU 1, 2
L "COUNT_2.0s"
__ASSERT== __ACCU 1, 2
// Everything is ok. Abort the test.
CALL "STP" // Stop CPU
END_ORGANIZATION_BLOCK
ORGANIZATION_BLOCK OB 100
BEGIN
CALL "UPDATE_TIME"
L "TIME"
T "STAMP_0.1s"
T "STAMP_0.2s"
T "STAMP_0.4s"
T "STAMP_0.5s"
T "STAMP_0.8s"
T "STAMP_1.0s"
T "STAMP_1.6s"
T "STAMP_2.0s"
T "START_TIME"
END_ORGANIZATION_BLOCK
|