Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@1:ecd469d7323d, 2017-09-01 (annotated)
- Committer:
- subinmbed
- Date:
- Fri Sep 01 17:58:24 2017 +0000
- Revision:
- 1:ecd469d7323d
- Parent:
- 0:491bc4ee502e
Accelerometer:completed with enable and disable option,need to check in real car(threshold changing functions not included)
Who changed what in which revision?
| User | Revision | Line number | New 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 | 1:ecd469d7323d | 39 | #include "OBD.h" |
| subinmbed | 1:ecd469d7323d | 40 | #include "ACCELEROMETER.h" |
| bala0x07 | 0:491bc4ee502e | 41 | |
| bala0x07 | 0:491bc4ee502e | 42 | |
| subinmbed | 1:ecd469d7323d | 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 | 1:ecd469d7323d | 47 | I2C i2c(PB_14, PB_13); |
| bala0x07 | 0:491bc4ee502e | 48 | |
| bala0x07 | 0:491bc4ee502e | 49 | #define acc_address 0x32 |
| subinmbed | 1:ecd469d7323d | 50 | int TIMING_M; |
| subinmbed | 1:ecd469d7323d | 51 | float speed_m=1; |
| subinmbed | 1:ecd469d7323d | 52 | Serial pc(PC_0, NC,115200); |
| subinmbed | 1:ecd469d7323d | 53 | char JERK_FLAG=0,MOVEMENT_FLAG=0,MOTION=0,START_TO_MOVING=0,MOVING_TO_STOP=0,NO_MOVING=0,MOTION_FIRST_STEP=0; |
| subinmbed | 1:ecd469d7323d | 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 | 1:ecd469d7323d | 59 | pc.printf("\nmvmnt"); |
| bala0x07 | 0:491bc4ee502e | 60 | MOVEMENT_FLAG=1; |
| subinmbed | 1:ecd469d7323d | 61 | if(fetch_vehicle_speed()>speed_m) |
| subinmbed | 1:ecd469d7323d | 62 | { |
| subinmbed | 1:ecd469d7323d | 63 | MOTION=1; |
| subinmbed | 1:ecd469d7323d | 64 | MOTION_FIRST_STEP=1; |
| subinmbed | 1:ecd469d7323d | 65 | |
| subinmbed | 1:ecd469d7323d | 66 | } |
| subinmbed | 1:ecd469d7323d | 67 | // else if(MOVING_FLAG) |
| subinmbed | 1:ecd469d7323d | 68 | // { |
| subinmbed | 1:ecd469d7323d | 69 | // pc.printf("MOVING_TO_STOP"); |
| subinmbed | 1:ecd469d7323d | 70 | // ACC_LED=0; |
| subinmbed | 1:ecd469d7323d | 71 | // MOVING_FLAG=0; |
| subinmbed | 1:ecd469d7323d | 72 | // } |
| subinmbed | 1:ecd469d7323d | 73 | else |
| subinmbed | 1:ecd469d7323d | 74 | { |
| subinmbed | 1:ecd469d7323d | 75 | MOVING_TO_STOP=0; |
| subinmbed | 1:ecd469d7323d | 76 | START_TO_MOVING=0; |
| subinmbed | 1:ecd469d7323d | 77 | ACC_LED=0; |
| subinmbed | 1:ecd469d7323d | 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 | 1:ecd469d7323d | 85 | pc.printf("\njerk"); |
| bala0x07 | 0:491bc4ee502e | 86 | JERK_FLAG=1; |
| bala0x07 | 0:491bc4ee502e | 87 | } |
| bala0x07 | 0:491bc4ee502e | 88 | //____________________________________________________________________________________________________ |
| bala0x07 | 0:491bc4ee502e | 89 | int main() |
| bala0x07 | 0:491bc4ee502e | 90 | { |
| subinmbed | 1:ecd469d7323d | 91 | change.rise(&movement_inertia); |
| subinmbed | 1:ecd469d7323d | 92 | jerk.rise(&sudden_jerk); |
| subinmbed | 1:ecd469d7323d | 93 | initialize_obd(); |
| subinmbed | 1:ecd469d7323d | 94 | initialise_configure_accelerometer(); |
| bala0x07 | 0:491bc4ee502e | 95 | |
| subinmbed | 1:ecd469d7323d | 96 | |
| bala0x07 | 0:491bc4ee502e | 97 | while(1) |
| bala0x07 | 0:491bc4ee502e | 98 | { |
| subinmbed | 1:ecd469d7323d | 99 | if(MOTION_FIRST_STEP) |
| subinmbed | 1:ecd469d7323d | 100 | { |
| subinmbed | 1:ecd469d7323d | 101 | MOTION_FIRST_STEP=0; |
| subinmbed | 1:ecd469d7323d | 102 | process_accelerometer(); |
| subinmbed | 1:ecd469d7323d | 103 | } |
| subinmbed | 1:ecd469d7323d | 104 | if((NO_MOVING)&&(fetch_vehicle_speed()<1)) |
| subinmbed | 1:ecd469d7323d | 105 | { |
| subinmbed | 1:ecd469d7323d | 106 | stopped(); |
| subinmbed | 1:ecd469d7323d | 107 | } |
| subinmbed | 1:ecd469d7323d | 108 | ////////////////////////////////////////////////////////// |
| subinmbed | 1:ecd469d7323d | 109 | //if in motion no interrupt comes it will ckeck after 2s// |
| subinmbed | 1:ecd469d7323d | 110 | // if(TIMER_RUNNING) |
| subinmbed | 1:ecd469d7323d | 111 | // { |
| subinmbed | 1:ecd469d7323d | 112 | // CURRENT_TIME=t.read(); |
| subinmbed | 1:ecd469d7323d | 113 | // pc.printf("\nTIMER_RUNNING"); |
| subinmbed | 1:ecd469d7323d | 114 | // if((CURRENT_TIME-FIRST_TIME)>2) |
| subinmbed | 1:ecd469d7323d | 115 | // { |
| subinmbed | 1:ecd469d7323d | 116 | // process_accelerometer(); |
| subinmbed | 1:ecd469d7323d | 117 | // TIMER_RUNNING=0; |
| subinmbed | 1:ecd469d7323d | 118 | // FIRST=1; |
| subinmbed | 1:ecd469d7323d | 119 | // } |
| subinmbed | 1:ecd469d7323d | 120 | // } |
| subinmbed | 1:ecd469d7323d | 121 | //////////////////////////////////////////////////////// |
| bala0x07 | 0:491bc4ee502e | 122 | |
| bala0x07 | 0:491bc4ee502e | 123 | } |
| subinmbed | 1:ecd469d7323d | 124 | return 0; |
| bala0x07 | 0:491bc4ee502e | 125 | } |
| bala0x07 | 0:491bc4ee502e | 126 | |
| bala0x07 | 0:491bc4ee502e | 127 | //____________________________________________________________________________________________________ |