2
2
3
3
When integration testing, the PSLab's PWM output is used to generate a signal
4
4
which is analyzed by the logic analyzer. Before running the integration tests,
5
- connect SQ1->LA1->LA2->LA3->LA4.
5
+ connect:
6
+ SQ1 -> LA1
7
+ SQ2 -> LA2
8
+ SQ3 -> LA3
9
+ SQ4 -> LA4
6
10
"""
7
11
8
12
import time
21
25
LOW_FREQUENCY = 100
22
26
LOWER_FREQUENCY = 10
23
27
MICROSECONDS = 1e6
24
- ONE_CLOCK_CYCLE = logic_analyzer .CLOCK_RATE ** - 1 * MICROSECONDS
28
+ TWO_CLOCK_CYCLES = 2 * logic_analyzer .CLOCK_RATE ** - 1 * MICROSECONDS
25
29
26
30
27
31
@pytest .fixture
@@ -81,17 +85,17 @@ def test_capture_four_low_frequency(la):
81
85
t1 = la .capture (4 , 10 , e2e_time = e2e_time )[0 ]
82
86
# When capturing every edge, the accuracy seems to depend on
83
87
# the PWM prescaler as well as the logic analyzer prescaler.
84
- pwm_abstol = ONE_CLOCK_CYCLE * logic_analyzer .PRESCALERS [2 ]
88
+ pwm_abstol = TWO_CLOCK_CYCLES * logic_analyzer .PRESCALERS [2 ]
85
89
assert np .array (9 * [e2e_time * MICROSECONDS ]) == pytest .approx (
86
- np .diff (t1 ), abs = ONE_CLOCK_CYCLE * logic_analyzer .PRESCALERS [1 ] + pwm_abstol
90
+ np .diff (t1 ), abs = TWO_CLOCK_CYCLES * logic_analyzer .PRESCALERS [1 ] + pwm_abstol
87
91
)
88
92
89
93
90
94
def test_capture_four_lower_frequency (la ):
91
95
e2e_time = LOW_FREQUENCY ** - 1
92
96
t1 = la .capture (4 , 10 , modes = 4 * ["rising" ], e2e_time = e2e_time )[0 ]
93
97
assert np .array (9 * [e2e_time * MICROSECONDS ]) == pytest .approx (
94
- np .diff (t1 ), abs = ONE_CLOCK_CYCLE * logic_analyzer .PRESCALERS [2 ]
98
+ np .diff (t1 ), abs = TWO_CLOCK_CYCLES * logic_analyzer .PRESCALERS [2 ]
95
99
)
96
100
97
101
@@ -101,7 +105,7 @@ def test_capture_four_lowest_frequency(la):
101
105
0
102
106
]
103
107
assert np .array (9 * [e2e_time * MICROSECONDS ]) == pytest .approx (
104
- np .diff (t1 ), abs = ONE_CLOCK_CYCLE * logic_analyzer .PRESCALERS [3 ]
108
+ np .diff (t1 ), abs = TWO_CLOCK_CYCLES * logic_analyzer .PRESCALERS [3 ]
105
109
)
106
110
107
111
@@ -124,7 +128,7 @@ def test_capture_rising_edges(la):
124
128
expected = FREQUENCY ** - 1 * MICROSECONDS / 2
125
129
result = t2 - t1 - (t2 - t1 )[0 ]
126
130
assert np .arange (0 , expected * events , expected ) == pytest .approx (
127
- result , abs = ONE_CLOCK_CYCLE
131
+ result , abs = TWO_CLOCK_CYCLES
128
132
)
129
133
130
134
@@ -134,7 +138,7 @@ def test_capture_four_rising_edges(la):
134
138
expected = FREQUENCY ** - 1 * MICROSECONDS * 3
135
139
result = t2 - t1 - (t2 - t1 )[0 ]
136
140
assert np .arange (0 , expected * events , expected ) == pytest .approx (
137
- result , abs = ONE_CLOCK_CYCLE
141
+ result , abs = TWO_CLOCK_CYCLES
138
142
)
139
143
140
144
@@ -144,7 +148,7 @@ def test_capture_sixteen_rising_edges(la):
144
148
expected = FREQUENCY ** - 1 * MICROSECONDS * 12
145
149
result = t2 - t1 - (t2 - t1 )[0 ]
146
150
assert np .arange (0 , expected * events , expected ) == pytest .approx (
147
- result , abs = ONE_CLOCK_CYCLE
151
+ result , abs = TWO_CLOCK_CYCLES
148
152
)
149
153
150
154
@@ -174,7 +178,7 @@ def test_measure_interval(la):
174
178
channels = ["LA1" , "LA2" ], modes = ["rising" , "falling" ], timeout = 0.1
175
179
)
176
180
expected_interval = FREQUENCY ** - 1 * MICROSECONDS * 0.5
177
- assert expected_interval == pytest .approx (interval , abs = ONE_CLOCK_CYCLE )
181
+ assert expected_interval == pytest .approx (interval , abs = TWO_CLOCK_CYCLES )
178
182
179
183
180
184
def test_measure_interval_same_channel (la ):
@@ -183,7 +187,7 @@ def test_measure_interval_same_channel(la):
183
187
channels = ["LA1" , "LA1" ], modes = ["rising" , "falling" ], timeout = 0.1
184
188
)
185
189
expected_interval = FREQUENCY ** - 1 * DUTY_CYCLE * MICROSECONDS
186
- assert expected_interval == pytest .approx (interval , abs = ONE_CLOCK_CYCLE )
190
+ assert expected_interval == pytest .approx (interval , abs = TWO_CLOCK_CYCLES )
187
191
188
192
189
193
def test_measure_interval_same_channel_any (la ):
@@ -192,7 +196,7 @@ def test_measure_interval_same_channel_any(la):
192
196
channels = ["LA1" , "LA1" ], modes = ["any" , "any" ], timeout = 0.1
193
197
)
194
198
expected_interval = FREQUENCY ** - 1 * DUTY_CYCLE * MICROSECONDS
195
- assert expected_interval == pytest .approx (interval , abs = ONE_CLOCK_CYCLE )
199
+ assert expected_interval == pytest .approx (interval , abs = TWO_CLOCK_CYCLES )
196
200
197
201
198
202
def test_measure_interval_same_channel_four_rising (la ):
@@ -201,7 +205,7 @@ def test_measure_interval_same_channel_four_rising(la):
201
205
channels = ["LA1" , "LA1" ], modes = ["rising" , "four rising" ], timeout = 0.1
202
206
)
203
207
expected_interval = FREQUENCY ** - 1 * 3 * MICROSECONDS
204
- assert expected_interval == pytest .approx (interval , abs = ONE_CLOCK_CYCLE )
208
+ assert expected_interval == pytest .approx (interval , abs = TWO_CLOCK_CYCLES )
205
209
206
210
207
211
def test_measure_interval_same_channel_sixteen_rising (la ):
@@ -210,7 +214,7 @@ def test_measure_interval_same_channel_sixteen_rising(la):
210
214
channels = ["LA1" , "LA1" ], modes = ["rising" , "sixteen rising" ], timeout = 0.1
211
215
)
212
216
expected_interval = FREQUENCY ** - 1 * 15 * MICROSECONDS
213
- assert expected_interval == pytest .approx (interval , abs = ONE_CLOCK_CYCLE )
217
+ assert expected_interval == pytest .approx (interval , abs = TWO_CLOCK_CYCLES )
214
218
215
219
216
220
def test_measure_interval_same_channel_same_event (la ):
@@ -219,14 +223,14 @@ def test_measure_interval_same_channel_same_event(la):
219
223
channels = ["LA3" , "LA3" ], modes = ["rising" , "rising" ], timeout = 0.1
220
224
)
221
225
expected_interval = FREQUENCY ** - 1 * MICROSECONDS
222
- assert expected_interval == pytest .approx (interval , abs = ONE_CLOCK_CYCLE )
226
+ assert expected_interval == pytest .approx (interval , abs = TWO_CLOCK_CYCLES )
223
227
224
228
225
229
def test_measure_duty_cycle (la ):
226
230
period , duty_cycle = la .measure_duty_cycle ("LA4" , timeout = 0.1 )
227
231
expected_period = FREQUENCY ** - 1 * MICROSECONDS
228
232
assert (expected_period , DUTY_CYCLE ) == pytest .approx (
229
- (period , duty_cycle ), abs = ONE_CLOCK_CYCLE
233
+ (period , duty_cycle ), abs = TWO_CLOCK_CYCLES
230
234
)
231
235
232
236
0 commit comments