14
14
15
15
FREQUENCY = 1000
16
16
MICROSECONDS = 1e-6
17
- ABSTOL = 2 * (16.5 - (- 16.5 )) / (2 ** 10 - 1 ) # Two times CH1 resolution.
17
+ ABSTOL = 4 * (16.5 - (- 16.5 )) / (2 ** 10 - 1 ) # Four times lowest CH1/CH2 resolution.
18
18
19
19
20
20
@pytest .fixture
@@ -32,16 +32,22 @@ def scope(handler):
32
32
return oscilloscope .Oscilloscope (handler )
33
33
34
34
35
- def count_zero_crossings (y ):
35
+ def count_zero_crossings (x , y ):
36
+ sample_rate = (np .diff (x )[0 ] * MICROSECONDS ) ** - 1
37
+ samples_per_period = sample_rate / FREQUENCY
36
38
zero_crossings = np .where (np .diff (np .sign (y )))[0 ]
37
- real_crossings = np .where (~ ( np .diff (zero_crossings ) == 1 ) )
39
+ real_crossings = np .where (np .diff (zero_crossings ) > samples_per_period * 0.01 )
38
40
real_crossings = np .append (real_crossings , True )
39
- zero_crossings = zero_crossings [real_crossings ]
40
- return len (zero_crossings )
41
41
42
+ if len (real_crossings ) % 1 :
43
+ if y [0 ] * y [- 1 ] <= 0 :
44
+ return len (real_crossings ) + 1
42
45
43
- def verify_periods (y , channel , periods = 1 ):
44
- zero_crossings = count_zero_crossings (y )
46
+ return len (real_crossings )
47
+
48
+
49
+ def verify_periods (x , y , channel , periods = 1 ):
50
+ zero_crossings = count_zero_crossings (x , y )
45
51
assert zero_crossings == 2 * periods
46
52
assert y [0 ] == pytest .approx (y [- 1 ], abs = ABSTOL )
47
53
@@ -55,8 +61,8 @@ def test_capture_one_12bit(scope):
55
61
56
62
57
63
def test_capture_one_high_speed (scope ):
58
- _ , y = scope .capture (channels = 1 , samples = 2000 , timegap = 0.5 )
59
- verify_periods (y , scope ._channels ["CH1" ])
64
+ x , y = scope .capture (channels = 1 , samples = 2000 , timegap = 0.5 )
65
+ verify_periods (x , y , scope ._channels ["CH1" ])
60
66
61
67
62
68
def test_capture_one_trigger (scope ):
@@ -66,16 +72,16 @@ def test_capture_one_trigger(scope):
66
72
67
73
68
74
def test_capture_two (scope ):
69
- _ , y1 , y2 = scope .capture (channels = 2 , samples = 500 , timegap = 2 )
70
- verify_periods (y1 , scope ._channels ["CH1" ])
71
- verify_periods (y2 , scope ._channels ["CH2" ])
75
+ x , y1 , y2 = scope .capture (channels = 2 , samples = 500 , timegap = 2 )
76
+ verify_periods (x , y1 , scope ._channels ["CH1" ])
77
+ verify_periods (x , y2 , scope ._channels ["CH2" ])
72
78
73
79
74
80
def test_capture_four (scope ):
75
- _ , y1 , y2 , y3 , _ = scope .capture (channels = 4 , samples = 500 , timegap = 2 )
76
- verify_periods (y1 , scope ._channels ["CH1" ])
77
- verify_periods (y2 , scope ._channels ["CH2" ])
78
- verify_periods (y3 , scope ._channels ["CH3" ])
81
+ x , y1 , y2 , y3 , _ = scope .capture (channels = 4 , samples = 500 , timegap = 2 )
82
+ verify_periods (x , y1 , scope ._channels ["CH1" ])
83
+ verify_periods (x , y2 , scope ._channels ["CH2" ])
84
+ verify_periods (x , y3 , scope ._channels ["CH3" ])
79
85
80
86
81
87
def test_capture_invalid_channel_one (scope ):
0 commit comments