Qmax / Mbed 2 deprecated LIS_Accelerometer_WIP

Dependencies:   mbed

Committer:
subinmbed
Date:
Sat Sep 02 11:09:35 2017 +0000
Revision:
2:c4fb968de7d3
Parent:
0:491bc4ee502e
Accelerometer commented

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bala0x07 0:491bc4ee502e 1
bala0x07 0:491bc4ee502e 2 /*
bala0x07 0:491bc4ee502e 3 _____________________________________________________________________________________________________
bala0x07 0:491bc4ee502e 4
bala0x07 0:491bc4ee502e 5 >>> ACTIVITY & INACTIVITY Interrupts to be configured on INT1 pin
bala0x07 0:491bc4ee502e 6 >>> CLICK & DOUBLE CLICK Interrupt to be configured on INT2 pin
bala0x07 0:491bc4ee502e 7
bala0x07 0:491bc4ee502e 8 NOTE :
bala0x07 0:491bc4ee502e 9 -----
bala0x07 0:491bc4ee502e 10 Leave the SA0 pin as it is and fix the slave address 32h
bala0x07 0:491bc4ee502e 11 __________29/7/17
bala0x07 0:491bc4ee502e 12 now via interrupt we can read SRC
bala0x07 0:491bc4ee502e 13
bala0x07 0:491bc4ee502e 14 _____________________________________________________________________________________________________
bala0x07 0:491bc4ee502e 15
bala0x07 0:491bc4ee502e 16 LAST UPDATED : 15-JUN-2017 (WEDNESDAY)
bala0x07 0:491bc4ee502e 17
bala0x07 0:491bc4ee502e 18 ____________________
bala0x07 0:491bc4ee502e 19
bala0x07 0:491bc4ee502e 20 Author : >> BALA <<
bala0x07 0:491bc4ee502e 21 ____________________
bala0x07 0:491bc4ee502e 22 _____________________________________________________________________________________________________
bala0x07 0:491bc4ee502e 23
bala0x07 0:491bc4ee502e 24 */
bala0x07 0:491bc4ee502e 25
bala0x07 0:491bc4ee502e 26 /*
bala0x07 0:491bc4ee502e 27 *****************************************************************************************************
bala0x07 0:491bc4ee502e 28 REFRENCES :
bala0x07 0:491bc4ee502e 29 ----------
bala0x07 0:491bc4ee502e 30 >>> SLAVE ADDRESS : 1001 A2 A1 A0 R/W : Page : 7 (Datasheet)
bala0x07 0:491bc4ee502e 31 >>> TEMPERATURE OVERSHOOT SHUTDOWN REG CONFIGURATION : Page : 10 (Datasheet)
bala0x07 0:491bc4ee502e 32
bala0x07 0:491bc4ee502e 33 *****************************************************************************************************
bala0x07 0:491bc4ee502e 34 */
bala0x07 0:491bc4ee502e 35
bala0x07 0:491bc4ee502e 36
bala0x07 0:491bc4ee502e 37 #include "mbed.h"
bala0x07 0:491bc4ee502e 38 #include "main.h"
subinmbed 2:c4fb968de7d3 39 #include "OBD.h"
subinmbed 2:c4fb968de7d3 40 #include "ACCELEROMETER.h"
bala0x07 0:491bc4ee502e 41
bala0x07 0:491bc4ee502e 42
subinmbed 2:c4fb968de7d3 43
bala0x07 0:491bc4ee502e 44 InterruptIn change(PC_6); // INT1
bala0x07 0:491bc4ee502e 45 InterruptIn jerk(PB_15); //INT2
bala0x07 0:491bc4ee502e 46 DigitalOut ACC_LED(PC_10);
subinmbed 2:c4fb968de7d3 47 I2C i2c(PB_14, PB_13);
bala0x07 0:491bc4ee502e 48
bala0x07 0:491bc4ee502e 49 #define acc_address 0x32
subinmbed 2:c4fb968de7d3 50 int TIMING_M;
subinmbed 2:c4fb968de7d3 51 float speed_m=1;
subinmbed 2:c4fb968de7d3 52 Serial pc(PC_0, NC,115200);
subinmbed 2:c4fb968de7d3 53 char JERK_FLAG=0,MOVEMENT_FLAG=0,MOTION=0,START_TO_MOVING=0,MOVING_TO_STOP=0,PRE_MOVING=0,MOTION_FIRST_STEP=0;
subinmbed 2:c4fb968de7d3 54 float TIMING=0,FIRST_TIME=0,CURRENT_TIME=0;
bala0x07 0:491bc4ee502e 55
bala0x07 0:491bc4ee502e 56
bala0x07 0:491bc4ee502e 57 void movement_inertia()
bala0x07 0:491bc4ee502e 58 {
subinmbed 2:c4fb968de7d3 59 pc.printf("\nmvmnt");
bala0x07 0:491bc4ee502e 60 MOVEMENT_FLAG=1;
subinmbed 2:c4fb968de7d3 61 if(fetch_vehicle_speed()>speed_m) //after interrupt comes and speed is there
subinmbed 2:c4fb968de7d3 62 {
subinmbed 2:c4fb968de7d3 63 MOTION=1;
subinmbed 2:c4fb968de7d3 64 MOTION_FIRST_STEP=1; //local flag for main
subinmbed 2:c4fb968de7d3 65
subinmbed 2:c4fb968de7d3 66 }
subinmbed 2:c4fb968de7d3 67 // else if(MOVING_FLAG)
subinmbed 2:c4fb968de7d3 68 // {
subinmbed 2:c4fb968de7d3 69 // pc.printf("MOVING_TO_STOP");
subinmbed 2:c4fb968de7d3 70 // ACC_LED=0;
subinmbed 2:c4fb968de7d3 71 // MOVING_FLAG=0;
subinmbed 2:c4fb968de7d3 72 // }
subinmbed 2:c4fb968de7d3 73 else
subinmbed 2:c4fb968de7d3 74 {
subinmbed 2:c4fb968de7d3 75 MOVING_TO_STOP=0;
subinmbed 2:c4fb968de7d3 76 START_TO_MOVING=0;
subinmbed 2:c4fb968de7d3 77 ACC_LED=0;
subinmbed 2:c4fb968de7d3 78 }
bala0x07 0:491bc4ee502e 79 }
bala0x07 0:491bc4ee502e 80
bala0x07 0:491bc4ee502e 81 //____________________________________________________________________________________________________
bala0x07 0:491bc4ee502e 82
bala0x07 0:491bc4ee502e 83 void sudden_jerk()
bala0x07 0:491bc4ee502e 84 {
subinmbed 2:c4fb968de7d3 85 pc.printf("\njerk");
subinmbed 2:c4fb968de7d3 86 JERK_FLAG=1; //now nowere it is clearing once it is set
bala0x07 0:491bc4ee502e 87 }
bala0x07 0:491bc4ee502e 88 //____________________________________________________________________________________________________
bala0x07 0:491bc4ee502e 89 int main()
bala0x07 0:491bc4ee502e 90 {
subinmbed 2:c4fb968de7d3 91 change.rise(&movement_inertia);
subinmbed 2:c4fb968de7d3 92 jerk.rise(&sudden_jerk);
subinmbed 2:c4fb968de7d3 93 initialize_obd();
subinmbed 2:c4fb968de7d3 94 initialise_configure_accelerometer();
bala0x07 0:491bc4ee502e 95
subinmbed 2:c4fb968de7d3 96
bala0x07 0:491bc4ee502e 97 while(1)
bala0x07 0:491bc4ee502e 98 {
subinmbed 2:c4fb968de7d3 99 if(MOTION_FIRST_STEP) //if movement interrupt comes
subinmbed 2:c4fb968de7d3 100 {
subinmbed 2:c4fb968de7d3 101 MOTION_FIRST_STEP=0;
subinmbed 2:c4fb968de7d3 102 process_accelerometer();
subinmbed 2:c4fb968de7d3 103 }
subinmbed 2:c4fb968de7d3 104 if((PRE_MOVING)&&(fetch_vehicle_speed()<1))//for ensuring stop if there is no movement interrupt during sudden stop
subinmbed 2:c4fb968de7d3 105 {
subinmbed 2:c4fb968de7d3 106 stopped();
subinmbed 2:c4fb968de7d3 107 }
subinmbed 2:c4fb968de7d3 108 //////////////////////////////////////////////////////////
subinmbed 2:c4fb968de7d3 109 //if in motion no interrupt comes it will ckeck after 2s//
subinmbed 2:c4fb968de7d3 110 // if(TIMER_RUNNING)
subinmbed 2:c4fb968de7d3 111 // {
subinmbed 2:c4fb968de7d3 112 // CURRENT_TIME=t.read();
subinmbed 2:c4fb968de7d3 113 // pc.printf("\nTIMER_RUNNING");
subinmbed 2:c4fb968de7d3 114 // if((CURRENT_TIME-FIRST_TIME)>2)
subinmbed 2:c4fb968de7d3 115 // {
subinmbed 2:c4fb968de7d3 116 // process_accelerometer();
subinmbed 2:c4fb968de7d3 117 // TIMER_RUNNING=0;
subinmbed 2:c4fb968de7d3 118 // FIRST=1;
subinmbed 2:c4fb968de7d3 119 // }
subinmbed 2:c4fb968de7d3 120 // }
subinmbed 2:c4fb968de7d3 121 ////////////////////////////////////////////////////////
bala0x07 0:491bc4ee502e 122
bala0x07 0:491bc4ee502e 123 }
subinmbed 2:c4fb968de7d3 124 return 0;
bala0x07 0:491bc4ee502e 125 }
bala0x07 0:491bc4ee502e 126
bala0x07 0:491bc4ee502e 127 //____________________________________________________________________________________________________