COG4050 and ADXL355 Tilt sensing

Dependencies:   ADXL355 include ttmath

Files at this revision

API Documentation at this revision

Comitter:
RGurav
Date:
Tue Aug 21 13:26:31 2018 +0000
Commit message:
Rohan - COG4050 and ADXL355 Tilt sensing

Changed in this revision

ADXL355.lib Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
include.lib 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-os.lib Show annotated file Show diff for this revision Revisions of this file
rtwtypes.h Show annotated file Show diff for this revision Revisions of this file
ttmath.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADXL355.lib	Tue Aug 21 13:26:31 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ADI_CAC/code/ADXL355/#e80c97768af4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Tue Aug 21 13:26:31 2018 +0000
@@ -0,0 +1,18 @@
+
+
+Following is the connection between EV-COG4050 and ADXL355 using the COG expander baord.
+
+ADXL35x on the EV-GEAR-EXPANDER1Z
+CONNECTION DIAGRAM through P4 PMOD_SP1
+
+SIGNAL_NAME     PIN NUM     EVAL-ADXL35xZ
+SPI1_CS0        PMOD-P4 1   P2 2
+SPI1_MOSI       PMOD-P4 2   P2 6
+SPI1_MISO       PMOD-P4 3   P2 5
+SPI1_CLK        PMOD-P4 4   P2 4
+GND             PMOD-P4 5   P1 5
+FT_EXT_VDD_OUT  PMOD-P4 6   P1 1
+FT_EXT_VDD_OUT  PMOD-P4 12  P1 3
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include.lib	Tue Aug 21 13:26:31 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/niv17/code/include/#5347612e39a3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 21 13:26:31 2018 +0000
@@ -0,0 +1,138 @@
+/*
+Created on: 15/08/2018
+Author: Rohan Gurav
+        
+Code: Use the following code to read the ADXL355 values connected to the SPI channel 
+      of the EV-COG4050-Expander board port0. Check the readme.md for connection info  
+      
+*/
+#include "mbed.h"
+#include "ADXL355.h"
+#include "complex.h"
+
+
+Serial pc(USBTX, USBRX);
+int axis = 0;
+
+ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK);    // PMOD port
+
+float single_axis(float x);
+float dual_axis(float x, float y);
+float tri_axis(float x, float y, float z);
+    
+int main()
+{
+    pc.baud(9600);
+    pc.printf("SPI ADXL355 and ADXL357 Demo\r\n");
+    pc.printf("GET device ID\r\n");
+   
+    accl.reset();
+    uint8_t d; 
+    
+    wait(0.2);
+    
+    d=accl.read_reg(accl.DEVID_AD);
+    pc.printf("AD id = %x \r\n",d);
+    
+    d=accl.read_reg(accl.DEVID_MST);
+    pc.printf("MEMS id = %x \r\n",d);
+    
+    d=accl.read_reg(accl.PARTID);
+    pc.printf("device id = %x \r\n",d);
+    
+    d=accl.read_reg(accl.REVID);
+    pc.printf("revision id = %x \r\n",d);
+    
+    pc.printf("GET device data [x, y, z, t] \r\n");
+    accl.set_power_ctl_reg(accl.MEASUREMENT);
+    
+    d=accl.read_reg(accl.POWER_CTL);
+    pc.printf("power control on measurement mode = %x \r\n",d);
+    
+    float x,y,z,t;
+        
+    double tilt_x, tilt_y,tilt_z;
+    
+    pc.printf("Enter no of axis for angle calculation (1/2/3):\r\n");
+    pc.scanf("%d",&axis);
+    
+    pc.printf("||x_accl||y_accl||z_accl||Temp||x_tilt||y_tilt||z_tilt||");
+    
+    /*The following part is used to perform 2's complemient and then display the data*/
+    while (1)
+    {
+        
+        
+        x = accl.convert(accl.scanx())*accl.axis355_sens;
+        y = accl.convert(accl.scany())*accl.axis355_sens;
+        z = accl.convert(accl.scanz())*accl.axis355_sens;
+        t = 25+float(accl.scant()-1852)/(-9.05);
+    
+        if (axis==1)
+        {
+            tilt_x = single_axis(x);
+            tilt_y = single_axis(y);
+            tilt_z = single_axis(z);
+        
+            pc.printf("||%0.2f||%0.2f||%0.2f||%0.2f||%0.2f||%0.2f|| \r\n" , x,y,z,tilt_x,tilt_y,tilt_z);
+            wait(0.5);
+        }
+        
+        if (axis==2)
+        {
+            tilt_x = dual_axis(x,z);
+            tilt_y = dual_axis(y,z);
+                    
+            pc.printf("||%0.2f||%0.2f||%0.2f||%0.2f||%0.2f|| \r\n" , x,y,z,tilt_x,tilt_y);
+            wait(0.5);
+        }
+      
+        if (axis==3)
+        {
+            tilt_x = tri_axis(x,y,z);
+            tilt_y = tri_axis(y,x,z);
+            
+            tilt_z = atan((sqrt((x*x)+(y*y)))/z);
+            tilt_z = floor(tilt_z*100)/100;
+                    
+            pc.printf("||%0.2f||%0.2f||%0.2f||%0.2f||%0.2f||%0.2f|| \r\n" , x,y,z,tilt_x,tilt_y, tilt_z);
+            wait(0.5);
+        }
+        
+    }
+
+}
+
+
+//single axis
+    float single_axis(float x)
+    {
+        double 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 dual_axis(float x, float y)
+    {
+        double Y;
+        Y = 57.2957f * (atan(x/y));
+        Y = floor(Y*100)/100;
+        return Y;    
+    }
+
+//Triaxial
+    float tri_axis(float x, float y, float z)
+    {
+        double Y;
+        double X;
+        X = (x)/(sqrt((y*y)+(z*z)));
+        Y= atan(X);
+        Y = floor(Y*57.2957*100)/100;
+        return Y;    
+    }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Tue Aug 21 13:26:31 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#485bdeee150e2bc8ed75e27d936060fb63a7a7d1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rtwtypes.h	Tue Aug 21 13:26:31 2018 +0000
@@ -0,0 +1,161 @@
+/*
+ * Academic License - for use in teaching, academic research, and meeting
+ * course requirements at degree granting institutions only.  Not for
+ * government, commercial, or other organizational use.
+ *
+ * File: rtwtypes.h
+ *
+ * Code generated for Simulink model 'ControllerFSM'.
+ *
+ * Model version                  : 1.108
+ * Simulink Coder version         : 8.10 (R2016a) 10-Feb-2016
+ * C/C++ source code generated on : Sat Jul 30 19:10:44 2016
+ *
+ * Target selection: ert.tlc
+ * Embedded hardware selection: ARM Compatible->ARM Cortex
+ * Code generation objectives: Unspecified
+ * Validation result: Not run
+ */
+
+#ifndef RTWTYPES_H
+#define RTWTYPES_H
+
+/* Logical type definitions */
+#if (!defined(__cplusplus))
+#  ifndef false
+#   define false                       (0U)
+#  endif
+
+#  ifndef true
+#   define true                        (1U)
+#  endif
+#endif
+
+/*=======================================================================*
+ * Target hardware information
+ *   Device type: ARM Compatible->ARM Cortex
+ *   Number of bits:     char:   8    short:   16    int:  32
+ *                       long:  32
+ *                       native word size:  32
+ *   Byte ordering: LittleEndian
+ *   Signed integer division rounds to: Zero
+ *   Shift right on a signed integer as arithmetic shift: on
+ *=======================================================================*/
+
+/*=======================================================================*
+ * Fixed width word size data types:                                     *
+ *   int8_T, int16_T, int32_T     - signed 8, 16, or 32 bit integers     *
+ *   uint8_T, uint16_T, uint32_T  - unsigned 8, 16, or 32 bit integers   *
+ *   real32_T, real64_T           - 32 and 64 bit floating point numbers *
+ *=======================================================================*/
+typedef signed char int8_T;
+typedef unsigned char uint8_T;
+typedef short int16_T;
+typedef unsigned short uint16_T;
+typedef int int32_T;
+typedef unsigned int uint32_T;
+typedef float real32_T;
+typedef double real64_T;
+
+/*===========================================================================*
+ * Generic type definitions: boolean_T, char_T, byte_T, int_T, uint_T,       *
+ *                           real_T, time_T, ulong_T.                        *
+ *===========================================================================*/
+typedef double real_T;
+typedef double time_T;
+typedef unsigned char boolean_T;
+typedef int int_T;
+typedef unsigned int uint_T;
+typedef unsigned long ulong_T;
+typedef char char_T;
+typedef unsigned char uchar_T;
+typedef char_T byte_T;
+
+/*===========================================================================*
+ * Complex number type definitions                                           *
+ *===========================================================================*/
+#define CREAL_T
+
+typedef struct {
+  real32_T re;
+  real32_T im;
+} creal32_T;
+
+typedef struct {
+  real64_T re;
+  real64_T im;
+} creal64_T;
+
+typedef struct {
+  real_T re;
+  real_T im;
+} creal_T;
+
+#define CINT8_T
+
+typedef struct {
+  int8_T re;
+  int8_T im;
+} cint8_T;
+
+#define CUINT8_T
+
+typedef struct {
+  uint8_T re;
+  uint8_T im;
+} cuint8_T;
+
+#define CINT16_T
+
+typedef struct {
+  int16_T re;
+  int16_T im;
+} cint16_T;
+
+#define CUINT16_T
+
+typedef struct {
+  uint16_T re;
+  uint16_T im;
+} cuint16_T;
+
+#define CINT32_T
+
+typedef struct {
+  int32_T re;
+  int32_T im;
+} cint32_T;
+
+#define CUINT32_T
+
+typedef struct {
+  uint32_T re;
+  uint32_T im;
+} cuint32_T;
+
+/*=======================================================================*
+ * Min and Max:                                                          *
+ *   int8_T, int16_T, int32_T     - signed 8, 16, or 32 bit integers     *
+ *   uint8_T, uint16_T, uint32_T  - unsigned 8, 16, or 32 bit integers   *
+ *=======================================================================*/
+#define MAX_int8_T                     ((int8_T)(127))
+#define MIN_int8_T                     ((int8_T)(-128))
+#define MAX_uint8_T                    ((uint8_T)(255U))
+#define MAX_int16_T                    ((int16_T)(32767))
+#define MIN_int16_T                    ((int16_T)(-32768))
+#define MAX_uint16_T                   ((uint16_T)(65535U))
+#define MAX_int32_T                    ((int32_T)(2147483647))
+#define MIN_int32_T                    ((int32_T)(-2147483647-1))
+#define MAX_uint32_T                   ((uint32_T)(0xFFFFFFFFU))
+
+/* Block D-Work pointer type */
+typedef void * pointer_T;
+
+#endif                                 /* RTWTYPES_H */
+
+/*
+ * File trailer for generated code.
+ *
+ * [EOF]
+ */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ttmath.lib	Tue Aug 21 13:26:31 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/stevep/code/ttmath/#04a9f72bbca7