A simple ADC program for the detector
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 Ticker in; 00004 AnalogIn sensor(PA_0); 00005 00006 const int maxReadings = 4096; //define the max samples 00007 00008 float measurementArray[maxReadings]; //define the array 00009 00010 volatile int readingNumber = 0; //volatile so the compiler knows to check if it's changed 00011 00012 char adc_time_stamp[maxReadings]; 00013 00014 //char *time_stamp() 00015 00016 char *time_stamp() 00017 { 00018 char *timestamp = (char *)malloc(sizeof(char) * 16); 00019 time_t ltime; 00020 ltime=time(NULL); 00021 struct tm *tm; 00022 tm=localtime(<time); 00023 00024 sprintf(timestamp,"%04d%02d%02d%02d%02d%02d", tm->tm_year+1900, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); 00025 return timestamp; 00026 } 00027 00028 void update() //function that creates an array from ADC pin values 00029 { 00030 if (readingNumber < maxReadings) 00031 { 00032 measurementArray[readingNumber] = sensor; //populate the array with input from ADC 00033 adc_time_stamp[readingNumber] = *time_stamp(); 00034 readingNumber++; 00035 } 00036 } 00037 00038 main() 00039 { 00040 int nextReading = 0; 00041 in.attach(&update,0.042); //attach update function to the timer and set it to interrupt after 20 mil sec; This can be changed 00042 while (nextReading < maxReadings) 00043 { 00044 if (readingNumber > nextReading) 00045 { 00046 nextReading = readingNumber-1; 00047 nextReading++; 00048 } 00049 } 00050 00051 for (int i=0; i<maxReadings; i++) 00052 { 00053 printf("%f\n", " TimeStamp: %s\n", measurementArray[i], time_stamp()); 00054 } 00055 00056 }
Generated on Wed Jul 20 2022 17:53:31 by
1.7.2