ADC
ADC copied to clipboard
add adc_histogram example
I find your library very useful. I wanted to analyze how noisy the ADC is under different configurations, so I made this program using your library to plot a histogram of the distribution of results from continuous read. Each possible configuration runs for 1 second and prints the resulting histogram as well as summary statistics.
For example, if I use a stable voltage source going into both ADC inputs, then my program prints this output (full file: results_both_all-configs.txt) for the most noisy configuration of ADC settings:
ADC0 config: BitDepth=12, averaging=1, ADC_CONVERSION_SPEED=ADACK_20, ADC_SAMPLING_SPEED=VERY_HIGH_SPEED.
716226 measurements, at a rate of 1.396 microsPerMeasurement or 716.23 kHz.
bin [index] count percent of total measurements
0.2371 [971]: 126 = 0.02%
0.2374 [972]: 712 = 0.10%
0.2376 [973]: 282 = 0.04%
0.2379 [974]: 637 = 0.09%
0.2381 [975]: 117 = 0.02%
0.2383 [976]: 1846 = 0.26%
0.2386 [977]: 2306 = 0.32%
0.2388 [978]: 11262 == 1.57%
0.2391 [979]: 5042 = 0.70%
0.2393 [980]: 8019 == 1.12%
0.2396 [981]: 7939 == 1.11%
0.2398 [982]: 9151 == 1.28%
0.2400 [983]: 42873 ====== 5.99%
0.2403 [984]: 42546 ====== 5.94%
0.2405 [985]: 123943 ================== 17.31%
0.2408 [986]: 225235 ================================ 31.45%
0.2410 [987]: 117773 ================= 16.44%
0.2413 [988]: 39538 ====== 5.52%
0.2415 [989]: 11303 == 1.58%
0.2418 [990]: 8007 == 1.12%
0.2420 [991]: 1481 = 0.21%
0.2422 [992]: 6437 = 0.90%
0.2425 [993]: 6516 = 0.91%
0.2427 [994]: 6568 = 0.92%
0.2430 [995]: 4092 = 0.57%
0.2432 [996]: 4530 = 0.63%
0.2435 [997]: 2530 = 0.35%
0.2437 [998]: 2160 = 0.30%
0.2440 [999]: 1859 = 0.26%
0.2442 [1000]: 1163 = 0.16%
0.2444 [1001]: 1294 = 0.18%
0.2447 [1002]: 1720 = 0.24%
Summary:
range: 0.019536020 over 80 bins from [962] to [1041]
mode: 0.240781441 [986]
mean: 0.240923390
var: 0.000001651
stdDev: 0.001285070
I'm making this PR cause others might find this useful as a test example and to help them evaluate what noise-vs-speed tradeoff works best for their application.