To test the analog input noise using potential divider rule. {{/media/uploads/yoonghm/analog_noise.jpg}}

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
yoonghm
Date:
Tue Dec 06 16:23:00 2011 +0000
Commit message:
Initial version

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Dec 06 16:23:00 2011 +0000
@@ -0,0 +1,71 @@
+/*
+ * The program try to test the phenomenon as mentioned in
+ * http://mbed.org/users/chris/notebook/Getting-best-ADC-performance/
+ *
+ *  a) Unused ADC pins are either tied to ground, or declared as DigitalOut
+ *  b) Quality of signal source, including low noise design techniques such 
+ *     as filtering. 
+ *  c) Reduce debugging communication via USB
+ */
+ 
+#include "mbed.h"
+
+#define   SSIZE 100
+
+AnalogIn  ain(p20);
+BusOut    unused(p15,p16,p17,p18,p19);  // Make unused analog pin to DigitalOut
+
+float     value[SSIZE];
+float     max;
+float     min;
+double    itg;
+
+void printNow()
+{
+  time_t    s;
+  char      buffer[20];
+
+  s = time(NULL);
+  strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", localtime(&s));
+  printf("%s\n", buffer);
+}
+
+void printSecNow()
+{
+  time_t    s;
+  s = time(NULL);
+  printf("%d\n", s);
+}
+
+int main() 
+{
+  set_time(1323180910);
+
+  while (1)
+  {
+    //printNow();
+    printf("\n-----------------\n");
+    printSecNow();
+    max = itg = 0.0;
+    min = 3.3;
+    // Sample before printing to avoid debug communucation
+    for (int i=0; i<SSIZE; i++)
+    {
+      value[i] = ain;
+      if (value[i] > max) max = value[i];
+      if (value[i] < min) min = value[i];
+      itg += value[i];
+    }
+    printSecNow();
+    
+    // Now print out
+    for (int i=0; i<SSIZE; i++)
+    {
+      printf("%0.3f ", value[i]*3.3);  
+    }
+    printf("\n");
+    printf("max=%0.3f, min=%0.3f, avg=%0.3f\n", 
+           max*3.3, min*3.3, 3.3*itg/SSIZE);
+    wait(10);
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Dec 06 16:23:00 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7110ebee3484