Skip to content

More statistics to detect bad/over polling for fast continuous example #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions examples/ads1x15_fast_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,36 @@
ads.mode = Mode.CONTINUOUS
ads.data_rate = RATE

repeats = 0

data = [None] * SAMPLES

start = time.monotonic()

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


end = time.monotonic()
total_time = end - start

print("Time of capture: {}s".format(total_time))
print("Sample rate requested={} actual={}".format(RATE, SAMPLES / total_time))
rate_reported = SAMPLES / total_time
rate_actual = (SAMPLES - repeats) / total_time
# NOTE: leave input floating to pickup some random noise
# This cannot estimate conversion rates higher than polling rate

print("Took {:5.3f} s to acquire {:d} samples.".format(total_time, SAMPLES))
print("")
print("Configured:")
print(" Requested = {:5d} sps".format(RATE))
print(" Reported = {:5d} sps".format(ads.data_rate))
print("")
print("Actual:")
print(" Polling Rate = {:8.2f} sps".format(rate_reported))
print(" {:9.2%}".format(rate_reported / RATE))
print(" Repeats = {:5d}".format(repeats))
print(" Conversion Rate = {:8.2f} sps (estimated)".format(rate_actual))