Skip to content

Commit c513e9e

Browse files
authored
Merge pull request #61 from WizardTim/master
More statistics to detect bad/over polling for fast continuous example
2 parents 5a71959 + 1f94daf commit c513e9e

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

examples/ads1x15_fast_read.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,36 @@
2222
ads.mode = Mode.CONTINUOUS
2323
ads.data_rate = RATE
2424

25+
repeats = 0
26+
2527
data = [None] * SAMPLES
2628

2729
start = time.monotonic()
2830

2931
# Read the same channel over and over
3032
for i in range(SAMPLES):
3133
data[i] = chan0.value
34+
# Detect repeated values due to over polling
35+
if data[i] == data[i - 1]:
36+
repeats += 1
37+
3238

3339
end = time.monotonic()
3440
total_time = end - start
3541

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))

0 commit comments

Comments
 (0)