Fixed algorithm to read 3 bytes of accelerometer data registers
Fork of COG4050_adxl355_adxl357 by
Revision 10:e054891b3598, committed 2018-09-10
- Comitter:
- nfathurr
- Date:
- Mon Sep 10 10:01:49 2018 +0000
- Parent:
- 9:6c803986dbde
- Commit message:
- Fixed algorithm to read 3 bytes of accelerometer data registers
Changed in this revision
diff -r 6c803986dbde -r e054891b3598 ADXL35x/ADXL355.cpp --- a/ADXL35x/ADXL355.cpp Mon Sep 03 10:39:56 2018 +0000 +++ b/ADXL35x/ADXL355.cpp Mon Sep 10 10:01:49 2018 +0000 @@ -64,7 +64,8 @@ cs = true; return ret_val; } -uint16_t ADXL355::read_reg_u16(ADXL355_register_t reg){ +uint16_t ADXL355::read_reg_u16(ADXL355_register_t reg) +{ uint16_t ret_val = 0; adxl355.format(8, _SPI_MODE); cs = false; @@ -74,86 +75,112 @@ cs = true; return ret_val; } -uint32_t ADXL355::read_reg_u20(ADXL355_register_t reg){ - uint32_t ret_val = 0; +uint32_t ADXL355::read_reg_u20(ADXL355_register_t reg) +{ + uint32_t ret_val = 0, valueH= 0, valueM= 0, valueL= 0; + adxl355.format(8, _SPI_MODE); cs = false; - adxl355.write((reg<<1) | _READ_REG_CMD); - ret_val = 0x0f & adxl355.write(_DUMMY_BYTE); + adxl355.write((reg<<1) | _READ_REG_CMD); //dummy read + /* + //alternative method from ADICUP360 ADXL355 code + valueH = adxl355.write(_DUMMY_BYTE); + valueM = adxl355.write(_DUMMY_BYTE); + valueL = adxl355.write(_DUMMY_BYTE); + + ret_val = ((valueH << 16)| (valueM << 8)| valueL); + ret_val = ret_val >> 4; + */ + //Valeria's method version 2.0 + ret_val = 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; } /** ----------------------------------- */ /** Sets the CTL registers */ /** ----------------------------------- */ -void ADXL355::set_power_ctl_reg(uint8_t data){ - write_reg(POWER_CTL, data); +void ADXL355::set_power_ctl_reg(uint8_t data) +{ + write_reg(POWER_CTL, data); } -void ADXL355::set_filter_ctl_reg(ADXL355_filter_ctl_t hpf, ADXL355_filter_ctl_t odr){ +void ADXL355::set_filter_ctl_reg(ADXL355_filter_ctl_t hpf, ADXL355_filter_ctl_t odr) +{ write_reg(FILTER, static_cast<uint8_t>(hpf|odr)); } -void ADXL355::set_clk(ADXL355_sync_ctl_t data) { +void ADXL355::set_clk(ADXL355_sync_ctl_t data) +{ write_reg(SYNC, static_cast<uint8_t>(data)); } -void ADXL355::set_device(ADXL355_range_ctl_t range) { +void ADXL355::set_device(ADXL355_range_ctl_t range) +{ write_reg(RANGE, static_cast<uint8_t>(range)); - switch(range){ + switch(range) { case 0x01: axis355_sens = 3.9e-6; - axis357_sens = 19.5e-6; + axis357_sens = 19.5e-6; //scale factor g per LSB break; case 0x02: axis355_sens = 7.8e-6; - axis357_sens = 39e-6; + axis357_sens = 39e-6; //scale factor g per LSB break; case 0x03: axis355_sens = 15.6e-6; - axis357_sens = 78e-6; + axis357_sens = 78e-6; //scale factor g per LSB break; - } + } } /** ----------------------------------- */ /** Read the STATUS registers */ /** ----------------------------------- */ -uint8_t ADXL355::read_status(){ +uint8_t ADXL355::read_status() +{ return read_reg(STATUS); } /** ----------------------------------- */ /** ADXL must be set in measurement */ /** mode to read the data registers */ /** ----------------------------------- */ -uint32_t ADXL355::scanx(){ +uint32_t ADXL355::scanx() +{ return read_reg_u20(XDATA3); } -uint32_t ADXL355::scany(){ +uint32_t ADXL355::scany() +{ return read_reg_u20(YDATA3); } -uint32_t ADXL355::scanz(){ +uint32_t ADXL355::scanz() +{ return read_reg_u20(ZDATA3); } -uint16_t ADXL355::scant(){ +uint16_t ADXL355::scant() +{ return read_reg_u16(TEMP2); } /** ----------------------------------- */ /** Activity SetUp - the measured */ -/** acceleration on any axis is above */ +/** acceleration on any axis is above */ /** the ACT_THRESH bits for ACT_COUNT */ /** consecutive measurements. */ /** ----------------------------------- */ -void ADXL355::set_activity_axis(ADXL355_act_ctl_t axis) { +void ADXL355::set_activity_axis(ADXL355_act_ctl_t axis) +{ write_reg(ACT_EN, axis); } -void ADXL355::set_activity_cnt(uint8_t count) { +void ADXL355::set_activity_cnt(uint8_t count) +{ write_reg(ACT_COUNT, count); } -void ADXL355::set_activity_threshold(uint8_t data_h, uint8_t data_l) { +void ADXL355::set_activity_threshold(uint8_t data_h, uint8_t data_l) +{ uint16_t ret_val = static_cast<uint16_t>((data_h<<8)|data_l); write_reg_u16(ACT_THRESH_H, ret_val); } -void ADXL355::set_inactivity() { +void ADXL355::set_inactivity() +{ write_reg(ACT_EN, 0x00); } /** ----------------------------------- */ @@ -171,16 +198,19 @@ /** ----------------------------------- */ /** FIFO set up and read operation */ /** ----------------------------------- */ -uint8_t ADXL355::fifo_read_nr_of_entries(){ +uint8_t ADXL355::fifo_read_nr_of_entries() +{ return read_reg(FIFO_ENTRIES); } -void ADXL355::fifo_setup(uint8_t nr_of_entries){ +void ADXL355::fifo_setup(uint8_t nr_of_entries) +{ if (nr_of_entries > 0x60) { nr_of_entries = nr_of_entries; } write_reg(FIFO_SAMPLES, nr_of_entries); -} -uint32_t ADXL355::fifo_read_u32() { +} +uint32_t ADXL355::fifo_read_u32() +{ uint32_t ret_val = 0; adxl355.format(8, _SPI_MODE); cs = false; @@ -190,8 +220,9 @@ ret_val = (ret_val<<4) | static_cast<uint8_t>(adxl355.write(_DUMMY_BYTE)>>4); cs = true; return ret_val; - } -uint64_t ADXL355::fifo_scan() { +} +uint64_t ADXL355::fifo_scan() +{ uint64_t ret_val = 0; uint32_t x = 0, y = 0, z = 0, dummy; adxl355.format(8, _SPI_MODE); @@ -213,7 +244,7 @@ z = dummy; break; } - } + } cs = true; // format (24)xx(24)yy(24)zz ret_val = static_cast<uint64_t> (x) << 48; @@ -223,14 +254,18 @@ } /** ----------------------------------- */ /** CALIBRATION AND CONVERSION */ -/** ----------------------------------- */ -float ADXL355::convert(uint32_t data){ +/** ----------------------------------- */ +float ADXL355::convert(uint32_t data) +{ + float result = 0; + // If a positive value, return it - if ((data & 0x80000) == 0) - { - return float(data); + if ((data & 0x80000) == 0) { + result= float(data); + } else { + // Otherwise perform the 2's complement math on the value + result = float((~(data - 0x01)) & 0xfffff) * -1; } - //uint32_t rawValue = data<<(32-nbit); - // Otherwise perform the 2's complement math on the value - return float((~(data - 0x01)) & 0xfffff) * -1; + + return result; } \ No newline at end of file
diff -r 6c803986dbde -r e054891b3598 ADXL35x/ADXL355.h --- a/ADXL35x/ADXL355.h Mon Sep 03 10:39:56 2018 +0000 +++ b/ADXL35x/ADXL355.h Mon Sep 10 10:01:49 2018 +0000 @@ -4,15 +4,15 @@ class ADXL355 { -public: +public: // -------------------------- // - // CONST AND VARIABLES // - const static float t_sens = -9.05; - const static float t_bias = 1852; + // CONST AND VARIABLES // + const static float t_sens = -9.05; + const static float t_bias = 1852; float axis355_sens; - float axis357_sens; + float axis357_sens; //scale factor in ug per LSB // -------------------------- // - // REGISTERS // + // REGISTERS // // -------------------------- // typedef enum { DEVID_AD = 0x00, @@ -55,20 +55,20 @@ // -------------------------- // // REGISTERS - DEFAULT VALUES // // -------------------------- // - // Modes - POWER_CTL + // Modes - POWER_CTL typedef enum { DRDY_OFF = 0x04, TEMP_OFF = 0x02, STANDBY = 0x01, MEASUREMENT = 0x00 - } ADXL355_modes_t; - // Activate Threshold - ACT_EN + } ADXL355_modes_t; + // Activate Threshold - ACT_EN typedef enum { ACT_Z = 0x04, ACT_Y = 0x02, ACT_X = 0x01 } ADXL355_act_ctl_t; - // High-Pass and Low-Pass Filter - FILTER + // High-Pass and Low-Pass Filter - FILTER typedef enum { HPFOFF = 0x00, HPF247 = 0x10, @@ -89,20 +89,20 @@ ODR7Hz = 0x09, ODR3HZ = 0x0A } ADXL355_filter_ctl_t; - // External timing register - INT_MAP + // External timing register - INT_MAP typedef enum { OVR_EN = 0x04, FULL_EN = 0x02, RDY_EN = 0x01 } ADXL355_intmap_ctl_t; - // External timing register - SYNC + // External timing register - SYNC typedef enum { EXT_CLK = 0x04, INT_SYNC = 0x00, EXT_SYNC_NO_INT = 0x01, EXT_SYNC_INT = 0x02 - } ADXL355_sync_ctl_t; - // polarity and range - RANGE + } ADXL355_sync_ctl_t; + // polarity and range - RANGE typedef enum { RANGE2G = 0x01, RANGE4G = 0x02, @@ -111,41 +111,41 @@ RANGE20 = 0x02, RANGE40 = 0x03 } ADXL355_range_ctl_t; - // self test interrupt - INT + // self test interrupt - INT typedef enum { ST2 = 0x02, ST1 = 0x01 } ADXL355_int_ctl_t; // -------------------------- // - // FUNCTIONS // + // FUNCTIONS // // -------------------------- // - // SPI configuration & constructor + // SPI configuration & constructor ADXL355(PinName cs_pin , PinName MOSI , PinName MISO , PinName SCK ); void frequency(int hz); - // Low level SPI bus comm methods + // Low level SPI bus comm methods void reset(void); void write_reg(ADXL355_register_t reg, uint8_t data); void write_reg_u16(ADXL355_register_t reg, uint16_t data); uint8_t read_reg(ADXL355_register_t reg); uint16_t read_reg_u16(ADXL355_register_t reg); uint32_t read_reg_u20(ADXL355_register_t reg); - // ADXL general register R/W methods + // ADXL general register R/W methods void set_power_ctl_reg(uint8_t data); void set_filter_ctl_reg(ADXL355_filter_ctl_t hpf, ADXL355_filter_ctl_t odr); void set_clk(ADXL355_sync_ctl_t data); void set_device(ADXL355_range_ctl_t range); uint8_t read_status(); - // ADXL X/Y/Z/T scanning methods + // ADXL X/Y/Z/T scanning methods uint32_t scanx(); uint32_t scany(); uint32_t scanz(); uint16_t scant(); - // ADXL activity methods + // ADXL activity methods void set_activity_axis(ADXL355_act_ctl_t axis); void set_activity_cnt(uint8_t count); void set_activity_threshold(uint8_t data_h, uint8_t data_l); void set_inactivity(); - // ADXL interrupt methods + // ADXL interrupt methods void set_interrupt1_pin(PinName in, ADXL355_intmap_ctl_t mode); void set_interrupt2_pin(PinName in, ADXL355_intmap_ctl_t mode); void enable_interrupt1(); @@ -156,24 +156,25 @@ void set_polling_interrupt2_pin(uint8_t data); bool get_int1(); bool get_int2(); - // ADXL FIFO methods + // ADXL FIFO methods uint8_t fifo_read_nr_of_entries(); void fifo_setup(uint8_t nr_of_entries); uint32_t fifo_read_u32(); uint64_t fifo_scan(); // ADXL conversion float convert(uint32_t data); - + private: // SPI adxl355; ///< SPI instance of the ADXL - SPI adxl355; DigitalOut cs; - const static uint8_t _DEVICE_AD = 0xAD; // contect of DEVID_AD (only-read) register - const static uint8_t _RESET = 0x52; // reset code + SPI adxl355; + DigitalOut cs; + const static uint8_t _DEVICE_AD = 0xAD; // contect of DEVID_AD (only-read) register + const static uint8_t _RESET = 0x52; // reset code const static uint8_t _DUMMY_BYTE = 0xAA; // 10101010 const static uint8_t _WRITE_REG_CMD = 0x00; // write register const static uint8_t _READ_REG_CMD = 0x01; // read register const static uint8_t _READ_FIFO_CMD = 0x23; // read FIFO const static uint8_t _SPI_MODE = 0; // timing scheme }; - + #endif \ No newline at end of file
diff -r 6c803986dbde -r e054891b3598 COG4050_adxl362.lib --- a/COG4050_adxl362.lib Mon Sep 03 10:39:56 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://os.mbed.com/users/APS_Lab/code/COG4050_ADT7420/#74a0756399ff
diff -r 6c803986dbde -r e054891b3598 COG4050_blink.lib --- a/COG4050_blink.lib Mon Sep 03 10:39:56 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://os.mbed.com/users/APS_Lab/code/COG4050_ADT7420/#74a0756399ff
diff -r 6c803986dbde -r e054891b3598 READMEconnection.md --- a/READMEconnection.md Mon Sep 03 10:39:56 2018 +0000 +++ b/READMEconnection.md Mon Sep 10 10:01:49 2018 +0000 @@ -3,15 +3,17 @@ 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 - +SIGNAL_NAME PIN NUM EVAL-ADXL35xZ ADXL357 +SPI1_CS0 PMOD-P4 1 P2 2 CS/CSL +SPI1_MOSI PMOD-P4 2 P2 6 MOSI/SDA +SPI1_MISO PMOD-P4 3 P2 5 MISO/ASEL +SPI1_CLK PMOD-P4 4 P2 4 SCLK/VSSIO +GND PMOD-P4 5 P1 5 GND +FT_EXT_VDD_OUT PMOD-P4 6 P1 1 V1P8ANA +FT_EXT_VDD_OUT PMOD-P4 12 P1 3 V1P8DIG +xxx PMOD-P4 x P1 2 INT1 +xxx PMOD-P4 x P1 4 INT2/EXT_CLK +xxx PMOD-P4 x P1 6 DRDY/SYNC ADXRS290 on the EV-GEAR-EXPANDER1Z CONNECTION DIAGRAM through A5 ARDUINO UNO COMPATIBLE
diff -r 6c803986dbde -r e054891b3598 main.cpp --- a/main.cpp Mon Sep 03 10:39:56 2018 +0000 +++ b/main.cpp Mon Sep 10 10:01:49 2018 +0000 @@ -3,167 +3,122 @@ #include <inttypes.h> #include "ADXL355.h" #include "CALIBRATION.h" - + Serial pc(USBTX, USBRX); - + ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK); // PMOD port + CALIBRATION test; + #define pi 3.14159265; + float angle[3][12] = { {-55, -125, -147, 33, -128, 52, 0, 0, 0, 0, 0, 0}, - {6, -6, 20, -20, -69, 69, 0, 0, 0, 0, 0, 0 }, - {1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0}}; + {6, -6, 20, -20, -69, 69, 0, 0, 0, 0, 0, 0 }, + {1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} +}; + float meas[3][12] = { {-0.09, 0.16, -0.31, 0.37, 0.91, -0.88}, - {-0.78, 0.81, -0.46, 0.49, -0.28, 0.32}, - {0.54, -0.55, -0.78, 0.76, -0.20, 0.20}}; -int main(){ - pc.baud(9600); - pc.printf("SPI ADXL355 and ADXL357 Demo\n"); - pc.printf("GET device ID\n"); - accl.reset(); - uint8_t d; - 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"); + {-0.78, 0.81, -0.46, 0.49, -0.28, 0.32}, + {0.54, -0.55, -0.78, 0.76, -0.20, 0.20} +}; +void adxl_init() +{ + uint8_t res; + + //getting Analog Device ID + res = accl.read_reg(accl.DEVID_AD); + pc.printf("AD id = %x \r\n",res); + //getting MEMS ID + res = accl.read_reg(accl.DEVID_MST); + pc.printf("MEMS id = %x \r\n",res); + //getting DEVICE ID + res = accl.read_reg(accl.PARTID); + pc.printf("DEVICE id = %x \r\n",res); + //getting REVISION ID + res = accl.read_reg(accl.REVID); + pc.printf("REVISION id = %x \r\n",res); + + //setting RANGE + accl.set_device(accl.RANGE20); + res = accl.read_reg(accl.RANGE); + pc.printf("RANGE register value = %x \r\n",res); + if(res == 0x01 | res == 0x81 | res == 0xC1 | res == 0x41) { + //range of +/-10G + pc.printf("RANGE is +/-10G \r\n",res); + pc.printf("Sensitivity is %f \r\n",accl.axis357_sens); + } else if(res == 0x02 | res == 0x82 | res == 0xC2 | res == 0x42) { + //range of +/-20G + pc.printf("RANGE is +/-20G \r\n",res); + pc.printf("Sensitivity is %f \r\n",accl.axis357_sens); + } else if (res == 0x03 | res == 0x83 | res == 0xC3 | res == 0x43) { + //range of +/-40G + pc.printf("RANGE is +/-30G \r\n",res); + pc.printf("Sensitivity is %f \r\n",accl.axis357_sens); + } else { + pc.printf("Unable to read RANGE Register\r\n"); + + } + + //setting FILTER + //accl.set_filter_ctl_reg(accl.HPFOFF , accl.ODR3HZ); + //setting MODE 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, w, k, h; + + //reading PWR CTL Register + res = accl.read_reg(accl.POWER_CTL); + pc.printf("power control on measurement mode = %x \r\n",res); +} + +void adxl_stream_results() +{ + float x, y, z; float t; + uint32_t raw_x, raw_y, raw_z, raw_t; // save data info a file - pc.printf("x \t y \t z \t t\r\n"); - for(int i=0; i<100; 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; + pc.printf("GET device data [x, y, z, t] \r\n"); + pc.printf("x \t raw x \t y \t raw \t y \t z \t raw z \t t \t raw t \r\n"); + for(int i=0; i<20; i++) { + raw_x = accl.scanx(); + raw_y = accl.scany(); + raw_z = accl.scanz(); + x = accl.convert(raw_x)*accl.axis357_sens; + y = accl.convert(raw_y)*accl.axis357_sens; + z = accl.convert(raw_z)*accl.axis357_sens; t = 25+float(accl.scant()-1852)/(-9.05); - pc.printf("%f \t %f \t %f \t %f \r\n" , x,y,z,t); - wait(0.1);} - // test the calibration procedure - test.matrix_reset(); - pc.printf("Start calibration test (y/n)?\r\n"); - char calib = pc.getc(); - switch(calib){ - case 'y': pc.printf("Select the calibration procedure: 2point or 4point? (2/4)\r\n"); - char point = pc.getc(); - if(point == '2'){ - pc.printf("Place the device verticaly to obtain x value close to -1, press any character to start the aquisition \r\n"); - pc.getc(); - x = accl.convert(accl.scanx())*accl.axis355_sens; y = x; - for(int i=0; i<50; i++){ - x = accl.convert(accl.scanx())*accl.axis355_sens; - if (x<y) {y=x;} - pc.printf("%f \t %f \r\n" , x,y); - wait(0.1);} - pc.printf("Place the device verticaly to obtain x value close to +1, press any character to start the aquisition \r\n"); - pc.getc(); - x = accl.convert(accl.scanx())*accl.axis355_sens; z = x; - for(int i=0; i<50; i++){ - x = accl.convert(accl.scanx())*accl.axis355_sens; - if (x>z) {z=x;} - pc.printf("%f \t %f \r\n" , x,z); - wait(0.1);} - float meas[] = {z, y}; - test.convert_2p(meas, 0); - pc.printf("The input for the calibration process are: %f \t %f \r\n" , meas[0], meas[1]); - pc.printf("The result (Sensibility and Bias) is: %f \t %f \r\n" , test.adxl355_sensitivity.S[0], test.adxl355_sensitivity.B[0]); - } - else if(point == '4'){ - pc.printf("Place the device verticaly to obtain x value close to 0, press any character to start the aquisition \r\n"); - pc.getc(); - x = accl.convert(accl.scanx())*accl.axis355_sens; y = x; - for(int i=0; i<50; i++){ - x = accl.convert(accl.scanx())*accl.axis355_sens; - y=(y+x)/2; - pc.printf("%f \t %f \r\n" , x,y); - wait(0.1);} - pc.printf("Rotate the device to obtain x value close to -1, press any character to start the aquisition \r\n"); - pc.getc(); - x = accl.convert(accl.scanx())*accl.axis355_sens; z = x; - for(int i=0; i<50; i++){ - x = accl.convert(accl.scanx())*accl.axis355_sens; - if (x<z) {z=x;} - pc.printf("%f \t %f \r\n" , x,z); - wait(0.1);} - pc.printf("Place the device verticaly to obtain x value close to 0, press any character to start the aquisition \r\n"); - pc.getc(); - x = accl.convert(accl.scanx())*accl.axis355_sens; w = x; - for(int i=0; i<50; i++){ - x = accl.convert(accl.scanx())*accl.axis355_sens; - w=(w+x)/2; - pc.printf("%f \t %f \r\n" , x,w); - wait(0.1);} - pc.printf("Rotate the device verticaly to obtain x value close to +1, press any character to start the aquisition \r\n"); - pc.getc(); - x = accl.convert(accl.scanx())*accl.axis355_sens; k = x; - for(int i=0; i<50; i++){ - x = accl.convert(accl.scanx())*accl.axis355_sens; - if (x>k) {k=x;} - pc.printf("%f \t %f \r\n" , x,k); - wait(0.1);} - float meas[] = {y, z, w, k}; - test.convert_4p(meas, 0); - pc.printf("The input for the calibration process are: %f \t %f \t %f \t %f \t \r\n" , y, z, w, k); - pc.printf("The result (Sensibility and Bias) is: %f \t %f \r\n" , test.adxl355_sensitivity.S[0], test.adxl355_sensitivity.B[0]); - } - else {pc.printf("Input value not recognized \r\n"); pc.printf("%c \r\n",point);} + pc.printf("%f \t %d \t %f \t %d \t %f \t %d \t %f \t %d \r\n" , x, raw_x, y, raw_y, z, raw_z, t, raw_t); + wait(0.1); + } +} + + +int main() +{ + pc.baud(9600); + pc.printf("SPI ADXL355 and ADXL357 Demo\r\n"); + pc.printf("04/09/2018 V1.0\r\n"); + + accl.reset(); + + adxl_init(); + + adxl_stream_results(); + + while(1) { + pc.printf("Do you want to repeat the measurement (y/n)?\r\n"); + char calib = pc.getc(); + switch(calib) { + case 'y': { + adxl_stream_results(); break; - case 'n': pc.printf("No calibration test \r\n"); - break; - default: pc.printf("Input value not recognized \r\n"); + } + case 'n': { + pc.printf("Thank you for evaluating the ADXL355/357\r\n"); + pc.printf("You may now close the serial terminal\r\n"); break; - } - // test reading angle - pc.printf("Start reading angle after calibration (y/n)?\r\n"); - calib = pc.getc(); - switch(calib){ - case 'y': pc.printf("Select the procedure for angle measurement: 1axis, 2axis or 3axis? (1/2/3)\r\n"); - char point = pc.getc(); - pc.printf("x \t y \t z \t pitch \t roll \t tau \r\n"); - if(point == '1'){ - 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; - w = asin(x/9.81)*180/pi; - k = asin(y/9.81)*180/pi; - h = asin(z/9.81)*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; - w = atan(x/z)*180/pi;; - k = atan(y/z)*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; - 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; - 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 {pc.printf("Input value not recognized \r\n"); pc.printf("%c \r\n",point);} + } + default: + pc.printf("Input value not recognized, try again! \r\n"); break; - case 'n': pc.printf("No calibration test \r\n"); - break; - default: pc.printf("Input value not recognized \r\n"); - break; - } + } + } } - \ No newline at end of file