Jim Cooke
/
Hat_Board_v5_1
Slight Mod
Fork of Hat_Board_v5 by
Revision 5:ef42f4648198, committed 2014-04-03
- Comitter:
- drnow
- Date:
- Thu Apr 03 10:56:37 2014 +0000
- Parent:
- 4:e9df42113893
- Commit message:
- Slight mod;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r e9df42113893 -r ef42f4648198 main.cpp --- a/main.cpp Thu Apr 03 07:31:24 2014 +0000 +++ b/main.cpp Thu Apr 03 10:56:37 2014 +0000 @@ -15,6 +15,7 @@ DigitalIn int_pin(p8); Timer t; +int t_usec; int reading_IR,reading_660,LSB,MSB; char rx_data[4]; char accel_data[6]; @@ -31,12 +32,12 @@ //////////////////////////////////////////// /////////////////////////////////////////// #define MAX_BLOCKSIZE 4096 -uint32_t fftsize = MAX_BLOCKSIZE/2; -const static arm_cfft_instance_f32 *S; +uint32_t fftsize = MAX_BLOCKSIZE/2; +const static arm_cfft_instance_f32 *S; /////////////////////////////////////////// long int BAUD_RATE = 230400; -void baud(int baudrate) +void baud(int baudrate) { Serial s(USBTX,USBRX); s.baud(baudrate); @@ -44,7 +45,7 @@ /////////////////////////////////////////// unsigned short i,j,k, m; -float32_t temp; +float32_t temp; float32_t temp2; float sclr; @@ -56,6 +57,7 @@ int main() { + t.start(); myled4 = 0; pc.baud(460800); Init_Accel(); // starts LIS3DH @@ -65,11 +67,9 @@ wait (0.5); j = 0; - + while(1) { if(!int_pin) { - //t.reset(); - //t.start(); write_reg(IRQ_STATUS,0x04); // clear the interrupt. @@ -82,132 +82,135 @@ dataX = accel_data[1] << 8 | accel_data[0]; dataY = accel_data[3] << 8 | accel_data[2]; dataZ = accel_data[5] << 8 | accel_data[4]; - + k = (j/2)*2; if (j==k) { - v[j] = (float32_t)reading_IR; - v[j+1] = 0; - w[j] = (float32_t)reading_660; - w[j+1] = 0; + v[j] = (float32_t)reading_IR; + v[j+1] = 0; + w[j] = (float32_t)reading_660; + w[j+1] = 0; - dataX_fl = (float) dataX; - dataY_fl = (float) dataY; - dataZ_fl = (float) dataZ; - - acc[j] = sqrt( (dataX_fl*dataX_fl) + (dataY_fl*dataY_fl) + (dataZ_fl*dataZ_fl) ); - acc[j+1] = 0; - - } - pc.printf ("%4d %5d %5d %5d %5d %5d\n\r", j, reading_IR, reading_660, dataX, dataY, dataZ); + dataX_fl = (float) dataX; + dataY_fl = (float) dataY; + dataZ_fl = (float) dataZ; - j++; - - if(j==MAX_BLOCKSIZE) - { - - switch (fftsize) { - case 64: - S = & arm_cfft_sR_f32_len64; - break; - case 128: - S = & arm_cfft_sR_f32_len128; - break; - case 256: - S = & arm_cfft_sR_f32_len256; - break; - case 512: - S = & arm_cfft_sR_f32_len512; - break; - case 1024: - S = & arm_cfft_sR_f32_len1024; - break; - case 2048: - S = & arm_cfft_sR_f32_len2048; - break; - case 4096: - S = & arm_cfft_sR_f32_len4096; - break; - } + acc[j] = sqrt( (dataX_fl*dataX_fl) + (dataY_fl*dataY_fl) + (dataZ_fl*dataZ_fl) ); + acc[j+1] = 0; + + } +// pc.printf ("%4d %5d %5d %5d %5d %5d\n\r", j, reading_IR, reading_660, dataX, dataY, dataZ); + + j= j + 2; + + if(j==MAX_BLOCKSIZE) { -///////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////// - float32_t maxvaluea, maxvalueb, maxacc, rvalue, spo2; - uint32_t testindexa, testindexb, indexacc; - - for (i = 0; i < 26; i++) { - pc.printf ("\n\r%4d %10.2f %10.2f %10.2f\n\r", i, v[i], w[i], acc[i]); - } - -///////////////////////////////////////////////////////////////////// - arm_cfft_f32(S, v, 0, 1); - arm_cmplx_mag_squared_f32(v, testoutput, fftsize); - sclr = 1000000/testoutput[0]; - arm_scale_f32(testoutput, sclr, testoutput, fftsize); - - for (i = 0; i < 26; i++) { - testoutputb[i] = testoutput[i]; - if (i<4) { - testoutputb[i] = 0; - } - pc.printf ("\n\r%4d %10.2f\n\r", i, testoutputb[i]); - } - // 805 nm - arm_max_f32(testoutputb, 26, &maxvalueb, &testindexb); // 720 hz sampling / 4096 fft = 0.1758 hz bin spacing = 360 hz sampling / 2048 fft - // 1 beat-sec / 0.1758 = about 6 bins (HR = 60 bpm) - // 3.6667 beats-sec / 0.1758 hz bin spacing = about 21 bins (HR = 220 bpm) - pc.printf ("\n\r\n\r%4d %10.3f\n\r\n\r", testindexb, maxvalueb); - -///////////////////////////////////////////////////////////////////// - arm_cfft_f32(S, w, 0, 1); - arm_cmplx_mag_squared_f32(w, testoutput, fftsize); - sclr = 1000000/testoutput[0]; - arm_scale_f32(testoutput, sclr, testoutput, fftsize); - - for (i = 0; i < 26; i++) { - testoutputc[i] = testoutput[i]; - if (i<4) { - testoutputc[i] = 0; - } - } - // 660 nm - arm_max_f32(testoutputc, 26, &maxvaluea, &testindexa); // 720 hz sampling / 4096 fft = 0.1758 hz bin spacing = 360 hz sampling / 2048 fft - // 1 beat-sec / 0.1758 = about 6 bins (HR = 60 bpm) - // 3.6667 beats-sec / 0.1758 hz bin spacing = about 21 bins (HR = 220 bpm) - pc.printf ("\n\r\n\r%4d %10.3f\n\r\n\r", testindexa, maxvaluea); - - rvalue = maxvaluea/maxvalueb; - spo2 = -22.6 * rvalue + 108; - - pc.printf ("\n\r\n\r%5.2f %5.2f\n\r\n\r", rvalue, spo2); - -///////////////////////////////////////////////////////////////////// - arm_cfft_f32(S, acc, 0, 1); - arm_cmplx_mag_squared_f32(acc, testoutput, fftsize); - sclr = 1000000/testoutput[0]; - arm_scale_f32(testoutput, sclr, testoutput, fftsize); - - for (i = 0; i < 26; i++) { - outputacc[i] = testoutput[i]; - if (i<4) { - outputacc[i] = 0; - } - pc.printf ("\n\r%4d %10.2f\n\r", i, outputacc[i]); - } - // accelerometer - arm_max_f32(outputacc, 26, &maxacc, &indexacc); // 720 hz sampling / 4096 fft = 0.1758 hz bin spacing = 360 hz sampling / 2048 fft - // 1 beat-sec / 0.1758 = about 6 bins (HR = 60 bpm) - // 3.6667 beats-sec / 0.1758 hz bin spacing = about 21 bins (HR = 220 bpm) - pc.printf ("\n\r\n\r%4d %10.3f\n\r\n\r", indexacc, maxacc); + switch (fftsize) { + case 64: + S = & arm_cfft_sR_f32_len64; + break; + case 128: + S = & arm_cfft_sR_f32_len128; + break; + case 256: + S = & arm_cfft_sR_f32_len256; + break; + case 512: + S = & arm_cfft_sR_f32_len512; + break; + case 1024: + S = & arm_cfft_sR_f32_len1024; + break; + case 2048: + S = & arm_cfft_sR_f32_len2048; + break; + case 4096: + S = & arm_cfft_sR_f32_len4096; + break; + } ///////////////////////////////////////////////////////////////////// - j = 0; +///////////////////////////////////////////////////////////////////// + float32_t maxvaluea, maxvalueb, maxacc, rvalue, spo2; + uint32_t testindexa, testindexb, indexacc; + + t.reset(); + + for (i = 0; i < 26; i++) { +// pc.printf ("\n\r%4d %10.2f %10.2f %10.2f\n\r", i, v[i], w[i], acc[i]); + } + +///////////////////////////////////////////////////////////////////// + arm_cfft_f32(S, v, 0, 1); + arm_cmplx_mag_squared_f32(v, testoutput, fftsize); + sclr = 1000000/testoutput[0]; + arm_scale_f32(testoutput, sclr, testoutput, fftsize); + + for (i = 0; i < 26; i++) { + testoutputb[i] = testoutput[i]; + if (i<4) { + testoutputb[i] = 0; + } +// pc.printf ("\n\r%4d %10.2f\n\r", i, testoutputb[i]); + } + // 805 nm + arm_max_f32(testoutputb, 26, &maxvalueb, &testindexb); // 720 hz sampling / 4096 fft = 0.1758 hz bin spacing = 360 hz sampling / 2048 fft + // 1 beat-sec / 0.1758 = about 6 bins (HR = 60 bpm) + // 3.6667 beats-sec / 0.1758 hz bin spacing = about 21 bins (HR = 220 bpm) +// pc.printf ("\n\r\n\r%4d %10.3f\n\r\n\r", testindexb, maxvalueb); ///////////////////////////////////////////////////////////////////// - - } - + arm_cfft_f32(S, w, 0, 1); + arm_cmplx_mag_squared_f32(w, testoutput, fftsize); + sclr = 1000000/testoutput[0]; + arm_scale_f32(testoutput, sclr, testoutput, fftsize); + + for (i = 0; i < 26; i++) { + testoutputc[i] = testoutput[i]; + if (i<4) { + testoutputc[i] = 0; + } + } + // 660 nm + arm_max_f32(testoutputc, 26, &maxvaluea, &testindexa); // 720 hz sampling / 4096 fft = 0.1758 hz bin spacing = 360 hz sampling / 2048 fft + // 1 beat-sec / 0.1758 = about 6 bins (HR = 60 bpm) + // 3.6667 beats-sec / 0.1758 hz bin spacing = about 21 bins (HR = 220 bpm) +// pc.printf ("\n\r\n\r%4d %10.3f\n\r\n\r", testindexa, maxvaluea); + + rvalue = maxvaluea/maxvalueb; + spo2 = -22.6 * rvalue + 108; + + pc.printf ("\n\r\n\r%5.2f %5.2f\n\r\n\r", rvalue, spo2); + +///////////////////////////////////////////////////////////////////// + arm_cfft_f32(S, acc, 0, 1); + arm_cmplx_mag_squared_f32(acc, testoutput, fftsize); + sclr = 1000000/testoutput[0]; + arm_scale_f32(testoutput, sclr, testoutput, fftsize); + + for (i = 0; i < 26; i++) { + outputacc[i] = testoutput[i]; + if (i<4) { + outputacc[i] = 0; + } +// pc.printf ("\n\r%4d %10.2f\n\r", i, outputacc[i]); + } + // accelerometer + arm_max_f32(outputacc, 26, &maxacc, &indexacc); // 720 hz sampling / 4096 fft = 0.1758 hz bin spacing = 360 hz sampling / 2048 fft + // 1 beat-sec / 0.1758 = about 6 bins (HR = 60 bpm) + // 3.6667 beats-sec / 0.1758 hz bin spacing = about 21 bins (HR = 220 bpm) +// pc.printf ("\n\r\n\r%4d %10.3f\n\r\n\r", indexacc, maxacc); + +///////////////////////////////////////////////////////////////////// + + j = 0; + t_usec = t.read_us(); + pc.printf ("FFT's etc: %d us\n",t_usec); + +///////////////////////////////////////////////////////////////////// + + } + //---------------------------------------------------------- } }