for utkalika use

Dependencies:   mbed

Fork of adc_timer_try7 by Manas Savkoor

main.cpp

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

File content as of revision 1:b53c17a4b4b0:

#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[] = {1,
2,
4,
9,
10,
12,
13,
15,
18,
20,
23,
24,
36,
39,
57,
65,
66,
71,
73,
75,
82,
85,
95,
114,
116,
118,
122,
125,
126,
130,
132,
137,
141,
153,
154,
158,
167,
168,
173,
191,
199,
203,
206,
207,
215,
222,
225,
226,
243,
245,
251,
260,
262,
263,
276,
277,
285,
288,
289,
293,
297,
307,
308,
313,
315,
318,
323,
324,
334,
341,
342,
348,
350,
359,
363,
368,
370,
385,
386,
391,
392,
393,
414,
416,
430,
432,
434,
444,
451,
470,
484,
497,
498,
503,
507,
516,
527,
528,
535,
561,
563,
567,
572,
576,
579,
580,
582,
588,
601,
603,
606,
607,
608,
610,
612,
615,
618,
620,
629,
630,
633,
637,
639,
663,
664,
671,
679,
683,
684,
685,
686,
693,
700,
702,
709,
711,
714,
719,
728,
731,
741,
747,
753,
765,
768,
793,
800,
814,
815,
845,
852,
889,
895,
901,
908,
915,
920,
936,
937,
949,
953,
957,
961,
972,
974,
976,
990,
992,
994,
997,
1000,
1003,
1014,
1018,
1020,
1033,
1034,
1036,
1045,
1046,
1050,
1051,
1053,
1058,
1059,
1067,
1070,
1071,
1073,
1090,
1092,
1094,
1104,
1105,
1118,
1120,
1126,
1136,
1143,
1144,
1146,
1149,
1150,
1154,
1158,
1161,
1164,
1173,
1175,
1177,
1192,
1196,
1200,
1203,
1206,
1208,
1215,
1218,
1229,
1231,
1239,
1246,
1249,
1250,
1253,
1255,
1274,
1275,
1277,
1278,
1280,
1281,
1290,
1291,
1292,
1295,
1296,
1303,
1304,
1308,
1309,
1310,
1315,
1316,
1320,
1323,
1325,
1334,
1335,
1339,
1345,
1352,
1363,
1366,
1378,
1379,
1381,
1388,
1391,
1394,
1395,
1396,
1399,
1403,
1408,
1419,
1428,
1437,
1439,
1453,
1456,
1458,
1465,
1466,
1467,
1478,
1481,
1484,
1491,
1497,
1524,
1525,
1535,
1537,
1548,
1549,
1553,
1554,
1557,
1559,
1575,
1576,
1577,
1608,
1609,
1613,
1614,
1626,
1629,
1633,
1653,
1654,
1655,
1660,
1666,
1667,
1672,
1674,
1682,
1683,
1692,
1696,
1697,
1701,
1703,
1707,
1711,
1721,
1725,
1732,
1735,
1742,
1746,
1747,
1751,
1755,
1760,
1766,
1767,
1768,
1771,
1778,
1779,
1781,
1787,
1793,
1804,
1808,
1810,
1813,
1816,
1817,
1821,
1825,
1834,
1852,
1853,
1854,
1863,
1868,
1874,
1875,
1876,
1883,
1888,
1891,
1894,
1898,
1900,
1906,
1909,
1911,
1915,
1919,
1920,
1921,
1924,
1926,
1947,
1948,
1953,
1954,
1962,
1964,
1970,
1971,
1972,
1984,
1986,
1987,
1995,
2002,
2008,
2012,
2015,
2022,
2024,
2026,
2029,
2031,
2033,
2040,
2043,
2045,
2047,
2053,
2055,
2056,
2065,
2067,
2071,
2076,
2077,
2084,
2090,
2095,
2096,
2098,
2101,
2103,
2107,
2110,
2113,
2114,
2120,
2125,
2131,
2141,
2147,
2148,
2165,
2167,
2171,
2183,
2185,
2191,
2195,
2200,
2202,
2208,
2216,
2218,
2222,
2226,
2231,
2232,
2243,
2244,
2254,
2256,
2259,
2262,
2265,
2269,
2272,
2280,
2282,
2285,
2302,
2312,
2313,
2323,
2326,
2329,
2332,
2346,
2347,
2351,
2353,
2372,
2374,
2376,
2377,
2378,
2387,
2393,
2400,
2401,
2404,
2407,
2412,
2417,
2419,
2422,
2428,
2434,
2440,
2449,
2451,
2456,
2463,
2472,
2475,
2490,
2492,
2501,
2508,
2509,
2510,
2511,
2512,
2521,
2524,
2528,
2534,
2539,
2544,
2551,
2553,
2555,
2556,
2559,
2561,
2575,
2578,
2581,
2583,
2595,
2597,
2599,
2600,
2603,
2605,
2613,
2618,
2620,
2622,
2624,
2625,
2630,
2633,
2661,
2664,
2667,
2670,
2681,
2683,
2686,
2687,
2689,
2692,
2693,
2694,
2698,
2705,
2709,
2714,
2715,
2716,
2719,
2721,
2722,
2726,
2732,
2735,
2742,
2747,
2752,
2753,
2754,
2757,
2761,
2773,
2777,
2788,
2790,
2803,
2808,
2809,
2820,
2825,
2826,
2827,
2828,
2831,
2833,
2835,
2836,
2843,
2848,
2849,
2851,
2856,
2859,
2881,
2882,
2885,
2887,
2888,
2892,
2898,
2899,
2903,
2906,
2909,
2917,
2921,
2929,
2930,
2932,
2936,
2940,
2943,
2948,
2950,
2960,
2963,
2964,
2978,
2980,
2982,
2987,
2991,
2993,
3000,
3003,
3011,
3016,
3021,
3028,
3034,
3039,
3050,
3052,
3057,
3071,
3074,
3086,
3087,
3093,
3095,
3101,
3105,
3106,
3115,
3117,
3124,
3127,
3128,
3132,
3140,
3141,
3154,
3157,
3159,
3160,
3168,
3178,
3182,
3185,
3190,
3192,
3193,
3194,
3200,
3204,
3205,
3208,
3211,
3215,
3218,
3227,
3236,
3239,
3243,
3257,
3263,
3269,
3276,
3283,
3285,
3290,
3292,
3297,
3299,
3308,
3310,
3311,
3315,
3317,
3321,
3322,
3324,
3327,
3328,
3334,
3335,
3338,
3348,
3355,
3365,
3370,
3379,
3385,
3386,
3387,
3392,
3395,
3397,
3406,
3408,
3410,
3419,
3422,
3429,
3434,
3448,
3449,
3457,
3463,
3466,
3469,
3492,
3493,
3497,
3498,
3505,
3508,
3511,
3523,
3524,
3525,
3527,
3530,
3538,
3544,
3545,
3555,
3558,
3561,
3563,
3569,
3572,
3575,
3580,
3583,
3594,
3596,
3597,
3601,
3615,
3616,
3619,
3621,
3624,
3632,
3635,
3638,
3641,
3644,
3647,
3660,
3666,
3667,
3672,
3673,
3678,
3685,
3701,
3702,
3703,
3706,
3710,
3714,
3715,
3721,
3724,
3725,
3726,
3744,
3749,
3753,
3756,
3757,
3759,
3767,
3776,
3778,
3779,
3782,
3784,
3788,
3802,
3805,
3808,
3816,
3834,
3836,
3838,
3842,
3851,
3856,
3860,
3867,
3872,
3877,
3882,
3894,
3896,
3898,
3901,
3902,
3905,
3906,
3913,
3914,
3917,
3918,
3919,
3920,
3925,
3926,
3928,
3932,
3936,
3940,
3941,
3946,
3952,
3954,
3957,
3958,
3964,
3966,
3981,
3983,
3984,
3991,
3992,
4000,
4002,
4009,
4011,
4013,
4015,
4020,
4024,
4026,
4028,
4042,
4048,
4060,
4061,
4069,
4073,
4086,
4087,
4092}
;   
//        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<838; 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);
 //       }
    }
    
}