base program for tilt measurement

Dependencies:   COG4050_ADT7420 ADXL362

Fork of COG4050_adxl355_adxl357-ver2 by ADI_CAC

Files at this revision

API Documentation at this revision

Comitter:
vtoffoli
Date:
Fri Sep 07 15:50:53 2018 +0000
Parent:
9:6c803986dbde
Commit message:
basic driver;

Changed in this revision

ADXL35x/ADXL355.cpp Show annotated file Show diff for this revision Revisions of this file
ADXL35x/ADXL355.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
diff -r 6c803986dbde -r f5ba762b58b4 ADXL35x/ADXL355.cpp
--- a/ADXL35x/ADXL355.cpp	Mon Sep 03 10:39:56 2018 +0000
+++ b/ADXL35x/ADXL355.cpp	Fri Sep 07 15:50:53 2018 +0000
@@ -81,7 +81,7 @@
     adxl355.write((reg<<1) | _READ_REG_CMD);
     ret_val = 0x0f & adxl355.write(_DUMMY_BYTE);
     ret_val = (ret_val<<8) | adxl355.write(_DUMMY_BYTE);
-    ret_val = (ret_val<<8) | adxl355.write(_DUMMY_BYTE);
+    ret_val = (ret_val<<4) | (adxl355.write(_DUMMY_BYTE)>>4);
     cs = true;
     return ret_val;
 }
@@ -233,4 +233,40 @@
     //uint32_t rawValue = data<<(32-nbit);
     // Otherwise perform the 2's complement math on the value
     return float((~(data - 0x01)) & 0xfffff) * -1;
-}
\ No newline at end of file
+}
+
+/** ----------------------------------- */
+/** ANGLE MEASUREMENT                   */
+/** ----------------------------------- */ 
+//single axis
+float ADXL355::single_axis(float x)
+    {
+        float Y;
+        //int a=4;
+        Y = floor(asin(x)*100)/100;
+        //void arm_cmplx_mag_f32  (double *Y, double *X, int32_t a);       
+
+        Y = floor(((57.2957f)*(Y))*100)/100;
+        return Y;
+                    
+    }
+
+//Dual Axis
+float ADXL355::dual_axis(float x, float y)
+    {
+        float Y;
+        Y = 57.2957f * (atan(x/y));
+        Y = floor(Y*100)/100;
+        return Y;    
+    }
+
+//Triaxial
+float ADXL355::tri_axis(float x, float y, float z)
+    {
+        float Y;
+        float X;
+        X = (x)/(sqrt((y*y)+(z*z)));
+        Y= atan(X);
+        Y = floor(Y*57.2957*100)/100;
+        return Y;    
+    }
diff -r 6c803986dbde -r f5ba762b58b4 ADXL35x/ADXL355.h
--- a/ADXL35x/ADXL355.h	Mon Sep 03 10:39:56 2018 +0000
+++ b/ADXL35x/ADXL355.h	Fri Sep 07 15:50:53 2018 +0000
@@ -163,7 +163,10 @@
     uint64_t fifo_scan();
     // ADXL conversion
     float convert(uint32_t data);
-    
+    // ADXL angle measurement
+    float single_axis(float x);
+    float dual_axis(float x, float y);
+    float tri_axis(float x, float y, float z);
 private:
     // SPI adxl355;                 ///< SPI instance of the ADXL
     SPI adxl355; DigitalOut cs;
diff -r 6c803986dbde -r f5ba762b58b4 main.cpp
--- a/main.cpp	Mon Sep 03 10:39:56 2018 +0000
+++ b/main.cpp	Fri Sep 07 15:50:53 2018 +0000
@@ -130,28 +130,28 @@
                         x = accl.convert(accl.scanx())*accl.axis355_sens;
                         y = accl.convert(accl.scany())*accl.axis355_sens;
                         z = accl.convert(accl.scanz())*accl.axis355_sens;
-                        w = asin(x/9.81)*180/pi;
-                        k = asin(y/9.81)*180/pi;
-                        h = asin(z/9.81)*180/pi;
+                        w = asin(x)*180/pi;
+                        k = asin(y)*180/pi;
+                        h = asin(z)*180/pi;
                         pc.printf("%f \t %f \t %f \t %f \t %f \t %f  \r\n" , x,y,z,w,k,h);
                         wait(0.1);}   
                     }
                 else if(point == '2'){
                     for(int i=0; i<50; i++){
-                        x = accl.convert(accl.scanx())*accl.axis355_sens;
-                        y = accl.convert(accl.scany())*accl.axis355_sens;
-                        z = accl.convert(accl.scanz())*accl.axis355_sens;
+                        x = accl.convert(accl.scanx());
+                        y = accl.convert(accl.scany());
+                        z = accl.convert(accl.scanz());
                         w = atan(x/z)*180/pi;;
-                        k = atan(y/z)*180/pi;;
+                        k = atan(y/x)*180/pi;;
                         h = 0;
                         pc.printf("%f \t %f \t %f \t %f \t %f \t %f  \r\n" , x,y,z,w,k,h);
                         wait(0.1);}
                     }
                 else if(point == '3'){
                     for(int i=0; i<50; i++){
-                        x = accl.convert(accl.scanx())*accl.axis355_sens;
-                        y = accl.convert(accl.scany())*accl.axis355_sens;
-                        z = accl.convert(accl.scanz())*accl.axis355_sens;
+                        x = accl.convert(accl.scanx());
+                        y = accl.convert(accl.scany());
+                        z = accl.convert(accl.scanz());
                         w = atan2(x,sqrt(pow(y,2)+pow(z,2)))*180/pi; 
                         k = atan2(y,sqrt(pow(x,2)+pow(z,2)))*180/pi;
                         h = atan2(sqrt(pow(x,2)+pow(y,2)),z)*180/pi;