Das einzige, das ich noch nicht sicher weiß ist, wie viel Zeit ich zwischen der Umschaltung des ADC-Kanals und dem Start der nächsten AD-Wandlung wirklich brauche.
Beim Arduino (also ATmega328P statt "Deinem" 128) sagt die Arduino Reference "It takes about 0.1 ms to read an analog input".
Gemessen habe ich - ohne jede Optimierung - 120 us pro Messung.
[Blödsinn gelöscht, ich sollte nicht so kurz vor dem Mittagessen posten
]
Wenn Du den Test machst, dann häng die beiden Analogeingänge under Test an stark unterschiedliche Spannungen, aber aben
nicht an die Versorgungsspannung, sondern in einen mittelohmigen Spannungsteiler:
/*
ADCcrosstalk - analyse ADC cross-talk during channel switching.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as published
by the Free Software Foundation, provided that the copyright notice remains
intact even in future versions. See the file LICENSE for details.
If you use this program (or any part of it) in another application,
note that the resulting application becomes also GPL. In other words,
GPL is a "contaminating" license.
This program is distributed in the hope that it will be useful,but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
--------------------------------------------------------------------
Modification/history:
2016-07-22, first operational version (JHa)
2016-07-23, better data structures, better loop, no more printing in loop (JHa)
*/
#include "QuickStats.h"
const int NCHAN = 2;
const int NSAMP = 10; // <80 otherwise you'll have memory problems
const char do_plot = 1 ;
void setup() {
pinMode(A0, INPUT);
pinMode(A1, INPUT);
Serial.begin(115200);
Serial.print("Init, N=");
Serial.println(NSAMP);
}
/*
Read two analog inputs, print the result to the serial monitor.
Note: feed the two inputs with very different (!) voltages
(NOT equal to the Arduino supply rails)
*/
void loop() {
int dly[] = { 0, 5, 10, 25 };
int wait[] = { 0, 5, 10, 25 };
int ndly = sizeof(dly) / sizeof(dly[0]);
int nwait = sizeof(wait) / sizeof(wait[0]);
int i, j;
for (j = 0; j < nwait; j++)
for (i = 0; i < ndly; i++)
run_test (dly
, wait[j]);
Serial.println("\n========== End of loop ==========\n\n");
}
void run_test (int dly, int wait) {
float ch[NCHAN][NSAMP]; // arrays to hold data points. We use float for the stat library
QuickStats stat[NCHAN];
int i;
String s = "";
s = String("\n# N=" + String(NSAMP, DEC) + ", " + String(wait, DEC) + " ms before, " + String(dly, DEC) + " ms between channels");
Serial.println(s);
for (i = 0; i < NSAMP; i++) {
if (wait) // time to settle
delay(wait);
ch[0] = analogRead(A0);
if (dly) // time between channels
delay(dly);
ch[1] = analogRead(A1);
}
/* only print *after* the loop, since all printing *in* the loop
will slow down data acquisition and falsify results
*/
if (do_plot) { // print only if data are desired
for (i = 0; i < NSAMP; i++) {
Serial.print(i);
Serial.print("\t");
Serial.print(ch[0]);
Serial.print("\t");
Serial.println(ch[1]);
}
}
if (do_plot) {
/* show statistics */
Serial.print("Avg (StdDev): ");
for (i = 0; i < NCHAN; i++)
{
Serial.print(stat.average(ch, NSAMP));
Serial.print(" (");
Serial.print(stat.stdev(ch, NSAMP));
Serial.print(")\t");
}
Serial.print("\nMin/Max: ");
for (i = 0; i < NCHAN; i++)
{
Serial.print(stat.minimum(ch, NSAMP));
Serial.print("/");
Serial.print(stat.maximum(ch, NSAMP));
Serial.print("\t");
}
Serial.print("\nMode: ");
for (i = 0; i < NCHAN; i++)
{
Serial.print(stat.mode(ch, NSAMP));
Serial.print("\t");
}
}
Serial.println("");
}