Working code for pc app 12/01/2018 commit
Dependencies: mbed MS5607 mbed-dsp
Fork of Turrentine_Code by
Diff: main.cpp
- Revision:
- 2:3d3e21c907e4
- Parent:
- 1:ab3dacbfcde6
- Child:
- 3:c80aa39db5bb
- Child:
- 6:8f16c432964d
--- a/main.cpp Fri Jan 12 13:17:35 2018 +0000 +++ b/main.cpp Fri Jan 12 15:40:32 2018 +0000 @@ -2,7 +2,7 @@ #define M_PI 3.14159265358979323846 -#define N_SAMPLES 500 +#define N_SAMPLES 1024 //mbed class def Serial pc(USBTX, USBRX); // tx, rx @@ -76,12 +76,12 @@ int main() { - printf("Turrentine\n"); - pc.baud(115200); motorOn = 0; motorOn.period_ms(10); + printf("Turrentine\n"); + // Chip must be deselected cs = 1; @@ -99,7 +99,7 @@ cs = 1; wait_ms(100); cs = 1; - + printf("Read cal data\n"); //read cal data values from device into program @@ -113,7 +113,27 @@ //Put data into 16bit unsigned int in calData array calData[i] = buffer16[1]<<8 | buffer16[2]; } - + + + printf("Pump On\n"); + + //turn pump on + motorOn.write(duty); + + + //dummy samples to wait for sensor response to stabilise + int a =0; + while(a < 10000) { + cs = 0; + spi.write(&D1conv256, 1, buffer16, 1); + wait_us(500); + cs = 1; + cs = 0; + spi.write(&readADC, 1, pressBuffer, 4); + cs = 1; + a++; + } + printf("Start loop\n"); //display calibration values to check against datasheet @@ -143,14 +163,8 @@ temp = tempBuffer[1]<<16 | tempBuffer[2]<<8 | tempBuffer[3]; //press = pressBuffer[1]<<16 | pressBuffer[2]<<8 | pressBuffer[3]; - printf("Pump On\n"); - - //turn pump on - motorOn.write(duty); - - //dummy samples to wait for sensor response to stabilise int a =0; - while(a < 10000) { + while(a < 5000) { cs = 0; spi.write(&D1conv256, 1, buffer16, 1); wait_us(500); @@ -160,7 +174,7 @@ cs = 1; a++; } - + printf("Start Measurement\n"); //double cumsum = 0; @@ -188,8 +202,8 @@ //stop motor and timer t.stop(); - motorOn.write(0); - + //motorOn.write(0); + printf("Stop Measurement\n"); //calc temperature @@ -201,12 +215,14 @@ //printf("avg %f\n\r", avg); //output date to PC - printf("C1: %hu\nC2: %hu\nC3: %hu\nC4: %hu\nC5: %hu\nC6: %hu\n", calData[0], calData[1], calData[2], calData[3], calData[4], calData[5]); + 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++) { - printf("%04d: %d\n", i, pData[i]); + printf("$%d\n", pData[i]); } + printf("$COMPLETE\n"); + /* //for crossing detection bool cflag1 = (avg > pData[0]); @@ -216,7 +232,7 @@ 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) {