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
ACCELEROMETER.cpp@2:c4fb968de7d3, 2017-09-02 (annotated)
- Committer:
- subinmbed
- Date:
- Sat Sep 02 11:09:35 2017 +0000
- Revision:
- 2:c4fb968de7d3
Accelerometer commented
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| subinmbed | 2:c4fb968de7d3 | 1 | |
| subinmbed | 2:c4fb968de7d3 | 2 | #include "mbed.h" |
| subinmbed | 2:c4fb968de7d3 | 3 | #include "ACCELEROMETER.h" |
| subinmbed | 2:c4fb968de7d3 | 4 | #include "OBD.h" |
| subinmbed | 2:c4fb968de7d3 | 5 | #include "main.h" |
| subinmbed | 2:c4fb968de7d3 | 6 | |
| subinmbed | 2:c4fb968de7d3 | 7 | |
| subinmbed | 2:c4fb968de7d3 | 8 | #define acc_address 0x32 |
| subinmbed | 2:c4fb968de7d3 | 9 | int i=0,j=0,Steady_cnt=0; |
| subinmbed | 2:c4fb968de7d3 | 10 | char src_data[1],FIRST=1,SECOND,MOVING_FLAG=0,TIMER_RUNNING; |
| subinmbed | 2:c4fb968de7d3 | 11 | unsigned int int1_src_data,cnt=0; |
| subinmbed | 2:c4fb968de7d3 | 12 | char acc_reg[1] = {0x29}; |
| subinmbed | 2:c4fb968de7d3 | 13 | char acc_data[6]; |
| subinmbed | 2:c4fb968de7d3 | 14 | //char int1_dur[2] = {0x33, 0x70}; |
| subinmbed | 2:c4fb968de7d3 | 15 | long speed,FIRST_SPEED=0,CURRENT_SPEED=0; |
| subinmbed | 2:c4fb968de7d3 | 16 | Timer t; |
| subinmbed | 2:c4fb968de7d3 | 17 | void configure_accelerometer() |
| subinmbed | 2:c4fb968de7d3 | 18 | { |
| subinmbed | 2:c4fb968de7d3 | 19 | /* |
| subinmbed | 2:c4fb968de7d3 | 20 | char ctrl_reg_0[2] = {0x1E, 0x10}; // SA0 Internal pullup Enabled |
| subinmbed | 2:c4fb968de7d3 | 21 | char ctrl_reg_1[2] = {0x20, 0x2F}; // ODR -> 10Hz, X,Y,Z axis Enabled |
| subinmbed | 2:c4fb968de7d3 | 22 | char ctrl_reg_2[2] = {0x21, 0x8E}; // High pass filter enabled for CLICK function, cutoff : 0.2Hz, High pass filter AOI function is routed to INT2 pin |
| subinmbed | 2:c4fb968de7d3 | 23 | char ctrl_reg_3[2] = {0x22, 0x40}; // (Default value of this register is 0x00, so eliminate this statement later)...Disable CLICK, IA, ZYXDA, WTM, OVERRUN interrupts on INT1 pin..... |
| subinmbed | 2:c4fb968de7d3 | 24 | char ctrl_reg_4[2] = {0x23, 0x80}; // BDU enabled, 2g full scale selection, Self test diabled |
| subinmbed | 2:c4fb968de7d3 | 25 | char ctrl_reg_5[2] = {0x24, 0x40}; // Reboot memory content disabled, FIFO enabled, Interrupt request not latched on INT1 & INT2, 4D detection disbaled |
| subinmbed | 2:c4fb968de7d3 | 26 | char ctrl_reg_6[2] = {0x25, 0xA0}; // CLICK Interrupt on INT2 pin, INT1 function on INT2 pin disabled, INT2 function on INt2 pin enabled, BOOT on INT2 pi disabled, Activity on INT2 pin disabled, INT1 & INT2 pin polarity is set to active HIGH |
| subinmbed | 2:c4fb968de7d3 | 27 | char fifo_ctrl_reg[2] = {0x2E, 0x80}; // STREAM Mode selected, Trigger event allows triggerring signal on INT1, WATER MARK LEVEL set to 0 (default value) |
| subinmbed | 2:c4fb968de7d3 | 28 | char int1_cfg[2] = {0x30, 0x1F}; // OR combination of interrupts, Interrupts enabled for all X/Y/Z high and low except Z-high event |
| subinmbed | 2:c4fb968de7d3 | 29 | char int1_ths[2] = {0x32, 7}; // For 2g Full scale, 1LSB = 16mg, Aim : Threshold : 100mg, 100/16 = 6.25, rounded to '7' |
| subinmbed | 2:c4fb968de7d3 | 30 | char int1_dur[2] = {0x33, (50 & 127)}; // Configured for 5sec : Duration time = N / ODR ; N = time * ODR = 5 * 10 = '50' (Value should not exceed 127) |
| subinmbed | 2:c4fb968de7d3 | 31 | |
| subinmbed | 2:c4fb968de7d3 | 32 | i2c.write(acc_address, ctrl_reg_0, 2); |
| subinmbed | 2:c4fb968de7d3 | 33 | i2c.write(acc_address, ctrl_reg_1, 2); |
| subinmbed | 2:c4fb968de7d3 | 34 | i2c.write(acc_address, ctrl_reg_2, 2); |
| subinmbed | 2:c4fb968de7d3 | 35 | i2c.write(acc_address, ctrl_reg_3, 2); |
| subinmbed | 2:c4fb968de7d3 | 36 | i2c.write(acc_address, ctrl_reg_4, 2); |
| subinmbed | 2:c4fb968de7d3 | 37 | i2c.write(acc_address, ctrl_reg_5, 2); |
| subinmbed | 2:c4fb968de7d3 | 38 | i2c.write(acc_address, ctrl_reg_6, 2); |
| subinmbed | 2:c4fb968de7d3 | 39 | i2c.write(acc_address, fifo_ctrl_reg, 2); |
| subinmbed | 2:c4fb968de7d3 | 40 | i2c.write(acc_address, int1_cfg, 2); |
| subinmbed | 2:c4fb968de7d3 | 41 | i2c.write(acc_address, int1_ths, 2); |
| subinmbed | 2:c4fb968de7d3 | 42 | i2c.write(acc_address, int1_dur, 2); |
| subinmbed | 2:c4fb968de7d3 | 43 | |
| subinmbed | 2:c4fb968de7d3 | 44 | char ver_data[1]; |
| subinmbed | 2:c4fb968de7d3 | 45 | i2c.write(acc_address, ctrl_reg_1, 1); |
| subinmbed | 2:c4fb968de7d3 | 46 | i2c.read(acc_address, ver_data, 1); |
| subinmbed | 2:c4fb968de7d3 | 47 | pc.printf("\r\n\r\n Verification data : "); |
| subinmbed | 2:c4fb968de7d3 | 48 | print_data_bits(ver_data[0]); |
| subinmbed | 2:c4fb968de7d3 | 49 | */ |
| subinmbed | 2:c4fb968de7d3 | 50 | |
| subinmbed | 2:c4fb968de7d3 | 51 | char ctrl_reg_0[2] = {0x1E, 0x10}; //added additionally this line |
| subinmbed | 2:c4fb968de7d3 | 52 | char ctrl_reg_1[2] = {0x20, 0x21}; //[ODR3 ODR2 ODR1 ODR0 nop Zen Yen Xen]////data rate=10hz(T=100MS)and x enabled |
| subinmbed | 2:c4fb968de7d3 | 53 | char ctrl_reg_2[2] = {0x21, 0x03}; //HIGH PASS FILTER Autoreset on interrupt event BUT NOT ENABLED FOR ANY FUNCTION |
| subinmbed | 2:c4fb968de7d3 | 54 | char ctrl_reg_3[2] = {0x22, 0x40}; //INT1 on INT1, CLK_INT DISABLED |
| subinmbed | 2:c4fb968de7d3 | 55 | char ctrl_reg_4[2] = {0x23, 0x80}; //block update ENABLED #NOT NEED FOR OUR APPLICATION |
| subinmbed | 2:c4fb968de7d3 | 56 | char ctrl_reg_5[2] = {0x24, 0x04}; //4D ENABLED AND IT ACTS WITH 6D ENABLING IN OTHER REGISTER |
| subinmbed | 2:c4fb968de7d3 | 57 | char ctrl_reg_6[2] = {0x25, 0x20}; // INT2 Interrupt on INT2 pin /clk INT2 & activity INT DISABLED..FOR CLICK=0XA0 |
| subinmbed | 2:c4fb968de7d3 | 58 | |
| subinmbed | 2:c4fb968de7d3 | 59 | char int1_cfg[2] = {0x30, 0x43}; // 6D direction motion detection enabled ,XH & XL enabled |
| subinmbed | 2:c4fb968de7d3 | 60 | char int1_ths[2] = {0x32, 0x01}; //INT1 threshold value |
| subinmbed | 2:c4fb968de7d3 | 61 | char int1_dur[2] = {0x33, 0x03}; //INT1 DURATION(GIVEN VALUE *100MS) value |
| subinmbed | 2:c4fb968de7d3 | 62 | |
| subinmbed | 2:c4fb968de7d3 | 63 | char int2_cfg[2] = {0x34, 0xFF}; //6D direction position detection enabled for XYZ high OR low |
| subinmbed | 2:c4fb968de7d3 | 64 | char int2_ths[2] = {0x36, 0x01}; //INT2 threshold value |
| subinmbed | 2:c4fb968de7d3 | 65 | char int2_dur[2] = {0x37, 0x02}; //INT2 DURATION(GIVEN VALUE *100MS) value |
| subinmbed | 2:c4fb968de7d3 | 66 | |
| subinmbed | 2:c4fb968de7d3 | 67 | char act_ths[2] = {0x3E, 0x00}; //#not used .sleep_to_wake up threshold |
| subinmbed | 2:c4fb968de7d3 | 68 | char act_dur[2] = {0x3F, 0x00}; //#not used.sleep_to_wake up duration |
| subinmbed | 2:c4fb968de7d3 | 69 | |
| subinmbed | 2:c4fb968de7d3 | 70 | // char clk_cfg[2] = {0x38, 0x15}; //enable XYZ single clicks |
| subinmbed | 2:c4fb968de7d3 | 71 | // char clk_src[2] = {0x39, 0x5F}; //Enable single click |
| subinmbed | 2:c4fb968de7d3 | 72 | // char clk_ths[2] = {0x3A, 0x01}; //click threshold |
| subinmbed | 2:c4fb968de7d3 | 73 | // char clk_Tlimit[2] = {0x3B, 0x03}; //max time for a tap to abv ths |
| subinmbed | 2:c4fb968de7d3 | 74 | // char clk_Tlatncy[2] = {0x3C, 0x0}; //time delay to start timr for waiting scnd tap |
| subinmbed | 2:c4fb968de7d3 | 75 | // char clk_Twindow[2] = {0x3D, 0x0}; //max time for timer to wait for scnd |
| subinmbed | 2:c4fb968de7d3 | 76 | |
| subinmbed | 2:c4fb968de7d3 | 77 | //32 33 30 |
| subinmbed | 2:c4fb968de7d3 | 78 | //36 37 34 |
| subinmbed | 2:c4fb968de7d3 | 79 | i2c.write(acc_address, ctrl_reg_0, 2); |
| subinmbed | 2:c4fb968de7d3 | 80 | i2c.write(acc_address, ctrl_reg_1, 2); |
| subinmbed | 2:c4fb968de7d3 | 81 | i2c.write(acc_address, ctrl_reg_2, 2); |
| subinmbed | 2:c4fb968de7d3 | 82 | i2c.write(acc_address, ctrl_reg_3, 2); |
| subinmbed | 2:c4fb968de7d3 | 83 | i2c.write(acc_address, ctrl_reg_4, 2); |
| subinmbed | 2:c4fb968de7d3 | 84 | i2c.write(acc_address, ctrl_reg_5, 2); |
| subinmbed | 2:c4fb968de7d3 | 85 | i2c.write(acc_address, ctrl_reg_6, 2); |
| subinmbed | 2:c4fb968de7d3 | 86 | |
| subinmbed | 2:c4fb968de7d3 | 87 | i2c.write(acc_address, int1_cfg, 2); |
| subinmbed | 2:c4fb968de7d3 | 88 | i2c.write(acc_address, int1_ths, 2); |
| subinmbed | 2:c4fb968de7d3 | 89 | i2c.write(acc_address, int1_dur, 2); |
| subinmbed | 2:c4fb968de7d3 | 90 | |
| subinmbed | 2:c4fb968de7d3 | 91 | i2c.write(acc_address, int2_ths, 2); |
| subinmbed | 2:c4fb968de7d3 | 92 | i2c.write(acc_address, int2_dur, 2); |
| subinmbed | 2:c4fb968de7d3 | 93 | i2c.write(acc_address, int2_cfg, 2); |
| subinmbed | 2:c4fb968de7d3 | 94 | |
| subinmbed | 2:c4fb968de7d3 | 95 | i2c.write(acc_address, act_ths, 2); |
| subinmbed | 2:c4fb968de7d3 | 96 | i2c.write(acc_address, act_dur, 2); |
| subinmbed | 2:c4fb968de7d3 | 97 | i2c.write(acc_address, int1_dur, 2); |
| subinmbed | 2:c4fb968de7d3 | 98 | |
| subinmbed | 2:c4fb968de7d3 | 99 | // i2c.write(acc_address, clk_cfg, 2); |
| subinmbed | 2:c4fb968de7d3 | 100 | // i2c.write(acc_address, clk_src, 2); |
| subinmbed | 2:c4fb968de7d3 | 101 | // i2c.write(acc_address, clk_ths, 2); |
| subinmbed | 2:c4fb968de7d3 | 102 | // i2c.write(acc_address, clk_Tlimit, 2); |
| subinmbed | 2:c4fb968de7d3 | 103 | // i2c.write(acc_address, clk_Tlatncy, 2); |
| subinmbed | 2:c4fb968de7d3 | 104 | // i2c.write(acc_address, clk_Twindow, 2); |
| subinmbed | 2:c4fb968de7d3 | 105 | } |
| subinmbed | 2:c4fb968de7d3 | 106 | ////////////////////////////////////////////////////////////////// |
| subinmbed | 2:c4fb968de7d3 | 107 | char initialize_accelerometer() |
| subinmbed | 2:c4fb968de7d3 | 108 | { |
| subinmbed | 2:c4fb968de7d3 | 109 | i2c.frequency(100000); |
| subinmbed | 2:c4fb968de7d3 | 110 | char dev_id_address[2] = {0x0F}; |
| subinmbed | 2:c4fb968de7d3 | 111 | char dev_id[1]; |
| subinmbed | 2:c4fb968de7d3 | 112 | //SA0 = 0; // I2C LSB Address |
| subinmbed | 2:c4fb968de7d3 | 113 | i2c.write(acc_address, dev_id_address, 1); |
| subinmbed | 2:c4fb968de7d3 | 114 | wait(0.1); |
| subinmbed | 2:c4fb968de7d3 | 115 | i2c.read(acc_address, dev_id, 1); |
| subinmbed | 2:c4fb968de7d3 | 116 | wait(2); |
| subinmbed | 2:c4fb968de7d3 | 117 | pc.printf("\r\n\r\nDEVICE ID : "); |
| subinmbed | 2:c4fb968de7d3 | 118 | print_data_bits(dev_id[0]); |
| subinmbed | 2:c4fb968de7d3 | 119 | if(dev_id[0] == 0x33)//00110011(who am i) |
| subinmbed | 2:c4fb968de7d3 | 120 | { |
| subinmbed | 2:c4fb968de7d3 | 121 | pc.printf("\r\nAccelerometer Initialized Successfully"); |
| subinmbed | 2:c4fb968de7d3 | 122 | return 1; |
| subinmbed | 2:c4fb968de7d3 | 123 | } |
| subinmbed | 2:c4fb968de7d3 | 124 | else |
| subinmbed | 2:c4fb968de7d3 | 125 | { |
| subinmbed | 2:c4fb968de7d3 | 126 | pc.printf("\r\nAccelerometer Initialization Failed..... Can't communicate with the device"); |
| subinmbed | 2:c4fb968de7d3 | 127 | return 0; |
| subinmbed | 2:c4fb968de7d3 | 128 | } |
| subinmbed | 2:c4fb968de7d3 | 129 | } |
| subinmbed | 2:c4fb968de7d3 | 130 | //////////////////////////////////////////////////////////////////////////////// |
| subinmbed | 2:c4fb968de7d3 | 131 | void initialise_configure_accelerometer()//CALLED BY PARENT FUNCTION |
| subinmbed | 2:c4fb968de7d3 | 132 | { |
| subinmbed | 2:c4fb968de7d3 | 133 | char retry_attempt = 0; |
| subinmbed | 2:c4fb968de7d3 | 134 | retry: |
| subinmbed | 2:c4fb968de7d3 | 135 | if(initialize_accelerometer()) |
| subinmbed | 2:c4fb968de7d3 | 136 | { |
| subinmbed | 2:c4fb968de7d3 | 137 | configure_accelerometer(); |
| subinmbed | 2:c4fb968de7d3 | 138 | } |
| subinmbed | 2:c4fb968de7d3 | 139 | else |
| subinmbed | 2:c4fb968de7d3 | 140 | { |
| subinmbed | 2:c4fb968de7d3 | 141 | if(retry_attempt < 100) //it will try 100 times to initialise accelerometer in case prev attempts are failed |
| subinmbed | 2:c4fb968de7d3 | 142 | { |
| subinmbed | 2:c4fb968de7d3 | 143 | retry_attempt++; |
| subinmbed | 2:c4fb968de7d3 | 144 | goto retry; |
| subinmbed | 2:c4fb968de7d3 | 145 | } |
| subinmbed | 2:c4fb968de7d3 | 146 | } |
| subinmbed | 2:c4fb968de7d3 | 147 | |
| subinmbed | 2:c4fb968de7d3 | 148 | } |
| subinmbed | 2:c4fb968de7d3 | 149 | //////////////////////////////////////////////////////////////////// |
| subinmbed | 2:c4fb968de7d3 | 150 | void print_data_bits(char data_fetched) //# now not using |
| subinmbed | 2:c4fb968de7d3 | 151 | { |
| subinmbed | 2:c4fb968de7d3 | 152 | unsigned int shifter; |
| subinmbed | 2:c4fb968de7d3 | 153 | |
| subinmbed | 2:c4fb968de7d3 | 154 | for(shifter = 0; shifter < 8; shifter++) |
| subinmbed | 2:c4fb968de7d3 | 155 | { |
| subinmbed | 2:c4fb968de7d3 | 156 | pc.printf("%d",((data_fetched&0x80)>>7)); |
| subinmbed | 2:c4fb968de7d3 | 157 | data_fetched = data_fetched << 1; |
| subinmbed | 2:c4fb968de7d3 | 158 | } |
| subinmbed | 2:c4fb968de7d3 | 159 | pc.printf("\r\n"); |
| subinmbed | 2:c4fb968de7d3 | 160 | } |
| subinmbed | 2:c4fb968de7d3 | 161 | ///////////////////////////////////////////////////////////////////////////// |
| subinmbed | 2:c4fb968de7d3 | 162 | |
| subinmbed | 2:c4fb968de7d3 | 163 | void process_accelerometer() |
| subinmbed | 2:c4fb968de7d3 | 164 | { |
| subinmbed | 2:c4fb968de7d3 | 165 | // if(MOVEMENT_FLAG) |
| subinmbed | 2:c4fb968de7d3 | 166 | // { |
| subinmbed | 2:c4fb968de7d3 | 167 | // MOVEMENT_FLAG=0; |
| subinmbed | 2:c4fb968de7d3 | 168 | // TIMING=t.read(); |
| subinmbed | 2:c4fb968de7d3 | 169 | // } |
| subinmbed | 2:c4fb968de7d3 | 170 | |
| subinmbed | 2:c4fb968de7d3 | 171 | // if(MOTION) |
| subinmbed | 2:c4fb968de7d3 | 172 | { |
| subinmbed | 2:c4fb968de7d3 | 173 | |
| subinmbed | 2:c4fb968de7d3 | 174 | ///////////////////////////////////////////////////////////if in motion no interrupt comes |
| subinmbed | 2:c4fb968de7d3 | 175 | // if(FIRST) |
| subinmbed | 2:c4fb968de7d3 | 176 | // { |
| subinmbed | 2:c4fb968de7d3 | 177 | // t.reset(); |
| subinmbed | 2:c4fb968de7d3 | 178 | // t.start(); |
| subinmbed | 2:c4fb968de7d3 | 179 | // FIRST=0; |
| subinmbed | 2:c4fb968de7d3 | 180 | // FIRST_TIME=t.read(); |
| subinmbed | 2:c4fb968de7d3 | 181 | // FIRST_SPEED=fetch_vehicle_speed(); |
| subinmbed | 2:c4fb968de7d3 | 182 | // } |
| subinmbed | 2:c4fb968de7d3 | 183 | ///////////////////////////////////////////////////////// |
| subinmbed | 2:c4fb968de7d3 | 184 | { |
| subinmbed | 2:c4fb968de7d3 | 185 | CURRENT_TIME=t.read(); |
| subinmbed | 2:c4fb968de7d3 | 186 | |
| subinmbed | 2:c4fb968de7d3 | 187 | CURRENT_SPEED=fetch_vehicle_speed(); |
| subinmbed | 2:c4fb968de7d3 | 188 | pc.printf("\nspeed=%ld",CURRENT_SPEED); |
| subinmbed | 2:c4fb968de7d3 | 189 | if((CURRENT_SPEED)>1) |
| subinmbed | 2:c4fb968de7d3 | 190 | { |
| subinmbed | 2:c4fb968de7d3 | 191 | pc.printf("START_TO_MOVING...."); |
| subinmbed | 2:c4fb968de7d3 | 192 | ACC_LED=1; |
| subinmbed | 2:c4fb968de7d3 | 193 | MOVING_FLAG=1; |
| subinmbed | 2:c4fb968de7d3 | 194 | START_TO_MOVING=1; |
| subinmbed | 2:c4fb968de7d3 | 195 | MOVING_TO_STOP=0; |
| subinmbed | 2:c4fb968de7d3 | 196 | PRE_MOVING=1; |
| subinmbed | 2:c4fb968de7d3 | 197 | TIMER_RUNNING=1; //# not needed incase of if in motion no interrupt comes,it will enable reading current time in main |
| subinmbed | 2:c4fb968de7d3 | 198 | jerk_disable(); // jerk is disabled by disabling stm32 interrupt |
| subinmbed | 2:c4fb968de7d3 | 199 | } |
| subinmbed | 2:c4fb968de7d3 | 200 | if((CURRENT_SPEED<2)&&(MOVING_FLAG==1))//when speed reach from higher value to 1/0 #can edit according to real speed behavior |
| subinmbed | 2:c4fb968de7d3 | 201 | { |
| subinmbed | 2:c4fb968de7d3 | 202 | pc.printf("MOVING_TO_STOP...."); |
| subinmbed | 2:c4fb968de7d3 | 203 | MOVING_FLAG=0; |
| subinmbed | 2:c4fb968de7d3 | 204 | MOVING_TO_STOP=1; |
| subinmbed | 2:c4fb968de7d3 | 205 | START_TO_MOVING=0; |
| subinmbed | 2:c4fb968de7d3 | 206 | ACC_LED=0; |
| subinmbed | 2:c4fb968de7d3 | 207 | jerk_enable(); // jerk is enabled by enabling stm32 interrupt again |
| subinmbed | 2:c4fb968de7d3 | 208 | TIMER_RUNNING=0; |
| subinmbed | 2:c4fb968de7d3 | 209 | t.stop(); //# not needed incase of if in motion no interrupt comes, it will stop timer when stop detected during time interval |
| subinmbed | 2:c4fb968de7d3 | 210 | } |
| subinmbed | 2:c4fb968de7d3 | 211 | else //speed is one at first itself it will not do anythimg consider as fault jerk,this we can eliminate if we set moving speed>1 and stopping at speed=0 |
| subinmbed | 2:c4fb968de7d3 | 212 | { MOVING_TO_STOP=0; |
| subinmbed | 2:c4fb968de7d3 | 213 | START_TO_MOVING=0; |
| subinmbed | 2:c4fb968de7d3 | 214 | ACC_LED=0; |
| subinmbed | 2:c4fb968de7d3 | 215 | TIMER_RUNNING=0; |
| subinmbed | 2:c4fb968de7d3 | 216 | t.stop(); |
| subinmbed | 2:c4fb968de7d3 | 217 | } |
| subinmbed | 2:c4fb968de7d3 | 218 | } |
| subinmbed | 2:c4fb968de7d3 | 219 | } |
| subinmbed | 2:c4fb968de7d3 | 220 | } |
| subinmbed | 2:c4fb968de7d3 | 221 | ///////////////////////////////////////////////////////////////// |
| subinmbed | 2:c4fb968de7d3 | 222 | void stopped() |
| subinmbed | 2:c4fb968de7d3 | 223 | { |
| subinmbed | 2:c4fb968de7d3 | 224 | START_TO_MOVING=0; |
| subinmbed | 2:c4fb968de7d3 | 225 | MOVING_TO_STOP=1; |
| subinmbed | 2:c4fb968de7d3 | 226 | ACC_LED=0; |
| subinmbed | 2:c4fb968de7d3 | 227 | PRE_MOVING=0; |
| subinmbed | 2:c4fb968de7d3 | 228 | pc.printf("STOPPED"); |
| subinmbed | 2:c4fb968de7d3 | 229 | jerk_enable(); |
| subinmbed | 2:c4fb968de7d3 | 230 | TIMER_RUNNING=0; |
| subinmbed | 2:c4fb968de7d3 | 231 | } |
| subinmbed | 2:c4fb968de7d3 | 232 | //////////////////////////////////////////////////////////////// |
| subinmbed | 2:c4fb968de7d3 | 233 | void jerk_threshold(char jt) //#editing via this function is not working,inorder to edit threshold we have to change in configuration function |
| subinmbed | 2:c4fb968de7d3 | 234 | { |
| subinmbed | 2:c4fb968de7d3 | 235 | |
| subinmbed | 2:c4fb968de7d3 | 236 | char int2_cfg[2] = {0x34, 0xFF}; //INT2 is disabled for XYZ HIE/LIE |
| subinmbed | 2:c4fb968de7d3 | 237 | char int2_ths[2] = {0x36, 0x09}; //changed from 2 more threshold |
| subinmbed | 2:c4fb968de7d3 | 238 | char int2_dur[2] = {0x37, 0x02}; |
| subinmbed | 2:c4fb968de7d3 | 239 | i2c.write(acc_address, int2_ths, 2); |
| subinmbed | 2:c4fb968de7d3 | 240 | i2c.write(acc_address, int2_dur, 2); |
| subinmbed | 2:c4fb968de7d3 | 241 | i2c.write(acc_address, int2_cfg, 2); |
| subinmbed | 2:c4fb968de7d3 | 242 | |
| subinmbed | 2:c4fb968de7d3 | 243 | } |
| subinmbed | 2:c4fb968de7d3 | 244 | void jerk_duration(char jd)//#editing via this function is not working,inorder to edit threshold we have to change in configuration function |
| subinmbed | 2:c4fb968de7d3 | 245 | { |
| subinmbed | 2:c4fb968de7d3 | 246 | char int2_dur[1] = {jd}; |
| subinmbed | 2:c4fb968de7d3 | 247 | i2c.write(acc_address, int2_dur, 2); |
| subinmbed | 2:c4fb968de7d3 | 248 | } |
| subinmbed | 2:c4fb968de7d3 | 249 | void movement_threshold(char mt)//#editing via this function is not working,inorder to edit threshold we have to change in configuration function |
| subinmbed | 2:c4fb968de7d3 | 250 | { |
| subinmbed | 2:c4fb968de7d3 | 251 | char int1_ths[1] = {mt}; |
| subinmbed | 2:c4fb968de7d3 | 252 | i2c.write(acc_address, int1_ths, 2); |
| subinmbed | 2:c4fb968de7d3 | 253 | } |
| subinmbed | 2:c4fb968de7d3 | 254 | void movement_duration(char md)//#editing via this function is not working,inorder to edit threshold we have to change in configuration function |
| subinmbed | 2:c4fb968de7d3 | 255 | { |
| subinmbed | 2:c4fb968de7d3 | 256 | char int1_dur[1] = {md}; |
| subinmbed | 2:c4fb968de7d3 | 257 | i2c.write(acc_address, int1_dur,2); |
| subinmbed | 2:c4fb968de7d3 | 258 | } |
| subinmbed | 2:c4fb968de7d3 | 259 | void jerk_enable() //enable stm32 interrupt |
| subinmbed | 2:c4fb968de7d3 | 260 | { |
| subinmbed | 2:c4fb968de7d3 | 261 | jerk.rise(&sudden_jerk); |
| subinmbed | 2:c4fb968de7d3 | 262 | |
| subinmbed | 2:c4fb968de7d3 | 263 | } |
| subinmbed | 2:c4fb968de7d3 | 264 | void jerk_disable() //enable stm32 interrupt |
| subinmbed | 2:c4fb968de7d3 | 265 | { |
| subinmbed | 2:c4fb968de7d3 | 266 | jerk.rise(NULL); |
| subinmbed | 2:c4fb968de7d3 | 267 | JERK_FLAG=0; |
| subinmbed | 2:c4fb968de7d3 | 268 | } |
| subinmbed | 2:c4fb968de7d3 | 269 | void movement_enable() //enable stm32 interrupt |
| subinmbed | 2:c4fb968de7d3 | 270 | { |
| subinmbed | 2:c4fb968de7d3 | 271 | change.rise(&movement_inertia); |
| subinmbed | 2:c4fb968de7d3 | 272 | } |
| subinmbed | 2:c4fb968de7d3 | 273 | void movement_disable() //enable stm32 interrupt |
| subinmbed | 2:c4fb968de7d3 | 274 | { |
| subinmbed | 2:c4fb968de7d3 | 275 | change.rise(NULL); |
| subinmbed | 2:c4fb968de7d3 | 276 | } |