Working code for pc app 12/01/2018 commit
Dependencies: mbed MS5607 mbed-dsp
Fork of Turrentine_Code by
Diff: main.cpp
- Revision:
- 6:8f16c432964d
- Parent:
- 2:3d3e21c907e4
--- a/main.cpp Fri Jan 12 15:40:32 2018 +0000 +++ b/main.cpp Tue Feb 13 11:01:34 2018 +0000 @@ -136,32 +136,21 @@ printf("Start loop\n"); - //display calibration values to check against datasheet - //program loop while(1) { + //read temerature value cs = 0; spi.write(&D2conv4096, 1, buffer16, 1); wait_ms(10); cs = 1; cs = 0; - spi.write(&readADC, 1, tempBuffer, 4); cs = 1; - //read pressure value - /*cs = 0; - spi.write(&D1conv512, 1, buffer16, 1); - wait_ms(2); - cs = 1; cs = 0; - - spi.write(&readADC, 1, pressBuffer, 4); - cs = 1;*/ - //write values from buffers to program variables temp = tempBuffer[1]<<16 | tempBuffer[2]<<8 | tempBuffer[3]; - //press = pressBuffer[1]<<16 | pressBuffer[2]<<8 | pressBuffer[3]; + int a =0; while(a < 5000) { @@ -176,11 +165,10 @@ } printf("Start Measurement\n"); - - //double cumsum = 0; - + t.reset(); t.start(); + //loop values for (int x = 0; x < N_SAMPLES; x++) { cs = 0; @@ -191,7 +179,7 @@ cs = 0; if (x > 0) { pData[x-1] = pressBuffer[1]<<16 | pressBuffer[2]<<8 | pressBuffer[3]; - //cumsum = cumsum + pData[x-1]; + } spi.write(&readADC, 1, pressBuffer, 4); tData[x] = t.read_us(); @@ -200,9 +188,8 @@ pData[N_SAMPLES - 1] = pressBuffer[1]<<16 | pressBuffer[2]<<8 | pressBuffer[3]; - //stop motor and timer + //stop timer t.stop(); - //motorOn.write(0); printf("Stop Measurement\n"); @@ -210,11 +197,8 @@ calcT(temp, calData); long long sum = 0; - //float avg = calcP(temp, cumsum/(nsample-1), calData); - //printf("avg %f\n\r", avg); - - //output date to PC + //output data to PC printf("$CAL %hu %hu %hu %hu %hu %hu\n", calData[0], calData[1], calData[2], calData[3], calData[4], calData[5]); for(int i = 0; i < N_SAMPLES; i++) { @@ -223,73 +207,6 @@ printf("$COMPLETE\n"); - /* - //for crossing detection - bool cflag1 = (avg > pData[0]); - bool cflag2 = (avg > pData[1]); - int numcross = 0; - int lastcrosspoint = 0; - unsigned int crosstart; - unsigned int crossend; - float freq = 0; - - //smooth data array 20 sample size - for (int y=0; y< nsample-1; y++) { - if (9< y && y <nsample-10) { - sum = 0; - for (int z=0; z<20; z++) { - sum = sum + pData[y-10+z]; - } - - spData[y] = (float) calcP(temp, sum/20, calData); - - //detect avg crossings for frequency calc - if (y>10) { - cflag2 = (avg > spData[y]); - cflag1 = (avg > spData[y-1]); - - if (cflag1 != cflag2) { - if(lastcrosspoint<=(y-10)) { - numcross++; - lastcrosspoint = y; - - if (numcross == 1) { - crosstart = tData[y]; - } - - crossend = tData[y]; - } - } - } - //calc pressure & display list - //printf("%d\t%d\t%d\n\r", tData[y], calcP(temp, spData[y], calData), calcP(temp, pData[y], calData)); - printf("%d\t%f\n\r", tData[y],spData[y]); - } else if (10> y || y >nsample-10) { - spData[y] = (float) calcP(temp, pData[y], calData); - } - - - } - - printf("numcross = %d\n\r", numcross); - printf("crosstart = %d\n\r", crosstart); - printf("crossend = %d\n\r", crossend); - - freq = (1e6 *numcross)/(2*(crossend - crosstart)); - printf("frequency = %f\n\r", freq); - - for (int z=0; z< nsample-1; z++) { - - spData[z] = spData[z] -avg; - } - - printf("Repeat Blockage Test?\n\rPress Enter to continue\n\r"); - - while(1) { - if (pc.getc() != 0) { - break; - } - } - */ + } } \ No newline at end of file