for utkalika use

Dependencies:   mbed

Fork of adc_timer_try7 by Manas Savkoor

main.cpp

Committer:
manants
Date:
2013-01-20
Revision:
1:85acb18c5873
Parent:
0:bf25fa7f7ff8

File content as of revision 1:85acb18c5873:

#include "mbed.h"
#include "adc.h" 
#define     SAMPLE_RATE     150000

#define NUM 200

 
InterruptIn button(p5);
//AnalogIn ain(p20);
DigitalOut pin10(p10);
DigitalOut flash(p11);
ADC adc(SAMPLE_RATE, 1);
LocalFileSystem local("local"); 

float  adcData[4097];
float  test[10];
//FILE *fp = fopen("/local/adc_1.txt", "w");
int i=0;
int k=0;

void flip() {
        int ary[] = {5,
6,
11,
13,
17,
24,
27,
38,
46,
56,
57,
59,
60,
65,
79,
83,
85,
99,
104,
109,
114,
120,
125,
126,
137,
149,
151,
153,
154,
159,
169,
173,
174,
175,
177,
178,
181,
184,
185,
188,
197,
198,
200,
201,
202,
204,
208,
209,
212,
220,
237,
239,
241,
247,
251,
253,
255,
260,
265,
273,
275,
284,
289,
306,
311,
312,
326,
327,
334,
335,
336,
339,
343,
347,
355,
360,
364,
369,
371,
375,
377,
384,
390,
403,
404,
405,
406,
407,
408,
413,
415,
422,
428,
430,
431,
451,
459,
476,
481,
483,
489,
499,
504,
512,
517,
522,
524,
530,
534,
541,
547,
549,
558,
567,
570,
571,
579,
580,
582,
583,
593,
596,
606,
608,
610,
612,
613,
617,
620,
625,
626,
627,
629,
635,
638,
652,
660,
661,
664,
667,
679,
680,
682,
684,
687,
691,
693,
694,
696,
698,
699,
712,
717,
721,
724,
725,
733,
741,
747,
750,
761,
764,
769,
778,
782,
788,
806,
807,
809,
811,
816,
829,
830,
831,
846,
848,
856,
857,
860,
868,
873,
876,
877,
880,
881,
892,
898,
903,
909,
918,
922,
932,
937,
950,
957,
963,
965,
968,
969,
970,
976,
978,
990,
991,
999,
1013,
1018,
1019,
1020,
1032,
1040,
1045,
1048,
1052,
1054,
1067,
1072,
1073,
1077,
1091,
1095,
1096,
1099,
1101,
1102,
1103,
1109,
1111,
1112,
1129,
1144,
1149,
1162,
1174,
1176,
1178,
1183,
1198,
1201,
1210,
1212,
1219,
1223,
1227,
1228,
1243,
1252,
1256,
1258,
1260,
1261,
1264,
1273,
1275,
1291,
1302,
1310,
1314,
1317,
1318,
1320,
1321,
1328,
1331,
1339,
1342,
1345,
1346,
1361,
1368,
1376,
1378,
1380,
1389,
1390,
1398,
1421,
1423,
1443,
1448,
1450,
1462,
1467,
1469,
1470,
1472,
1473,
1475,
1480,
1489,
1495,
1512,
1518,
1525,
1531,
1532,
1544,
1546,
1548,
1560,
1561,
1570,
1578,
1584,
1587,
1592,
1593,
1595,
1600,
1606,
1608,
1615,
1620,
1622,
1630,
1634,
1641,
1644,
1650,
1651,
1658,
1666,
1673,
1681,
1690,
1708,
1718,
1719,
1722,
1725,
1730,
1732,
1739,
1740,
1743,
1747,
1756,
1761,
1767,
1769,
1776,
1783,
1791,
1792,
1794,
1803,
1815,
1818,
1823,
1826,
1830,
1838,
1848,
1856,
1857,
1865,
1870,
1875,
1882,
1883,
1888,
1902,
1907,
1908,
1911,
1918,
1925,
1933,
1952,
1955,
1959,
1960,
1976,
1977,
1979,
1982,
1985,
1988,
1993,
2002,
2010,
2012,
2018,
2021,
2023,
2025,
2027,
2030,
2035,
2039,
2052,
2055,
2058,
2059,
2062,
2073,
2079,
2083,
2085,
2088,
2092,
2093,
2108,
2109,
2110,
2112,
2126,
2131,
2143,
2149,
2152,
2153,
2164,
2172,
2177,
2179,
2181,
2182,
2190,
2194,
2195,
2196,
2209,
2222,
2223,
2227,
2228,
2230,
2237,
2253,
2263,
2265,
2267,
2278,
2280,
2287,
2298,
2304,
2312,
2313,
2328,
2329,
2330,
2332,
2336,
2348,
2351,
2352,
2354,
2356,
2357,
2360,
2368,
2371,
2394,
2396,
2410,
2411,
2415,
2426,
2428,
2435,
2437,
2438,
2444,
2446,
2456,
2460,
2465,
2466,
2469,
2478,
2486,
2489,
2491,
2492,
2497,
2500,
2502,
2504,
2509,
2517,
2528,
2529,
2535,
2538,
2541,
2548,
2551,
2552,
2557,
2558,
2559,
2560,
2565,
2566,
2571,
2584,
2590,
2594,
2597,
2599,
2601,
2611,
2616,
2619,
2624,
2630,
2633,
2635,
2642,
2648,
2651,
2659,
2673,
2674,
2680,
2682,
2688,
2694,
2696,
2699,
2703,
2711,
2721,
2731,
2733,
2744,
2746,
2747,
2769,
2771,
2782,
2786,
2793,
2797,
2799,
2803,
2815,
2833,
2837,
2851,
2852,
2854,
2855,
2856,
2867,
2871,
2873,
2874,
2876,
2885,
2888,
2894,
2896,
2900,
2902,
2907,
2918,
2919,
2922,
2925,
2927,
2938,
2939,
2940,
2949,
2954,
2959,
2961,
2963,
2974,
2983,
2986,
2987,
2989,
2991,
3005,
3011,
3012,
3013,
3024,
3029,
3033,
3036,
3040,
3041,
3050,
3052,
3057,
3058,
3062,
3070,
3075,
3079,
3080,
3083,
3088,
3089,
3091,
3092,
3093,
3094,
3101,
3105,
3115,
3119,
3124,
3128,
3130,
3139,
3154,
3159,
3174,
3177,
3180,
3187,
3188,
3191,
3204,
3213,
3221,
3227,
3237,
3242,
3247,
3252,
3255,
3264,
3274,
3286,
3294,
3300,
3306,
3315,
3317,
3320,
3321,
3328,
3329,
3331,
3337,
3342,
3345,
3362,
3363,
3375,
3377,
3387,
3389,
3394,
3398,
3400,
3402,
3404,
3408,
3413,
3428,
3440,
3442,
3444,
3446,
3449,
3453,
3458,
3460,
3462,
3467,
3469,
3484,
3487,
3489,
3491,
3493,
3494,
3496,
3499,
3501,
3504,
3507,
3513,
3515,
3516,
3521,
3522,
3526,
3527,
3530,
3536,
3546,
3549,
3552,
3556,
3559,
3565,
3568,
3572,
3574,
3576,
3581,
3588,
3590,
3591,
3593,
3595,
3616,
3620,
3622,
3627,
3628,
3634,
3635,
3643,
3645,
3659,
3665,
3680,
3698,
3702,
3704,
3710,
3719,
3724,
3731,
3741,
3743,
3744,
3754,
3757,
3760,
3764,
3770,
3772,
3780,
3782,
3786,
3788,
3797,
3814,
3828,
3836,
3842,
3848,
3853,
3868,
3869,
3871,
3882,
3889,
3893,
3899,
3902,
3914,
3923,
3924,
3930,
3931,
3936,
3942,
3943,
3950,
3951,
3953,
3963,
3970,
3976,
3985,
3996,
4003,
4009,
4013,
4016,
4023,
4025,
4032,
4035,
4045,
4046,
4053,
4060,
4067,
4068,
4071,
4081,
4083}
;   
//        int *a;
        
        if(i<4097){


            if (k < 4097) {
            if (i == ary[k]){
            adc.select(p20);
            adc.start();            // Start ADC conversion
            while(!adc.done(p20));      // Wait for it to complete
            adcData[i] = adc.read(p20);  // Get ADC data.
//          adcData = ain;
            pin10 = !pin10;     // Invert test pin.
//          fprintf(fp, "%3.4f\n",adcData*3.3);
            k++;
              } //ary
              } //k
            }//i
//      else {
//          fclose(fp);
//           }
        i++;
        }//isr

int main() {
//    float  adcData;
//    adcData = 1.0;
    FILE *fp = fopen("/local/adc_2.txt", "w");
//    FILE *fp1 = fopen("/local/adc_3.txt", "w");
    int j = 0;
    pin10 = 1;
        adc.setup(p20,1);       // Set up ADC on pin 20
//        adc.select(p20);        // Measure pin 20
   
//       FILE *fp = fopen("/local/adc_1.txt", "w");

    button.rise(&flip);  // attach the address of the flip function to the rising edge
    while(1) {           // wait around, interrupts will interrupt this!

//        pin10 = 1;
//        fprintf(fp, "%f\n",adcData);
           if (i>=4097) {
           for (j = 0; j<785; j++) {
                   fprintf(fp, "i = %d, j = %d, d = %3.4f\n", i, j, adcData[j]*3.3);
           }
           fclose(fp);
//           for (j = 0; j<10; j++) {
//                   fprintf(fp1, "i = %d, j = %d, d = %3.4f\n", i, j, test[j]*3.3);
//           }
 //          fclose(fp1);
           }
           else {

            flash = !flash;
            
        wait(0.25);
        }
//        i++;
//        if(i == 200)
//        {
//            fclose(fp);
 //       }
    }
    
}