From 62b39f5e3e0650611c5e20321f018898e0c8076d Mon Sep 17 00:00:00 2001 From: WizardTim <43670403+WizardTim@users.noreply.github.com> Date: Tue, 1 Dec 2020 16:14:48 +1000 Subject: [PATCH 1/5] More statistics to detect bad/over polling --- examples/ads1x15_fast_read.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/examples/ads1x15_fast_read.py b/examples/ads1x15_fast_read.py index 1e499b8..e585415 100644 --- a/examples/ads1x15_fast_read.py +++ b/examples/ads1x15_fast_read.py @@ -22,6 +22,8 @@ ads.mode = Mode.CONTINUOUS ads.data_rate = RATE +repeats = 0 + data = [None] * SAMPLES start = time.monotonic() @@ -29,9 +31,26 @@ # Read the same channel over and over for i in range(SAMPLES): data[i] = chan0.value + 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: cannot detect 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)) + From 9e7e017014cd50802432f1c850b27acbe31ed899 Mon Sep 17 00:00:00 2001 From: WizardTim <43670403+WizardTim@users.noreply.github.com> Date: Tue, 1 Dec 2020 16:32:00 +1000 Subject: [PATCH 2/5] Expand comments --- examples/ads1x15_fast_read.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/ads1x15_fast_read.py b/examples/ads1x15_fast_read.py index e585415..5e68498 100644 --- a/examples/ads1x15_fast_read.py +++ b/examples/ads1x15_fast_read.py @@ -31,6 +31,7 @@ # 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 @@ -40,7 +41,7 @@ rate_reported = SAMPLES / total_time rate_actual = (SAMPLES-repeats) / total_time -# NOTE: cannot detect conversion rates higher than polling rate +# 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("") From 2de02e0e36870bf33c3c892d8d4e50a5a41f50a6 Mon Sep 17 00:00:00 2001 From: WizardTim <43670403+WizardTim@users.noreply.github.com> Date: Wed, 2 Dec 2020 09:57:15 +1000 Subject: [PATCH 3/5] Reformat code with psf/black --- examples/ads1x15_fast_read.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ads1x15_fast_read.py b/examples/ads1x15_fast_read.py index 5e68498..a298aec 100644 --- a/examples/ads1x15_fast_read.py +++ b/examples/ads1x15_fast_read.py @@ -32,7 +32,7 @@ for i in range(SAMPLES): data[i] = chan0.value # Detect repeated values due to over polling - if data[i] == data[i-1]: + if data[i] == data[i - 1]: repeats += 1 @@ -40,7 +40,7 @@ total_time = end - start rate_reported = SAMPLES / total_time -rate_actual = (SAMPLES-repeats) / 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)) From ee9eb68a1012fd44bc84520a4ec4e8b72189f4ea Mon Sep 17 00:00:00 2001 From: WizardTim <43670403+WizardTim@users.noreply.github.com> Date: Wed, 2 Dec 2020 10:04:44 +1000 Subject: [PATCH 4/5] Fix EOF for psf/black --- examples/ads1x15_fast_read.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/ads1x15_fast_read.py b/examples/ads1x15_fast_read.py index a298aec..335c68c 100644 --- a/examples/ads1x15_fast_read.py +++ b/examples/ads1x15_fast_read.py @@ -54,4 +54,3 @@ print(" {:9.2%}".format(rate_reported / RATE)) print(" Repeats = {:5d}".format(repeats)) print(" Conversion Rate = {:8.2f} sps (estimated)".format(rate_actual)) - From 1f94dafcb1880b60b33a16bb859d25b5a259bb39 Mon Sep 17 00:00:00 2001 From: WizardTim <43670403+WizardTim@users.noreply.github.com> Date: Wed, 2 Dec 2020 10:22:23 +1000 Subject: [PATCH 5/5] Wrap long line for psf/black --- examples/ads1x15_fast_read.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/ads1x15_fast_read.py b/examples/ads1x15_fast_read.py index 335c68c..801a2c7 100644 --- a/examples/ads1x15_fast_read.py +++ b/examples/ads1x15_fast_read.py @@ -41,7 +41,8 @@ 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 +# 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("")