Program to benchmark AnalogIn performance

Dependencies:   mbed

Fork of ADC_spikes by Chris Styles

Revision:
2:4c61969f2207
Parent:
1:bdd134268a52
Child:
3:4c45267b653d
--- a/main.cpp	Fri Dec 02 10:04:15 2011 +0000
+++ b/main.cpp	Fri Dec 02 11:42:51 2011 +0000
@@ -18,6 +18,7 @@
 int num_1024;
 int num_2048;
 
+
 int main() {
 
     pc.baud(115200);
@@ -35,26 +36,28 @@
     num_1024 = 0;
     num_2048 = 0;
 
-
 // Take the average over 500,000 samples
-// This is because teh bias to 1.65v has a tolerance
+// This is because the bias to 1.65v has a tolerance
     float AVERAGE = 0.5;
 
     pc.printf("Taking an average over %d samples\n",NUM_SAMPLES);
     while (num_samples < NUM_SAMPLES) {
         float r = ain.read();
 
-        if ((r > 0.49) && (r < 0.51)) {
-            AVERAGE = (AVERAGE + r) /2.0;
+        if ((r > 0.45) && (r < 0.55)) {
+            AVERAGE += r;
             num_samples++;
         }
     }
+    
+    AVERAGE /= NUM_SAMPLES;
+    
     num_samples = 0;
     pc.printf("Average = %f\n",AVERAGE);
 
-    
+
 // Now start sampling series of 500,000
-// acculumating the errors seen in each range 
+// acculumating the errors seen in each range
     while (1) {
 
         for (int i = 0; i < NUM_SAMPLES ; i++) {