File tree 1 file changed +22
-2
lines changed
1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 22
22
ads .mode = Mode .CONTINUOUS
23
23
ads .data_rate = RATE
24
24
25
+ repeats = 0
26
+
25
27
data = [None ] * SAMPLES
26
28
27
29
start = time .monotonic ()
28
30
29
31
# Read the same channel over and over
30
32
for i in range (SAMPLES ):
31
33
data [i ] = chan0 .value
34
+ # Detect repeated values due to over polling
35
+ if data [i ] == data [i - 1 ]:
36
+ repeats += 1
37
+
32
38
33
39
end = time .monotonic ()
34
40
total_time = end - start
35
41
36
- print ("Time of capture: {}s" .format (total_time ))
37
- print ("Sample rate requested={} actual={}" .format (RATE , SAMPLES / total_time ))
42
+ rate_reported = SAMPLES / total_time
43
+ rate_actual = (SAMPLES - repeats ) / total_time
44
+ # NOTE: leave input floating to pickup some random noise
45
+ # This cannot estimate conversion rates higher than polling rate
46
+
47
+ print ("Took {:5.3f} s to acquire {:d} samples." .format (total_time , SAMPLES ))
48
+ print ("" )
49
+ print ("Configured:" )
50
+ print (" Requested = {:5d} sps" .format (RATE ))
51
+ print (" Reported = {:5d} sps" .format (ads .data_rate ))
52
+ print ("" )
53
+ print ("Actual:" )
54
+ print (" Polling Rate = {:8.2f} sps" .format (rate_reported ))
55
+ print (" {:9.2%}" .format (rate_reported / RATE ))
56
+ print (" Repeats = {:5d}" .format (repeats ))
57
+ print (" Conversion Rate = {:8.2f} sps (estimated)" .format (rate_actual ))
You can’t perform that action at this time.
0 commit comments