SonicMEMS@Cornell
/
mbed_ADC_INPUT
Code to transfer 400 data points of a sine wave to a MATLAB program.
Revision 0:f3fb19f954b4, committed 2014-07-10
- Comitter:
- MCubed4
- Date:
- Thu Jul 10 22:20:51 2014 +0000
- Commit message:
- ADC input code for sine wave creation
Changed in this revision
diff -r 000000000000 -r f3fb19f954b4 USBDevice.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Thu Jul 10 22:20:51 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/USBDevice/#0c6524151939
diff -r 000000000000 -r f3fb19f954b4 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jul 10 22:20:51 2014 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" + +Serial pc(USBTX, USBRX); //creates serial line to talk with matlab +BusIn ADC(p20, p19, p18, p17, p16, p15, p14, p13); //creates a bus input to take in ADC value +int dataIn[400]; //data storage array +DigitalOut myled(LED1); //heartbeat led for data acquisition +int buf[128]; //code execution data array + +int main(){ + if (pc.readable()) { + //WAV 0 END \n \0 + //use buf[3] as a 0 just as a parity bit + pc.gets(buf, 16); + if ((buf[0] == 'W')&&(buf[1] == 'A')&&(buf[2] == 'V')&&(buf[4] == 'E')&&(buf[5] == 'N')&&(buf[6] == 'D')) { + ADC.mode(PullNone); //sets the mode to pull none + for(int i = 0; i < 400; i++){ //acquires ADC values for 400 data points with 2 ms delays + myled = 1; + wait(0.001); + myled = 0; + wait(0.001); //gives delay prior to each reading to ensure different values + dataIn[i] = ADC.read(); + } + for(int i = 0; i < 400; i++){ //prints data point values to computer + printf("ADC value is %d\n\r", dataIn[i]); + } + + } // end of if( buffer read) + } // end of if(pc.readable()) + + return 1; + +} \ No newline at end of file
diff -r 000000000000 -r f3fb19f954b4 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jul 10 22:20:51 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae \ No newline at end of file