Second part of midterm
Dependencies: MMA8451Q8b SLCD mbed
Fork of KL46z_single_tap_2017 by
Revision 13:df4917c65cc7, committed 2017-03-15
- Comitter:
- mireyarod23
- Date:
- Wed Mar 15 14:29:24 2017 +0000
- Parent:
- 12:4774c4fc718e
- Commit message:
- Second part of mid term
Changed in this revision
KL46z_single_tap_2016..cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 4774c4fc718e -r df4917c65cc7 KL46z_single_tap_2016..cpp --- a/KL46z_single_tap_2016..cpp Tue Mar 14 16:42:14 2017 +0000 +++ b/KL46z_single_tap_2016..cpp Wed Mar 15 14:29:24 2017 +0000 @@ -25,19 +25,27 @@ #define MAX_2G 0x00 #define MAX_4G 0x01 #define MAX_8G 0x02 -#define SET_INTERRUPT 0x08 //using interrupt INT1 PTC5 -#define SET_INT_LINE 0x08 -#define SET_THZ 0x20 // See Table 49 in data sheet + +#define SET_INTERRUPT 0x20 //using interrupt INT1 PTC5 CTRL_REG4 0d1010 0000 +#define SET_INT_LINE 0x00 // CTRL_REG5 register 0d0000 0000 all set to zero to user int2 + +/********** +Where to set the pulse +PULSE_CFG for double tap +0d0110 0000 = 60 +**********/ + +#define SET_THZ 0x28 // See Table 49 in data sheet /*********** 0b0010 0000 -2g/0.063g/count = 32 counts +4g/0.063g/count = 40 counts = 0d1010 0000 ************/ #define SET_TMLT 0x18 // See Talbe 51 in data sheet /****** 0b0001 1000 24 = 0x18 -time step at 800Hz ODR = 0.625ms -24x0.625 = 15 ms +time step at 400Hz ODR = 2.5ms +24x 1.25 = 28 ms = 1C ******/ //#define PRINTDBUG @@ -65,6 +73,7 @@ int relayState = RELAYOFF; int outState = false; SLCD slcd; //define LCD display +Serial pc(USBTX, USBRX); // set up USB as communications to Host PC via USB connectons char LCDMessages[2][LCDLEN] = {"TRUE", "FALS"}; @@ -98,7 +107,7 @@ int main() { uint8_t regData; - uint8_t latchData = 0x40; //0b01000000; //for pulse config register + uint8_t latchData = 0x60; //0b01100000; //for pulse config register double tap uint8_t axisData = 0x10; //0b00010000; char lcdData[LCDLEN]; @@ -116,6 +125,7 @@ // Read Pulse Source Data and check to see if things have been set acc.readRegs(REG_PULSE_CFG, ®Data, 1); // check it sprintf (lcdData,"%x",regData); + pc.printf("Source register","%x",regData); // source register LCDMess(lcdData,BLINKTIME); // *********** Initialize for tap tecognition *********** @@ -123,6 +133,7 @@ acc.setRegisterInStandby(REG_PULSE_CFG, regData); // write the data acc.readRegs(REG_PULSE_CFG, ®Data, 1); // check it sprintf (lcdData,"%x",regData); + LCDMess(lcdData,BLINKTIME); // Check to see if accerlometer is alive and well @@ -133,21 +144,30 @@ // Setup single-tap pulse prarameters. acc.setRegisterInStandby(REG_PULSE_THSZ, SET_THZ); // write the data - acc.setRegisterInStandby(REH_PULSE_TMLT, SET_TMLT); // write the data + acc.readRegs(SET_THZ, ®Data, 1); + pc.printf("Threshold", "%",regData); // Return thresholdz registery + + acc.setRegisterInStandby(REH_PULSE_TMLT, SET_TMLT); // write the data + acc.readRegs(SET_TMLT, ®Data, 1); + pc.printf("Time limit", "%",regData); // Return time limit registery -// Set up (pulse) interrupt to INT1 pin +// Set up (pulse) interrupt to INT2 pin acc.setRegisterInStandby(REG_CTRL_4, SET_INTERRUPT); // write the data + pc.printf("REG_4", SET_INTERRUPT ); acc.setRegisterInStandby(REG_CTRL_5, SET_INT_LINE); // write the data + pc.printf("REG_5", SET_INT_LINE ); // End or seetup acc.readRegs(REG_WHO_AM_I, ®Data, 1); sprintf (lcdData,"%x",regData); + pc.printf("Main REG", "%x",regData); LCDMess(lcdData,BLINKTIME); while (true) { acc.readRegs(REG_PULSE_SRC, ®Data, 1); sprintf (lcdData,"%x",regData); + pc.printf("Reg pulse", "%x", regData); LCDMess(lcdData,BLINKTIME); LCDMessNoDwell(LCDMessages[relayState]); wait(delay);