base program for tilt measurement
Dependencies: COG4050_ADT7420 ADXL362
Fork of COG4050_adxl355_adxl357-ver2 by
Revision 6:45d2393ef468, committed 2018-08-14
- Comitter:
- vtoffoli
- Date:
- Tue Aug 14 06:49:07 2018 +0000
- Parent:
- 5:05af38b6375a
- Child:
- 7:5aaa09c40283
- Commit message:
- update 14.08.2018
Changed in this revision
--- a/ADXL35x/ADXL355.cpp Wed Aug 08 12:13:05 2018 +0000
+++ b/ADXL35x/ADXL355.cpp Tue Aug 14 06:49:07 2018 +0000
@@ -3,7 +3,6 @@
#include "ADXL355.h"
-//DigitalOut(cs); ///< DigitalOut instance for the chipselect of the ADXL
//DigitalOut int1; ///< DigitalOut instance for the chipselect of the ADXL
//DigitalOut int2; ///< DigitalOut instance for the chipselect of the ADXL
@@ -12,6 +11,8 @@
cs = 1;
adxl355.format(8,_SPI_MODE);
adxl355.lock();
+ axis355_sens = 3.9e-6;
+ axis357_sens = 19.5e-6;
}
/** SPI bus frequency */
@@ -28,6 +29,8 @@
// Writing Code 0x52 (representing the letter, R, in ASCII or unicode) to this register immediately resets the ADXL362.
write_reg(RESET, _RESET);
cs = true;
+ axis355_sens = 3.9e-6;
+ axis357_sens = 19.5e-6;
}
/** ----------------------------------- */
/** Writes the reg register with data */
@@ -72,12 +75,12 @@
cs = true;
return ret_val;
}
-uint32_t ADXL355::read_reg_u32(ADXL355_register_t reg){
+uint32_t ADXL355::read_reg_u20(ADXL355_register_t reg){
uint32_t ret_val = 0;
adxl355.format(8, _SPI_MODE);
cs = false;
adxl355.write((reg<<1) | _READ_REG_CMD);
- ret_val = adxl355.write(_DUMMY_BYTE);
+ 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);
cs = true;
@@ -97,6 +100,20 @@
}
void ADXL355::set_device(ADXL355_range_ctl_t range) {
write_reg(RANGE, static_cast<uint8_t>(range));
+ switch(range){
+ case 0x01:
+ axis355_sens = 3.9e-6;
+ axis357_sens = 19.5e-6;
+ break;
+ case 0x02:
+ axis355_sens = 7.8e-6;
+ axis357_sens = 39e-6;
+ break;
+ case 0x03:
+ axis355_sens = 15.6e-6;
+ axis357_sens = 78e-6;
+ break;
+ }
}
/** ----------------------------------- */
/** Read the STATUS registers */
@@ -109,26 +126,37 @@
/** mode to read the data registers */
/** ----------------------------------- */
uint32_t ADXL355::scanx(){
- return read_reg_u32(XDATA3);
+ return read_reg_u20(XDATA3);
}
uint32_t ADXL355::scany(){
- return read_reg_u32(YDATA3);
+ return read_reg_u20(YDATA3);
}
uint32_t ADXL355::scanz(){
- return read_reg_u32(ZDATA3);
+ return read_reg_u20(ZDATA3);
}
uint16_t ADXL355::scant(){
return read_reg_u16(TEMP2);
}
/** ----------------------------------- */
+/** Activity SetUp - the measured */
+/** 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_cnt(uint8_t count) {}
+
+void ADXL355::set_activity_axis(ADXL355_act_ctl_t axis) {
+ write_reg(ACT_EN, axis);
+}
+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) {
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);
+}
/** ----------------------------------- */
/** ----------------------------------- */
void ADXL355::set_interrupt1_pin(PinName in, ADXL355_intmap_ctl_t mode) {}
--- a/ADXL35x/ADXL355.h Wed Aug 08 12:13:05 2018 +0000
+++ b/ADXL35x/ADXL355.h Tue Aug 14 06:49:07 2018 +0000
@@ -5,7 +5,11 @@
class ADXL355
{
public:
-
+ const static float t_sens = -9.05;
+ const static float t_bias = 1852;
+ float axis355_sens;
+ float axis357_sens;
+
// -------------------------- //
// REGISTERS //
// -------------------------- //
@@ -47,7 +51,6 @@
SELF_TEST = 0x2E,
RESET = 0x2F
} ADXL355_register_t;
-
// -------------------------- //
// REGISTERS - DEFAULT VALUES //
// -------------------------- //
@@ -103,7 +106,7 @@
RANGE2G = 0x01,
RANGE4G = 0x02,
RANGE8G = 0x03,
- RANGE10 = 0x00,
+ RANGE10 = 0x01,
RANGE20 = 0x02,
RANGE40 = 0x03
} ADXL355_range_ctl_t;
@@ -125,7 +128,7 @@
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_u32(ADXL355_register_t reg);
+ uint32_t read_reg_u20(ADXL355_register_t reg);
// 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);
--- a/ADXRS290/ADXRS290.cpp Wed Aug 08 12:13:05 2018 +0000
+++ b/ADXRS290/ADXRS290.cpp Tue Aug 14 06:49:07 2018 +0000
@@ -0,0 +1,35 @@
+#include <stdint.h>
+#include "mbed.h"
+#include "ADXRS290.h"
+
+
+ADXRS290::ADXRS290(PinName cs_pin, PinName MOSI, PinName MISO, PinName SCK): adxrs290(MOSI, MISO, SCK), cs(cs_pin)
+{
+ cs = 1;
+ adxrs290.format(8,_SPI_MODE);
+ adxrs290.lock();
+ gyro_sens = 5e-3;
+ t_sens = 0.1;
+}
+
+/** SPI bus frequency */
+void ADXRS290::frequency(int hz)
+{
+ adxrs290.frequency(hz);
+}
+
+/** ----------------------------------- */
+/** Writes the reg register with data */
+/** ----------------------------------- */
+void ADXRS290::write_reg(ADXRS290_register_t reg, uint8_t data){}
+uint8_t ADXRS290::read_reg(ADXRS290_register_t reg){}
+uint16_t ADXRS290::read_reg_u16(ADXRS290_register_t reg){}
+
+void ADXRS290::set_power_ctl_reg(uint8_t data){}
+void ADXRS290::set_filter_ctl_reg(ADXRS290_filter_ctl_t hpf, ADXRS290_filter_ctl_t odr){}
+void ADXRS290::set_sync(ADXRS290_dataready_ctl_t data){}
+
+uint16_t ADXRS290::scanx(){}
+uint16_t ADXRS290::scany(){}
+uint16_t ADXRS290::scant(){}
+
\ No newline at end of file
--- a/ADXRS290/ADXRS290.h Wed Aug 08 12:13:05 2018 +0000
+++ b/ADXRS290/ADXRS290.h Tue Aug 14 06:49:07 2018 +0000
@@ -0,0 +1,106 @@
+
+#ifndef ADXRS290_H_
+#define ADXRS290_H_
+
+class ADXRS290
+{
+public:
+ float gyro_sens;
+ float t_sens;
+ // -------------------------- //
+ // REGISTERS //
+ // -------------------------- //
+ typedef enum {
+ DEVID_AD = 0x00,
+ DEVID_MST = 0x01,
+ PARTID = 0x02,
+ REVID = 0x03,
+ SN0 = 0x04,
+ SN1 = 0x05,
+ SN2 = 0x06,
+ SN3 = 0x07,
+ DATAX0 = 0x08,
+ DATAX1 = 0x09,
+ DATAY0 = 0x0A,
+ DATAY1 = 0x0B,
+ TEMP0 = 0x0C,
+ TEMP1 = 0x0D,
+ POWER_CTL = 0x10,
+ FILTER = 0x11,
+ DATA_READY = 0x12
+ } ADXRS290_register_t;
+ // -------------------------- //
+ // REGISTERS - DEFAULT VALUES //
+ // -------------------------- //
+ // Modes - POWER_CTL
+ typedef enum {
+ TEMP_ON = 0x00,
+ TEMP_OFF = 0x01,
+ STANDBY = 0x00,
+ MEASUREMENT = 0x02
+ } ADXL355_modes_t;
+ // High-Pass and Low-Pass Filter - FILTER
+ typedef enum {
+ LPF480 = 0x00,
+ LPF320 = 0x01,
+ LPF160 = 0x02,
+ LPF80 = 0x03,
+ LPF56 = 0x04,
+ LPF40 = 0x05,
+ LPF28 = 0x06,
+ LPF20 = 0x07,
+ HPFOFF = 0x00,
+ HPF001 = 0x10,
+ HPF002 = 0x20,
+ HPF004 = 0x30,
+ HPF008 = 0x40,
+ HPF017 = 0x50,
+ HPF035 = 0x60,
+ HPF070 = 0x70,
+ HPF140 = 0x80,
+ HPF280 = 0x90,
+ HPF1130 = 0xA0
+ } ADXRS290_filter_ctl_t;
+ // External timing register - INT_MAP
+ typedef enum {
+ OVR_EN = 0x04,
+ FULL_EN = 0x02,
+ RDY_EN = 0x01
+ } ADXRS290_intmap_ctl_t;
+ // External timing register - SYNC
+ typedef enum {
+ ANAL_SYNC = 0x00,
+ DIGI_SYNC = 0x01
+ } ADXRS290_dataready_ctl_t;
+
+ // -------------------------- //
+ // FUNCTIONS //
+ // -------------------------- //
+ // SPI configuration & constructor
+ ADXRS290(PinName cs_pin , PinName MOSI , PinName MISO , PinName SCK );
+ void frequency(int hz);
+ // SPI configuration & constructor
+ void write_reg(ADXRS290_register_t reg, uint8_t data);
+ uint8_t read_reg(ADXRS290_register_t reg);
+ uint16_t read_reg_u16(ADXRS290_register_t reg);
+ // ADXRS general register R/W methods
+ void set_power_ctl_reg(uint8_t data);
+ void set_filter_ctl_reg(ADXRS290_filter_ctl_t hpf, ADXRS290_filter_ctl_t odr);
+ void set_sync(ADXRS290_dataready_ctl_t data);
+ // ADXRS X/Y/T scanning methods
+ uint16_t scanx();
+ uint16_t scany();
+ uint16_t scant();
+ // ADXRS tilt methods and calibration
+ // TBD
+private:
+ // SPI adxl355; ///< SPI instance of the ADXL
+ SPI adxrs290; DigitalOut cs;
+ const static uint8_t _DEVICE_AD = 0x92; // contect of DEVID_AD (only-read) register
+ 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 = 0x80; // read register
+ const static uint8_t _SPI_MODE = 4; // timing scheme
+};
+
+#endif
\ No newline at end of file
--- a/README.md Wed Aug 08 12:13:05 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ - -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/READMEcalibration.md Tue Aug 14 06:49:07 2018 +0000 @@ -0,0 +1,23 @@ +/* ----------------------------------------------------------------------------- +/* ADXL calibration equation +/* ----------------------------------------------------------------------------- + +|acx| |pxx pxy pxz| |ax| |bx| +|acy| = |pyx pyy pyz|*|ay|+|by| +|acz| |pzx pzy pzz| |az| |bz| + +/* ----------------------------------------------------------------------------- +/* ADXL calibration procedures +/* ----------------------------------------------------------------------------- + +2 MEASUREMENT ORIENTATIONS: the orientations are selected to give an equal +posit5ive gravitational filed of g/sqrt(3) in each axis followed by -g/sqrt(3) +in each axis +We assumed that pij=0 when i!=j + + +3 MEASUREMENT ORIENTATIONS +4 MEASUREMENT ORIENTATIONS +6 MEASUREMENT ORIENTATIONS +8 MEASUREMENT ORIENTATIONS +12 MEASUREMENT ORIENTATIONS \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/READMEconnection.md Tue Aug 14 06:49:07 2018 +0000 @@ -0,0 +1,14 @@ + +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 + +
--- a/main.cpp Wed Aug 08 12:13:05 2018 +0000
+++ b/main.cpp Tue Aug 14 06:49:07 2018 +0000
@@ -5,7 +5,19 @@
Serial pc(USBTX, USBRX);
ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK); // PMOD port
+
+float convert(uint32_t data){
+ // If a positive value, return it
+ if ((data & 0x80000) == 0)
+ {
+ return float(data);
+ }
+ //uint32_t rawValue = data<<(32-nbit);
+ // Otherwise perform the 2's complement math on the value
+ return float((~(data - 0x01)) & 0xfffff) * -1;
+ }
+
int main(){
pc.baud(9600);
pc.printf("SPI ADXL355 and ADXL357 Demo\n");
@@ -24,15 +36,15 @@
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);
- uint32_t x,y,z;
- uint16_t t;
+ float x, y,z;
+ float t;
while(1) {
- x = accl.scanx();
- y = accl.scany();
- z = accl.scanz();
- t = accl.scant();
- pc.printf("%u \t %u \t %u \t %u \r\n" , x,y,z,t);
- wait(1.0);
+ x = convert(accl.scanx())*accl.axis355_sens;
+ y = convert(accl.scany())*accl.axis355_sens;
+ z = convert(accl.scanz())*accl.axis355_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.50);
}
}
-
+
\ No newline at end of file
