To test the analog input noise using potential divider rule. {{/media/uploads/yoonghm/analog_noise.jpg}}
main.cpp
00001 /* 00002 * The program try to test the phenomenon as mentioned in 00003 * http://mbed.org/users/chris/notebook/Getting-best-ADC-performance/ 00004 * 00005 * a) Unused ADC pins are either tied to ground, or declared as DigitalOut 00006 * b) Quality of signal source, including low noise design techniques such 00007 * as filtering. 00008 * c) Reduce debugging communication via USB 00009 */ 00010 00011 #include "mbed.h" 00012 00013 #define SSIZE 100 00014 00015 AnalogIn ain(p20); 00016 BusOut unused(p15,p16,p17,p18,p19); // Make unused analog pin to DigitalOut 00017 00018 float value[SSIZE]; 00019 float max; 00020 float min; 00021 double itg; 00022 00023 void printNow() 00024 { 00025 time_t s; 00026 char buffer[20]; 00027 00028 s = time(NULL); 00029 strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", localtime(&s)); 00030 printf("%s\n", buffer); 00031 } 00032 00033 void printSecNow() 00034 { 00035 time_t s; 00036 s = time(NULL); 00037 printf("%d\n", s); 00038 } 00039 00040 int main() 00041 { 00042 set_time(1323180910); 00043 00044 while (1) 00045 { 00046 //printNow(); 00047 printf("\n-----------------\n"); 00048 printSecNow(); 00049 max = itg = 0.0; 00050 min = 3.3; 00051 // Sample before printing to avoid debug communucation 00052 for (int i=0; i<SSIZE; i++) 00053 { 00054 value[i] = ain; 00055 if (value[i] > max) max = value[i]; 00056 if (value[i] < min) min = value[i]; 00057 itg += value[i]; 00058 } 00059 printSecNow(); 00060 00061 // Now print out 00062 for (int i=0; i<SSIZE; i++) 00063 { 00064 printf("%0.3f ", value[i]*3.3); 00065 } 00066 printf("\n"); 00067 printf("max=%0.3f, min=%0.3f, avg=%0.3f\n", 00068 max*3.3, min*3.3, 3.3*itg/SSIZE); 00069 wait(10); 00070 } 00071 }
Generated on Mon Jul 25 2022 23:20:52 by 1.7.2