Slight Mod

Dependencies:   mbed-dsp mbed

Fork of Hat_Board_v5 by John Scharf

Files at this revision

API Documentation at this revision

Comitter:
jjes144
Date:
Thu Apr 03 07:31:24 2014 +0000
Parent:
3:8334f137c151
Child:
5:ef42f4648198
Commit message:
accel now workin

Changed in this revision

SI_LIS.cpp Show annotated file Show diff for this revision Revisions of this file
arm_const_structs.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-dsp.lib Show annotated file Show diff for this revision Revisions of this file
--- a/SI_LIS.cpp	Fri Mar 21 01:13:05 2014 +0000
+++ b/SI_LIS.cpp	Thu Apr 03 07:31:24 2014 +0000
@@ -133,7 +133,7 @@
     // Nib 1 of 0101: Normal mode, 100 Hz;  Nib 2 of 0111: Normal mode, XYZ enabled
 //    Reg_Val = 0x57; // Nib 1 of 0101: Normal mode, 100 Hz;  Nib 2 of 0111: Normal mode, XYZ enabled
     // Nib 1 of 0111: 400 Hz;  Nib 2 of 0111: XYZ enabled
-    Reg_Val = 0x77; 
+    Reg_Val = 0x97;  //0x77 is 400 hz    --    0x97 is 1.2 khz
 
     data[0]   = Reg_Num;     //register to be written to
     data[1]   = Reg_Val;     //data
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arm_const_structs.h	Thu Apr 03 07:31:24 2014 +0000
@@ -0,0 +1,86 @@
+/* ----------------------------------------------------------------------
+* Copyright (C) 2010-2013 ARM Limited. All rights reserved.
+*
+* $Date:        17. January 2013
+* $Revision:    V1.4.1
+*
+* Project:      CMSIS DSP Library
+* Title:        arm_const_structs.h
+*
+* Description:  This file has constant structs that are initialized for
+*               user convenience.  For example, some can be given as
+*               arguments to the arm_cfft_f32() function.
+*
+* Target Processor: Cortex-M4/Cortex-M3
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*   - Redistributions of source code must retain the above copyright
+*     notice, this list of conditions and the following disclaimer.
+*   - Redistributions in binary form must reproduce the above copyright
+*     notice, this list of conditions and the following disclaimer in
+*     the documentation and/or other materials provided with the
+*     distribution.
+*   - Neither the name of ARM LIMITED nor the names of its contributors
+*     may be used to endorse or promote products derived from this
+*     software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+* -------------------------------------------------------------------- */
+
+#ifndef _ARM_CONST_STRUCTS_H
+#define _ARM_CONST_STRUCTS_H
+
+#include "arm_math.h"
+#include "arm_common_tables.h"
+
+   const arm_cfft_instance_f32 arm_cfft_sR_f32_len16 = {
+      16, twiddleCoef_16, armBitRevIndexTable16, ARMBITREVINDEXTABLE__16_TABLE_LENGTH
+   };
+
+   const arm_cfft_instance_f32 arm_cfft_sR_f32_len32 = {
+      32, twiddleCoef_32, armBitRevIndexTable32, ARMBITREVINDEXTABLE__32_TABLE_LENGTH
+   };
+
+   const arm_cfft_instance_f32 arm_cfft_sR_f32_len64 = {
+      64, twiddleCoef_64, armBitRevIndexTable64, ARMBITREVINDEXTABLE__64_TABLE_LENGTH
+   };
+
+   const arm_cfft_instance_f32 arm_cfft_sR_f32_len128 = {
+      128, twiddleCoef_128, armBitRevIndexTable128, ARMBITREVINDEXTABLE_128_TABLE_LENGTH
+   };
+
+   const arm_cfft_instance_f32 arm_cfft_sR_f32_len256 = {
+      256, twiddleCoef_256, armBitRevIndexTable256, ARMBITREVINDEXTABLE_256_TABLE_LENGTH
+   };
+
+   const arm_cfft_instance_f32 arm_cfft_sR_f32_len512 = {
+      512, twiddleCoef_512, armBitRevIndexTable512, ARMBITREVINDEXTABLE_512_TABLE_LENGTH
+   };
+
+   const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024 = {
+      1024, twiddleCoef_1024, armBitRevIndexTable1024, ARMBITREVINDEXTABLE1024_TABLE_LENGTH
+   };
+
+   const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048 = {
+      2048, twiddleCoef_2048, armBitRevIndexTable2048, ARMBITREVINDEXTABLE2048_TABLE_LENGTH
+   };
+
+   const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096 = {
+      4096, twiddleCoef_4096, armBitRevIndexTable4096, ARMBITREVINDEXTABLE4096_TABLE_LENGTH
+   };
+
+#endif
+
--- a/main.cpp	Fri Mar 21 01:13:05 2014 +0000
+++ b/main.cpp	Thu Apr 03 07:31:24 2014 +0000
@@ -1,11 +1,14 @@
-//Hat Board Test by James Cooke 3/18/2014
-//Goal of  program: read and output data from LIS3DH accelerometer
-//Started with Si_4088_PC working program: able to get data from Si1142 on new hat board
+//Hat Board v5 by Cooke Scharf 4/2/2014
 
 #include "mbed.h"
 #include "SI_LIS.h"
 #include <time.h>
 
+#include "arm_math.h"
+#include "math_helper.h"
+#include "dsp.h"
+#include "arm_const_structs.h"
+
 DigitalOut  myled3(LED3);
 DigitalOut  myled4(LED4);
 Serial      pc(USBTX,USBRX);
@@ -23,25 +26,50 @@
 float       dataX_fl;
 float       dataY_fl;
 float       dataZ_fl;
-float       accel_fl;
+//float       accel_fl;
+
+////////////////////////////////////////////
+///////////////////////////////////////////
+#define         MAX_BLOCKSIZE   4096
+uint32_t        fftsize = MAX_BLOCKSIZE/2; 
+const static    arm_cfft_instance_f32 *S;  
+
+///////////////////////////////////////////
+long int        BAUD_RATE = 230400;
+void baud(int baudrate)        
+{
+    Serial s(USBTX,USBRX);
+    s.baud(baudrate);
+}
+
+///////////////////////////////////////////
+unsigned short  i,j,k, m;
+float32_t       temp;   
+float32_t       temp2;
+float           sclr;
+
+float32_t       v[MAX_BLOCKSIZE], w[MAX_BLOCKSIZE], acc[MAX_BLOCKSIZE];
+float32_t       testoutput[MAX_BLOCKSIZE/2];
+float32_t       testoutputb[26], testoutputc[26], outputacc[26];
+
+////////////////////////////////////////////
 
 int main()
 {
-    // To test:  Block data update (CTRL_REG4);  1.25 KHz data;  low power vs normal power
-
-    myled4 = 0;  // ODD: if this line not included, there is a compiler "internal error"
+    myled4 = 0;
     pc.baud(460800);
     Init_Accel();   // starts LIS3DH
     restart();      // starts Si1142
-
     wait_ms(30);
     command (PS_AUTO);   //start measuring
     wait (0.5);
 
+    j = 0;
+    
     while(1) {
         if(!int_pin) {
-            t.reset();
-            t.start();
+            //t.reset();
+            //t.start();
 
             write_reg(IRQ_STATUS,0x04);  // clear the interrupt.
 
@@ -49,30 +77,139 @@
             reading_IR  = rx_data[1] << 8 | rx_data[0];
             reading_660 = rx_data[3] << 8 | rx_data[1];
 
-            pc.printf ("%d, %d, ", reading_IR,reading_660);
-
             Get_Accel_Reg_6 (0x28);
 
             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;
+
             dataX_fl = (float) dataX;
-            dataY = accel_data[3] << 8 | accel_data[2];
             dataY_fl = (float) dataY;
-            dataZ = accel_data[5] << 8 | accel_data[4];
             dataZ_fl = (float) dataZ;
-            accel_fl = sqrt( (dataX_fl*dataX_fl) + (dataY_fl*dataY_fl) + (dataZ_fl*dataZ_fl) );
-            pc.printf ("%6.0f ",accel_fl);
+            
+            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++;
+    
+            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;
+        }
 
-            t.stop();
-            t_msec = t.read() * 1000;
-            printf("%6.3f msec\n", t_msec);
+/////////////////////////////////////////////////////////////////////
+        
+/////////////////////////////////////////////////////////////////////
+        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);
+
+/////////////////////////////////////////////////////////////////////
+
+        j = 0;
+
+/////////////////////////////////////////////////////////////////////
+    
+    }
+    
+//----------------------------------------------------------
         }
     }
 }
-/*
-Notes on RJ-45: Pin 1: Vcc  Pin 2: GND  Pin 3: SDA > 9 on 4088
-                Pin 4: SCL >> 10 on 4088  Pin 6: INT > 8 on 4088
 
-Bluetooth:  Tx on 4088: Pin 37 >> RX   Rx on 4088: Pin 31 >> TX
-PC COMM port on Square board: 12
-
-*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-dsp.lib	Thu Apr 03 07:31:24 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/teams/mbed-official/code/mbed-dsp/#7a284390b0ce