ADXL345 Evaluation

Dependencies:   mbed

Revision:
5:88787a48e96e
Parent:
4:f5a78245f2d0
Child:
6:592373200317
diff -r f5a78245f2d0 -r 88787a48e96e main.cpp
--- a/main.cpp	Tue Aug 29 09:18:15 2017 +0000
+++ b/main.cpp	Fri Sep 01 10:10:46 2017 +0000
@@ -53,7 +53,7 @@
          _summary += x;
          _squardsum += x*x;
          _numbers ++;
-         _itg1 = _summary;
+         _itg1 += x - _summary / _numbers ;
          _itg2 += _itg1;
          _itg3 += _itg2;
          temp = _dif1;
@@ -77,7 +77,7 @@
  int main() {
      char getc =0;
      int channel = 0, datamode =0;
-     bool output = true, mapout = false;
+     bool output = true, mapout = true;
      pc.baud(115200);
      int readings[3] = {0, 0, 0};
      RangeMapper DAC_Mapper( 0 - 1<<13, 1<<13, 0, 1);
@@ -179,32 +179,46 @@
             }
         else
             {
-            double mapdata;
             error_count = 0; 
-            dp[0].putData((int16_t)readings[0]);
-            dp[1].putData((int16_t)readings[1]);
-            dp[2].putData((int16_t)readings[2]);
+            int i;
+            for (i = 0; i<3; i++)
+                dp[i].putData(readings[i] = (int16_t) readings[i] );
+                
             if (output)
              {
                switch (datamode)
                {
-                case 0: mapdata = readings[channel]; pc.printf("RAW: %i, %i, %i\r\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); break;
-                //case 0: mapdata = readings[channel]; pc.printf("RAW: %i, %i, %i\r\n", readings[0], readings[1], readings[2]); break;
-                case 1: mapdata = dp[channel].getMean(); pc.printf("MEAN: %f, %f, %f\r\n", dp[0].getMean(), dp[1].getMean(), dp[2].getMean() ); break;
-                case 2: mapdata = dp[channel].getSum(); pc.printf("SUM: %jd, %jd, %jd\r\n", dp[0].getSum(), dp[1].getSum(), dp[2].getSum() ); break;                
-                case 3: mapdata = dp[channel].getStdDiv(); pc.printf("STD: %f, %f, %f\r\n", dp[0].getStdDiv(), dp[1].getStdDiv(), dp[2].getStdDiv() ); break;
-                case 4: mapdata = dp[channel].getO1integration(); pc.printf("1ITG: %jd, %jd, %jd\r\n", dp[0].getO1integration(), dp[1].getO1integration(), dp[2].getO1integration() ); break;     
-                case 5: mapdata = dp[channel].getO2integration(); pc.printf("2ITG: %jd, %jd, %jd\r\n", dp[0].getO2integration(), dp[1].getO2integration(), dp[2].getO2integration() ); break;     
-                case 6: mapdata = dp[channel].getO3integration(); pc.printf("3ITG: %jd, %jd, %jd\r\n", dp[0].getO3integration(), dp[1].getO3integration(), dp[2].getO3integration() ); break;     
-                case 7: mapdata = dp[channel].GetO1differ(); pc.printf("1DIF: %jd, %jd, %jd\r\n", dp[0].GetO1differ(), dp[1].GetO1differ(), dp[2].GetO1differ() ); break;     
-                case 8: mapdata = dp[channel].GetO2differ(); pc.printf("2DIF: %jd, %jd, %jd\r\n", dp[0].GetO2differ(), dp[1].GetO2differ(), dp[2].GetO2differ() ); break;     
+                case 0: pc.printf("RAW: %i, %i, %i\r\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); break;
+                //case 0: pc.printf("RAW: %i, %i, %i\r\n", readings[0], readings[1], readings[2]); break;
+                case 1: pc.printf("MEAN: %f, %f, %f\r\n", dp[0].getMean(), dp[1].getMean(), dp[2].getMean() ); break;
+                case 2: pc.printf("SUM: %jd, %jd, %jd\r\n", dp[0].getSum(), dp[1].getSum(), dp[2].getSum() ); break;                
+                case 3: pc.printf("STD: %f, %f, %f\r\n", dp[0].getStdDiv(), dp[1].getStdDiv(), dp[2].getStdDiv() ); break;
+                case 4: pc.printf("1ITG: %jd, %jd, %jd\r\n", dp[0].getO1integration(), dp[1].getO1integration(), dp[2].getO1integration() ); break;     
+                case 5: pc.printf("2ITG: %jd, %jd, %jd\r\n", dp[0].getO2integration(), dp[1].getO2integration(), dp[2].getO2integration() ); break;     
+                case 6: pc.printf("3ITG: %jd, %jd, %jd\r\n", dp[0].getO3integration(), dp[1].getO3integration(), dp[2].getO3integration() ); break;     
+                case 7: pc.printf("1DIF: %jd, %jd, %jd\r\n", dp[0].GetO1differ(), dp[1].GetO1differ(), dp[2].GetO1differ() ); break;     
+                case 8: pc.printf("2DIF: %jd, %jd, %jd\r\n", dp[0].GetO2differ(), dp[1].GetO2differ(), dp[2].GetO2differ() ); break;     
                 default: break;         
                }
              }
             if (mapout)
              {
-                 // Set data the DAC
-                 DAC_Mapper.getOutput(mapdata);
+               double mapdata;
+               switch (datamode)
+               {
+                case 0: mapdata = readings[channel];  break;
+                case 1: mapdata = dp[channel].getMean(); break;
+                case 2: mapdata = dp[channel].getSum();  break;                
+                case 3: mapdata = dp[channel].getStdDiv();  break;
+                case 4: mapdata = dp[channel].getO1integration(); break;     
+                case 5: mapdata = dp[channel].getO2integration();  break;     
+                case 6: mapdata = dp[channel].getO3integration();  break;     
+                case 7: mapdata = dp[channel].GetO1differ(); break;     
+                case 8: mapdata = dp[channel].GetO2differ(); break;     
+                default: mapdata = 0; break;         
+               }
+                // Set data the DAC
+                DAC_Mapper.getOutput(mapdata);
              }
              wait(1);
             }