Added EPS faults

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of QM_BAE_review_1 by Team Fox

Committer:
azaddevarm
Date:
Mon Jun 13 10:37:50 2016 +0000
Revision:
16:5f0f2a3f3e8d
Parent:
15:e09aaaccf134
Added EPS faults

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sakthipriya 0:7b4c00e3912f 1 #include "EPS.h"
sakthipriya 0:7b4c00e3912f 2 #include "pin_config.h"
sakthipriya 6:036d08b62785 3 #include "iostream"
sakthipriya 0:7b4c00e3912f 4 /***********************************************global variable declaration***************************************************************/
sakthipriya 0:7b4c00e3912f 5 extern uint32_t BAE_STATUS;
sakthipriya 0:7b4c00e3912f 6 extern uint32_t BAE_ENABLE;
sakthipriya 6:036d08b62785 7 extern uint8_t BAE_data[74];
sakthipriya 6:036d08b62785 8 extern char BAE_chardata[74];
sakthipriya 0:7b4c00e3912f 9
sakthipriya 0:7b4c00e3912f 10 //m_I2C.frequency(10000)
lakshya 15:e09aaaccf134 11 const char RCOMP0= 0x97;// don't know what it is now
sakthipriya 0:7b4c00e3912f 12 BAE_HK_actual actual_data;
sakthipriya 0:7b4c00e3912f 13 BAE_HK_quant quant_data;
sakthipriya 0:7b4c00e3912f 14 BAE_HK_min_max bae_HK_minmax;
sakthipriya 0:7b4c00e3912f 15 BAE_HK_arch arch_data;
sakthipriya 0:7b4c00e3912f 16
sakthipriya 5:bb592f3185cc 17
sakthipriya 0:7b4c00e3912f 18 //......................................Peripheral declarations.........................................................//
sakthipriya 0:7b4c00e3912f 19 Serial pc_eps(USBTX,USBRX);
sakthipriya 3:07e15677a75c 20
sakthipriya 0:7b4c00e3912f 21 I2C m_I2C(PIN85,PIN84);
sakthipriya 0:7b4c00e3912f 22 DigitalOut TRXY(TRXY_DR_EN); //active high
sakthipriya 0:7b4c00e3912f 23 DigitalOut TRZ(TRZ_DR_EN); //active high
sakthipriya 0:7b4c00e3912f 24 DigitalOut EN3V3A(ENBL3V3A);
sakthipriya 0:7b4c00e3912f 25 DigitalOut EN_BTRY_HT(BATT_HEAT);
sakthipriya 0:7b4c00e3912f 26 //DigitalIn BTRY_HT_OUTPUT(BATT_HEAT_OUTPUT);
sakthipriya 3:07e15677a75c 27 //AnalogIn Vbatt_ang(VBATT);
sakthipriya 3:07e15677a75c 28 AnalogIn Batt_voltage(PIN20); //Battery voltage
sakthipriya 3:07e15677a75c 29
lakshya 15:e09aaaccf134 30 SPI spi_bt(PIN99,PIN100,PIN98); //MOSI,MISO,SLK // battery temp something 3
lakshya 15:e09aaaccf134 31 DigitalOut ssn1(PIN19); //Slave select1 // low line master talks
sakthipriya 2:c823d84b4cb0 32 DigitalOut ssn2(PIN21);//Slave select2
sakthipriya 2:c823d84b4cb0 33 //DigitalOut PS(PTB0);
sakthipriya 2:c823d84b4cb0 34 //DigitalOut HS(PTB1);
sakthipriya 2:c823d84b4cb0 35
sakthipriya 3:07e15677a75c 36 AnalogIn CurrentInput(PIN54); // Input from Current Multiplexer //PIN54
sakthipriya 3:07e15677a75c 37 AnalogIn VoltageInput(PIN53); // Input from Voltage Multiplexer //PIN53
sakthipriya 3:07e15677a75c 38 AnalogIn BAE_temp_sensor(PIN55); //Input from BAE temp sensor
sakthipriya 3:07e15677a75c 39
lakshya 15:e09aaaccf134 40 /*mux for reading value one by one*/
sakthipriya 3:07e15677a75c 41 DigitalOut SelectLinea3 (PIN46); // MSB of Select Lines
sakthipriya 3:07e15677a75c 42 DigitalOut SelectLinea2 (PIN45);
sakthipriya 3:07e15677a75c 43 DigitalOut SelectLinea1 (PIN44);
sakthipriya 3:07e15677a75c 44 DigitalOut SelectLinea0 (PIN43); // LSB of Select Lines
sakthipriya 3:07e15677a75c 45
sakthipriya 3:07e15677a75c 46 DigitalOut SelectLineb3 (PIN56); // MSB of Select Lines
sakthipriya 3:07e15677a75c 47 DigitalOut SelectLineb2 (PIN57);
sakthipriya 3:07e15677a75c 48 DigitalOut SelectLineb1 (PIN58);
sakthipriya 3:07e15677a75c 49 DigitalOut SelectLineb0 (PIN59); // LSB of Select Lines
sakthipriya 0:7b4c00e3912f 50
sakthipriya 0:7b4c00e3912f 51 //*********************************************************flags********************************************************//
sakthipriya 0:7b4c00e3912f 52 extern char EPS_INIT_STATUS ;
sakthipriya 0:7b4c00e3912f 53 extern char EPS_BATTERY_GAUGE_STATUS ;
sakthipriya 0:7b4c00e3912f 54 extern char EPS_MAIN_STATUS;
sakthipriya 0:7b4c00e3912f 55 extern char EPS_BATTERY_TEMP_STATUS ;
sakthipriya 0:7b4c00e3912f 56 extern char EPS_STATUS ;
sakthipriya 0:7b4c00e3912f 57
sakthipriya 0:7b4c00e3912f 58 extern char EPS_BATTERY_HEAT_ENABLE ;
sakthipriya 0:7b4c00e3912f 59
azaddevarm 16:5f0f2a3f3e8d 60 //eps cdms fault
azaddevarm 16:5f0f2a3f3e8d 61 extern uint8_t CDMS_SW_STATUS;
azaddevarm 16:5f0f2a3f3e8d 62 extern bool CDMS_OC_FAULT;
azaddevarm 16:5f0f2a3f3e8d 63 extern bool CDMS_SW_ENABLE;
azaddevarm 16:5f0f2a3f3e8d 64 extern int CDMS_FAULT_COUNTER;
azaddevarm 16:5f0f2a3f3e8d 65
azaddevarm 16:5f0f2a3f3e8d 66 //eps hw faults
azaddevarm 16:5f0f2a3f3e8d 67
azaddevarm 16:5f0f2a3f3e8d 68 extern uint8_t ACS_TR_Z_SW_STATUS;
azaddevarm 16:5f0f2a3f3e8d 69 extern bool ACS_TR_Z_ENABLE;
azaddevarm 16:5f0f2a3f3e8d 70 extern bool ACS_TR_Z_OC_FAULT;
azaddevarm 16:5f0f2a3f3e8d 71 extern bool ACS_TR_Z_FAULT; //Driver IC fault
azaddevarm 16:5f0f2a3f3e8d 72 extern int ACS_TR_Z_FAULT_COUNTER;
azaddevarm 16:5f0f2a3f3e8d 73
azaddevarm 16:5f0f2a3f3e8d 74 extern uint8_t ACS_TR_XY_SW_STATUS;
azaddevarm 16:5f0f2a3f3e8d 75 extern bool ACS_TR_XY_ENABLE;
azaddevarm 16:5f0f2a3f3e8d 76 extern bool ACS_TR_XY_OC_FAULT;
azaddevarm 16:5f0f2a3f3e8d 77 extern bool ACS_TR_XY_FAULT; //Driver IC fault
azaddevarm 16:5f0f2a3f3e8d 78 extern int ACS_TR_XY_FAULT_COUNTER;
azaddevarm 16:5f0f2a3f3e8d 79
azaddevarm 16:5f0f2a3f3e8d 80 extern uint8_t ACS_ATS1_SW_STATUS;
azaddevarm 16:5f0f2a3f3e8d 81 extern bool ACS_ATS1_ENABLE;
azaddevarm 16:5f0f2a3f3e8d 82 extern bool ACS_ATS1_OC_FAULT;
azaddevarm 16:5f0f2a3f3e8d 83 extern int ACS_ATS1_FAULT_COUNTER;
azaddevarm 16:5f0f2a3f3e8d 84
azaddevarm 16:5f0f2a3f3e8d 85 extern uint8_t ACS_ATS2_SW_STATUS;
azaddevarm 16:5f0f2a3f3e8d 86 extern bool ACS_ATS2_ENABLE;
azaddevarm 16:5f0f2a3f3e8d 87 extern bool ACS_ATS2_OC_FAULT;
azaddevarm 16:5f0f2a3f3e8d 88 extern int ACS_ATS2_FAULT_COUNTER;
azaddevarm 16:5f0f2a3f3e8d 89
azaddevarm 16:5f0f2a3f3e8d 90 extern uint8_t BCN_TX_SW_STATUS;
azaddevarm 16:5f0f2a3f3e8d 91 extern bool BCN_TX_ENABLE;
azaddevarm 16:5f0f2a3f3e8d 92 extern bool BCN_TX_OC_FAULT;
azaddevarm 16:5f0f2a3f3e8d 93 extern int BCN_TX_FAULT_COUNTER;
azaddevarm 16:5f0f2a3f3e8d 94
azaddevarm 16:5f0f2a3f3e8d 95
sakthipriya 0:7b4c00e3912f 96 //........................................... FUCTIONS.................................................//
sakthipriya 0:7b4c00e3912f 97
sakthipriya 0:7b4c00e3912f 98 void FCTN_EPS_INIT()
sakthipriya 0:7b4c00e3912f 99 {
sakthipriya 0:7b4c00e3912f 100 printf("\n\r eps init \n");
sakthipriya 0:7b4c00e3912f 101 EPS_INIT_STATUS = 's' ; //set EPS_INIT_STATUS flag
sakthipriya 3:07e15677a75c 102 // FLAG();
sakthipriya 0:7b4c00e3912f 103 FCTN_BATTERYGAUGE_INIT();
sakthipriya 3:07e15677a75c 104 FCTN_BATTTEMP_INIT();
sakthipriya 0:7b4c00e3912f 105 EN3V3A = 1; //enable dc dc converter A
lakshya 15:e09aaaccf134 106 char value=alertFlags(); // initialization part of battery gauge
sakthipriya 0:7b4c00e3912f 107 unsigned short value_u= (short int )value;
sakthipriya 0:7b4c00e3912f 108 value_u &=0x0001;
sakthipriya 0:7b4c00e3912f 109 if(value_u ==0x0001) // battery gauge not initialised
sakthipriya 0:7b4c00e3912f 110 {
sakthipriya 0:7b4c00e3912f 111 actual_data.power_mode = 1;
sakthipriya 0:7b4c00e3912f 112 EPS_BATTERY_GAUGE_STATUS = 'c'; //clear EPS_BATTERY_GAUGE_STATUS
sakthipriya 0:7b4c00e3912f 113 }
sakthipriya 0:7b4c00e3912f 114 else
sakthipriya 0:7b4c00e3912f 115 {
sakthipriya 0:7b4c00e3912f 116 actual_data.Batt_gauge_actual[1] = soc();
lakshya 15:e09aaaccf134 117 actual_data.Batt_voltage_actual = Batt_voltage.read()*3.3; //1 corresponds to 3.3 scaling factor
sakthipriya 0:7b4c00e3912f 118 FCTN_EPS_POWERMODE(actual_data.Batt_gauge_actual[1]);
sakthipriya 0:7b4c00e3912f 119 EPS_BATTERY_GAUGE_STATUS = 's'; //set EPS_BATTERY_GAUGE_STATUS
sakthipriya 0:7b4c00e3912f 120 }
sakthipriya 0:7b4c00e3912f 121
sakthipriya 0:7b4c00e3912f 122 EPS_INIT_STATUS = 'c' ; //clear EPS_INIT_STATUS flag
sakthipriya 0:7b4c00e3912f 123
sakthipriya 0:7b4c00e3912f 124 }
sakthipriya 0:7b4c00e3912f 125
azaddevarm 16:5f0f2a3f3e8d 126 void FCTN_EPS_HANDLE_CDMS_FAULT()
azaddevarm 16:5f0f2a3f3e8d 127 { //Variable names from MMS structure, if not, marked as //Temp name
azaddevarm 16:5f0f2a3f3e8d 128 if(CDMS_SW_STATUS == 0b11) //powered on and oc fault
azaddevarm 16:5f0f2a3f3e8d 129 if(!CDMS_OC_FAULT)
azaddevarm 16:5f0f2a3f3e8d 130 CDMS_SW_STATUS = 0b01; //powered on and working
azaddevarm 16:5f0f2a3f3e8d 131 else
azaddevarm 16:5f0f2a3f3e8d 132 {
azaddevarm 16:5f0f2a3f3e8d 133 if(CDMS_SW_STATUS == 0b10) //powered off and oc fault
azaddevarm 16:5f0f2a3f3e8d 134 CDMS_SW_ENABLE = 1; //Temp name
azaddevarm 16:5f0f2a3f3e8d 135 if(CDMS_OC_FAULT == 0)
azaddevarm 16:5f0f2a3f3e8d 136 {
azaddevarm 16:5f0f2a3f3e8d 137 CDMS_FAULT_COUNTER = 0; //Temp name
azaddevarm 16:5f0f2a3f3e8d 138 CDMS_SW_STATUS = 0b01; //powered on and working
azaddevarm 16:5f0f2a3f3e8d 139 }
azaddevarm 16:5f0f2a3f3e8d 140 else
azaddevarm 16:5f0f2a3f3e8d 141 {
azaddevarm 16:5f0f2a3f3e8d 142 CDMS_FAULT_COUNTER++;
azaddevarm 16:5f0f2a3f3e8d 143 if(CDMS_FAULT_COUNTER == 3)
azaddevarm 16:5f0f2a3f3e8d 144 CDMS_SW_STATUS = 0b11; //powered on and oc fault
azaddevarm 16:5f0f2a3f3e8d 145 else
azaddevarm 16:5f0f2a3f3e8d 146 {
azaddevarm 16:5f0f2a3f3e8d 147 CDMS_SW_ENABLE = 0; //power OFF switch
azaddevarm 16:5f0f2a3f3e8d 148 CDMS_SW_STATUS = 0b10; //powered off and oc fault
azaddevarm 16:5f0f2a3f3e8d 149 }
azaddevarm 16:5f0f2a3f3e8d 150 }
azaddevarm 16:5f0f2a3f3e8d 151 }
azaddevarm 16:5f0f2a3f3e8d 152 }
azaddevarm 16:5f0f2a3f3e8d 153
azaddevarm 16:5f0f2a3f3e8d 154 void FCTN_EPS_HANDLE_HW_FAULTS()
azaddevarm 16:5f0f2a3f3e8d 155 { //Variable names from MMS structure, if not, marked as //Temp name
azaddevarm 16:5f0f2a3f3e8d 156
azaddevarm 16:5f0f2a3f3e8d 157 //--------ACS_TR_Z--------//
azaddevarm 16:5f0f2a3f3e8d 158 if(ACS_TR_Z_SW_STATUS != 0b11) //!disabled
azaddevarm 16:5f0f2a3f3e8d 159 {
azaddevarm 16:5f0f2a3f3e8d 160 if(ACS_TR_Z_SW_STATUS == 0b10) //oc fault and powered off
azaddevarm 16:5f0f2a3f3e8d 161 ACS_TR_Z_ENABLE = 1;
azaddevarm 16:5f0f2a3f3e8d 162 if(ACS_TR_Z_OC_FAULT || ACS_TR_Z_FAULT)
azaddevarm 16:5f0f2a3f3e8d 163 {
azaddevarm 16:5f0f2a3f3e8d 164 ACS_TR_Z_ENABLE = 0;
azaddevarm 16:5f0f2a3f3e8d 165 ACS_TR_Z_FAULT_COUNTER++; //Temp name
azaddevarm 16:5f0f2a3f3e8d 166 if(ACS_TR_Z_FAULT_COUNTER == 3)
azaddevarm 16:5f0f2a3f3e8d 167 ACS_TR_Z_SW_STATUS = 0b11; //disabled
azaddevarm 16:5f0f2a3f3e8d 168 //update in flash as default state at bootup
azaddevarm 16:5f0f2a3f3e8d 169 else ACS_TR_Z_SW_STATUS = 0b10; //oc fault and powered off
azaddevarm 16:5f0f2a3f3e8d 170 }
azaddevarm 16:5f0f2a3f3e8d 171 else
azaddevarm 16:5f0f2a3f3e8d 172 {
azaddevarm 16:5f0f2a3f3e8d 173 ACS_TR_Z_SW_STATUS = 0b01; //powered on and working;
azaddevarm 16:5f0f2a3f3e8d 174 //update in flash also
azaddevarm 16:5f0f2a3f3e8d 175 ACS_TR_Z_FAULT_COUNTER = 0;
azaddevarm 16:5f0f2a3f3e8d 176 }
azaddevarm 16:5f0f2a3f3e8d 177 }
azaddevarm 16:5f0f2a3f3e8d 178
azaddevarm 16:5f0f2a3f3e8d 179 //--------ACS_TR_XY--------//
azaddevarm 16:5f0f2a3f3e8d 180 //Same as ACS_TR_Z, just replace Z with XY
azaddevarm 16:5f0f2a3f3e8d 181
azaddevarm 16:5f0f2a3f3e8d 182 //--------ACS_ATS1--------//
azaddevarm 16:5f0f2a3f3e8d 183 //Same as ACS_ATS2
azaddevarm 16:5f0f2a3f3e8d 184
azaddevarm 16:5f0f2a3f3e8d 185 //--------ACS_ATS2--------//
azaddevarm 16:5f0f2a3f3e8d 186 if(ACS_ATS2_SW_STATUS & 0b1100 != 0b1100) //!disabled
azaddevarm 16:5f0f2a3f3e8d 187 {
azaddevarm 16:5f0f2a3f3e8d 188 if(ACS_ATS2_SW_STATUS & 0b1100 == 0b1000) //oc fault and powered off
azaddevarm 16:5f0f2a3f3e8d 189 ACS_ATS2_ENABLE = 1; //Temp name
azaddevarm 16:5f0f2a3f3e8d 190 if(ACS_ATS2_OC_FAULT)
azaddevarm 16:5f0f2a3f3e8d 191 {
azaddevarm 16:5f0f2a3f3e8d 192 ACS_ATS2_ENABLE = 0;
azaddevarm 16:5f0f2a3f3e8d 193 ACS_ATS2_FAULT_COUNTER++; //Temp name
azaddevarm 16:5f0f2a3f3e8d 194 if(ACS_ATS2_FAULT_COUNTER == 3)
azaddevarm 16:5f0f2a3f3e8d 195 ACS_ATS2_SW_STATUS = ACS_ATS2_SW_STATUS | 0b1100; //disabled
azaddevarm 16:5f0f2a3f3e8d 196 //update in flash as default state at bootup
azaddevarm 16:5f0f2a3f3e8d 197 else
azaddevarm 16:5f0f2a3f3e8d 198 {
azaddevarm 16:5f0f2a3f3e8d 199 ACS_ATS2_SW_STATUS = ACS_ATS2_SW_STATUS | 0b1000; //setting to 10xx
azaddevarm 16:5f0f2a3f3e8d 200 ACS_ATS2_SW_STATUS = ACS_ATS2_SW_STATUS & 0b1011; //oc fault and powered off
azaddevarm 16:5f0f2a3f3e8d 201 }
azaddevarm 16:5f0f2a3f3e8d 202 }
azaddevarm 16:5f0f2a3f3e8d 203 else
azaddevarm 16:5f0f2a3f3e8d 204 {
azaddevarm 16:5f0f2a3f3e8d 205 if(ACS_ATS2_SW_STATUS & 0b1100 == 0b1000) //Device oc fault?
azaddevarm 16:5f0f2a3f3e8d 206 ACS_ATS2_ENABLE = 0;
azaddevarm 16:5f0f2a3f3e8d 207 ACS_ATS2_SW_STATUS = ACS_ATS2_SW_STATUS & 0b0011; //working but powered off
azaddevarm 16:5f0f2a3f3e8d 208 //Update in flash also
azaddevarm 16:5f0f2a3f3e8d 209 ACS_ATS2_FAULT_COUNTER = 0;
azaddevarm 16:5f0f2a3f3e8d 210 }
azaddevarm 16:5f0f2a3f3e8d 211 }
azaddevarm 16:5f0f2a3f3e8d 212
azaddevarm 16:5f0f2a3f3e8d 213 //--------BCN_TX----------//
azaddevarm 16:5f0f2a3f3e8d 214 if(BCN_TX_SW_STATUS != 0b11) //!disabled
azaddevarm 16:5f0f2a3f3e8d 215 {
azaddevarm 16:5f0f2a3f3e8d 216 if(BCN_TX_SW_STATUS == 0b10) //oc fault and powered off
azaddevarm 16:5f0f2a3f3e8d 217 BCN_TX_ENABLE = 1; //Temp name
azaddevarm 16:5f0f2a3f3e8d 218 if(BCN_TX_OC_FAULT)
azaddevarm 16:5f0f2a3f3e8d 219 {
azaddevarm 16:5f0f2a3f3e8d 220 BCN_TX_ENABLE = 0;
azaddevarm 16:5f0f2a3f3e8d 221 BCN_TX_FAULT_COUNTER++; //Temp name
azaddevarm 16:5f0f2a3f3e8d 222 if(BCN_TX_FAULT_COUNTER == 3)
azaddevarm 16:5f0f2a3f3e8d 223 BCN_TX_SW_STATUS = 0b11; //disabled
azaddevarm 16:5f0f2a3f3e8d 224 //update in flash as default state at bootup
azaddevarm 16:5f0f2a3f3e8d 225 else BCN_TX_SW_STATUS = 0b10; //oc fault and powered off
azaddevarm 16:5f0f2a3f3e8d 226 }
azaddevarm 16:5f0f2a3f3e8d 227 else
azaddevarm 16:5f0f2a3f3e8d 228 {
azaddevarm 16:5f0f2a3f3e8d 229 BCN_TX_SW_STATUS = 0b01; //powered on and working;
azaddevarm 16:5f0f2a3f3e8d 230 //update in flash also
azaddevarm 16:5f0f2a3f3e8d 231 BCN_TX_FAULT_COUNTER = 0;
azaddevarm 16:5f0f2a3f3e8d 232 }
azaddevarm 16:5f0f2a3f3e8d 233 }
azaddevarm 16:5f0f2a3f3e8d 234
azaddevarm 16:5f0f2a3f3e8d 235 }
azaddevarm 16:5f0f2a3f3e8d 236
sakthipriya 0:7b4c00e3912f 237 //----------------------------------------------------Power algo code--------------------------------------------------------------------//
lakshya 15:e09aaaccf134 238 /*update the power modes*/
lakshya 15:e09aaaccf134 239
sakthipriya 0:7b4c00e3912f 240 void FCTN_EPS_POWERMODE(float soc) //dummy algo
sakthipriya 0:7b4c00e3912f 241 {
sakthipriya 0:7b4c00e3912f 242 if(soc >= 80)
sakthipriya 0:7b4c00e3912f 243 actual_data.power_mode = 4;
sakthipriya 0:7b4c00e3912f 244 else if(soc >= 70 & soc < 80)
sakthipriya 0:7b4c00e3912f 245 actual_data.power_mode = 3;
sakthipriya 0:7b4c00e3912f 246 else if(soc >= 60 & soc < 70)
sakthipriya 0:7b4c00e3912f 247 actual_data.power_mode = 2;
sakthipriya 0:7b4c00e3912f 248 else if(soc < 60)
sakthipriya 0:7b4c00e3912f 249 actual_data.power_mode = 1;
sakthipriya 0:7b4c00e3912f 250 }
sakthipriya 0:7b4c00e3912f 251
sakthipriya 0:7b4c00e3912f 252 //...................................................HK...........................................//
lakshya 15:e09aaaccf134 253 /*reading values*/
sakthipriya 3:07e15677a75c 254
sakthipriya 3:07e15677a75c 255 void FCTN_HK_MAIN()
sakthipriya 3:07e15677a75c 256 {
sakthipriya 3:07e15677a75c 257 int Iteration=0;
sakthipriya 3:07e15677a75c 258
sakthipriya 3:07e15677a75c 259 SelectLinea0=0;
sakthipriya 3:07e15677a75c 260 SelectLinea1=0;
sakthipriya 3:07e15677a75c 261 SelectLinea2=0;
sakthipriya 3:07e15677a75c 262 SelectLinea3=0;
sakthipriya 3:07e15677a75c 263
sakthipriya 3:07e15677a75c 264 SelectLineb0=0;
sakthipriya 3:07e15677a75c 265 SelectLineb1=0;
sakthipriya 3:07e15677a75c 266 SelectLineb2=0;
sakthipriya 3:07e15677a75c 267 SelectLineb3=0;
sakthipriya 3:07e15677a75c 268
sakthipriya 3:07e15677a75c 269 //collecting data
sakthipriya 3:07e15677a75c 270 for(Iteration=0; Iteration<16; Iteration++){
sakthipriya 3:07e15677a75c 271
sakthipriya 3:07e15677a75c 272 actual_data.voltage_actual[Iteration]=VoltageInput.read();
sakthipriya 3:07e15677a75c 273 actual_data.current_actual[Iteration]=CurrentInput.read();
sakthipriya 3:07e15677a75c 274
sakthipriya 3:07e15677a75c 275 SelectLinea0=!(SelectLinea0);
sakthipriya 3:07e15677a75c 276 if(Iteration%2==1)
sakthipriya 3:07e15677a75c 277 SelectLinea1=!(SelectLinea1);
sakthipriya 3:07e15677a75c 278 if(Iteration%4==3)
sakthipriya 3:07e15677a75c 279 SelectLinea2=!(SelectLinea2);
sakthipriya 3:07e15677a75c 280 if(Iteration%8==7)
sakthipriya 3:07e15677a75c 281 SelectLinea3=!(SelectLinea3);
sakthipriya 3:07e15677a75c 282 int s0,s1,s2,s3;
sakthipriya 3:07e15677a75c 283 s0=SelectLineb0=SelectLinea0;
sakthipriya 3:07e15677a75c 284 s1=SelectLineb1=SelectLinea2;
sakthipriya 3:07e15677a75c 285 s2=SelectLineb2=SelectLinea2;
sakthipriya 3:07e15677a75c 286 s3=SelectLineb3=SelectLinea3;
sakthipriya 3:07e15677a75c 287 printf("\n\r %d %d %d %d", s0,s1,s2,s3);
sakthipriya 3:07e15677a75c 288
sakthipriya 3:07e15677a75c 289 }
sakthipriya 3:07e15677a75c 290 for(Iteration=0; Iteration<16; Iteration++){
sakthipriya 3:07e15677a75c 291
sakthipriya 3:07e15677a75c 292 if(Iteration==14)
sakthipriya 3:07e15677a75c 293 actual_data.voltage_actual[Iteration]= (-90.7*3.3*actual_data.voltage_actual[Iteration])+190.1543;
sakthipriya 3:07e15677a75c 294 else
sakthipriya 3:07e15677a75c 295 actual_data.voltage_actual[Iteration]= actual_data.voltage_actual[Iteration]*3.3*5.63;
sakthipriya 3:07e15677a75c 296 }
sakthipriya 3:07e15677a75c 297
sakthipriya 3:07e15677a75c 298 for(Iteration=0;Iteration<12;Iteration++){
sakthipriya 3:07e15677a75c 299 if(Iteration<8)
sakthipriya 3:07e15677a75c 300 actual_data.current_actual[Iteration]= actual_data.current_actual[Iteration]*3.3/(50*rsens);
sakthipriya 3:07e15677a75c 301 else
sakthipriya 3:07e15677a75c 302 actual_data.current_actual[Iteration]=actual_data.current_actual[Iteration]*3.3;
sakthipriya 3:07e15677a75c 303 int resistance;
sakthipriya 3:07e15677a75c 304
sakthipriya 3:07e15677a75c 305 resistance=24000*actual_data.current_actual[Iteration]/(3.3-actual_data.current_actual[Iteration]);
sakthipriya 3:07e15677a75c 306 if(actual_data.current_actual[Iteration]>1.47)
sakthipriya 3:07e15677a75c 307 {
sakthipriya 3:07e15677a75c 308 actual_data.current_actual[Iteration]=3694/log(24.032242*resistance);
sakthipriya 3:07e15677a75c 309 }
sakthipriya 3:07e15677a75c 310 else{
sakthipriya 3:07e15677a75c 311
sakthipriya 3:07e15677a75c 312 actual_data.current_actual[Iteration]=3365.4/log(7.60573*resistance);
sakthipriya 3:07e15677a75c 313 }
sakthipriya 3:07e15677a75c 314 }
sakthipriya 3:07e15677a75c 315 actual_data.BAE_temp_actual=(-90.7*3.3*actual_data.BAE_temp_actual)+190.1543;
sakthipriya 3:07e15677a75c 316
sakthipriya 3:07e15677a75c 317 actual_data.Batt_voltage_actual=Batt_voltage.read()*3.3*5.63;
sakthipriya 3:07e15677a75c 318
sakthipriya 3:07e15677a75c 319 //quantizing data
sakthipriya 3:07e15677a75c 320 for(Iteration=0; Iteration<16; Iteration++){
sakthipriya 3:07e15677a75c 321
sakthipriya 3:07e15677a75c 322 if(Iteration==14)
sakthipriya 3:07e15677a75c 323 quant_data.voltage_quant[Iteration]=quantiz(tstart,tstep,actual_data.voltage_actual[Iteration]);
sakthipriya 3:07e15677a75c 324 else
sakthipriya 3:07e15677a75c 325 quant_data.voltage_quant[Iteration]=quantiz(vstart,vstep,actual_data.voltage_actual[Iteration]);
sakthipriya 3:07e15677a75c 326
sakthipriya 3:07e15677a75c 327 }
sakthipriya 3:07e15677a75c 328 for(Iteration=0;Iteration<12;Iteration++){
sakthipriya 3:07e15677a75c 329 if(Iteration<8)
sakthipriya 3:07e15677a75c 330 quant_data.current_quant[Iteration]=quantiz(cstart,cstep,actual_data.current_actual[Iteration]);
sakthipriya 3:07e15677a75c 331 else
sakthipriya 3:07e15677a75c 332 quant_data.current_quant[Iteration]=quantiz(tstart_thermistor,tstep_thermistor,actual_data.current_actual[Iteration]);
sakthipriya 3:07e15677a75c 333 }
sakthipriya 3:07e15677a75c 334 for(Iteration=0;Iteration<2;Iteration++){
sakthipriya 3:07e15677a75c 335
sakthipriya 3:07e15677a75c 336 quant_data.Batt_temp_quant[Iteration]=quantiz(tstart,tstep,actual_data.Batt_temp_actual[Iteration]);
sakthipriya 3:07e15677a75c 337 }
sakthipriya 3:07e15677a75c 338
sakthipriya 3:07e15677a75c 339 quant_data.Batt_gauge_quant[0]=quantiz(vcell_start,vcell_step,actual_data.Batt_gauge_actual[0]);
sakthipriya 3:07e15677a75c 340 quant_data.Batt_gauge_quant[1]=quantiz(soc_start,soc_step,actual_data.Batt_gauge_actual[1]);
sakthipriya 3:07e15677a75c 341 quant_data.Batt_gauge_quant[2]=quantiz(crate_start,crate_step,actual_data.Batt_gauge_actual[2]);
sakthipriya 3:07e15677a75c 342 quant_data.Batt_gauge_alerts=actual_data.Batt_gauge_actual[3];
sakthipriya 3:07e15677a75c 343
sakthipriya 3:07e15677a75c 344 quant_data.BAE_temp_quant=quantiz(tstart,tstep,actual_data.BAE_temp_actual);
sakthipriya 3:07e15677a75c 345
sakthipriya 3:07e15677a75c 346 for(Iteration=0;Iteration<3;Iteration++){
sakthipriya 5:bb592f3185cc 347 quant_data.AngularSpeed_quant[Iteration]=actual_data.AngularSpeed_actual[Iteration];
sakthipriya 6:036d08b62785 348 printf("\n\r w value %f",quant_data.AngularSpeed_quant[Iteration]);
sakthipriya 3:07e15677a75c 349 }
sakthipriya 3:07e15677a75c 350
sakthipriya 3:07e15677a75c 351 for(Iteration=0;Iteration<3;Iteration++){
sakthipriya 3:07e15677a75c 352 quant_data.Bvalue_quant[Iteration]=actual_data.Bvalue_actual[Iteration];
sakthipriya 6:036d08b62785 353 printf("\n\r b value %f",quant_data.Bvalue_quant[Iteration]);
sakthipriya 3:07e15677a75c 354 }
sakthipriya 3:07e15677a75c 355
sakthipriya 3:07e15677a75c 356 quant_data.Batt_voltage_quant=quantiz(vstart,vstep,actual_data.Batt_voltage_actual);
sakthipriya 3:07e15677a75c 357
sakthipriya 3:07e15677a75c 358
sakthipriya 3:07e15677a75c 359 arch_data.Batt_1_temp=quant_data.Batt_temp_quant[0];
sakthipriya 3:07e15677a75c 360 arch_data.Batt_2_temp=quant_data.Batt_temp_quant[1];
sakthipriya 3:07e15677a75c 361 arch_data.EPS_PCB_temp=quant_data.voltage_quant[14];
sakthipriya 3:07e15677a75c 362 arch_data.Batt_SOC=quant_data.Batt_gauge_quant[1];
sakthipriya 3:07e15677a75c 363 arch_data.power_mode=actual_data.power_mode;
sakthipriya 5:bb592f3185cc 364 arch_data.faultPoll_status=actual_data.faultPoll_status;
sakthipriya 5:bb592f3185cc 365 arch_data.faultIr_status=actual_data.faultIr_status;
sakthipriya 3:07e15677a75c 366 arch_data.Batt_voltage=quant_data.Batt_voltage_quant;
sakthipriya 6:036d08b62785 367 printf("\n\r in hk");
sakthipriya 3:07e15677a75c 368
sakthipriya 3:07e15677a75c 369 }
sakthipriya 3:07e15677a75c 370
sakthipriya 5:bb592f3185cc 371 void FCTN_APPEND_HKDATA()
sakthipriya 5:bb592f3185cc 372 {
sakthipriya 5:bb592f3185cc 373 // quantized data
sakthipriya 5:bb592f3185cc 374 for (int i=0;i<16;i++)
sakthipriya 5:bb592f3185cc 375 BAE_data[i] = quant_data.voltage_quant[i];
sakthipriya 5:bb592f3185cc 376 for (int i=16;i<28;i++)
sakthipriya 5:bb592f3185cc 377 BAE_data[i] = quant_data.current_quant[i-16];
sakthipriya 5:bb592f3185cc 378 BAE_data[28] = quant_data.Batt_temp_quant[0];
sakthipriya 5:bb592f3185cc 379 BAE_data[29] = quant_data.Batt_temp_quant[1];
sakthipriya 5:bb592f3185cc 380 BAE_data[30] = quant_data.Batt_gauge_quant[1];
sakthipriya 5:bb592f3185cc 381 BAE_data[31] = quant_data.Batt_gauge_quant[1];
sakthipriya 5:bb592f3185cc 382 BAE_data[32] = quant_data.Batt_gauge_quant[1];
sakthipriya 5:bb592f3185cc 383 FCTN_CONVERT_FLOAT(quant_data.Batt_gauge_alerts,&BAE_data[33]);
sakthipriya 5:bb592f3185cc 384 BAE_data[37] = quant_data.BAE_temp_quant;
sakthipriya 5:bb592f3185cc 385 FCTN_CONVERT_FLOAT(quant_data.AngularSpeed_quant[0],&BAE_data[38]);
sakthipriya 6:036d08b62785 386 //printf("\n\r outside %d %d %d %d", BAE_data[38],BAE_data[39],BAE_data[40],BAE_data[41]);
sakthipriya 6:036d08b62785 387 //std:: cout << "\n\r uint8 outside " << BAE_data[38] << '\t' << BAE_data[39] << '\t' << BAE_data[40] << '\t' << BAE_data[41] <<std::endl;
sakthipriya 5:bb592f3185cc 388 FCTN_CONVERT_FLOAT(quant_data.AngularSpeed_quant[1],&BAE_data[42]);
sakthipriya 6:036d08b62785 389 //std:: cout << "\n\r uint8 outside " << BAE_data[42] << '\t' << BAE_data[43] << '\t' << BAE_data[44] << '\t' << BAE_data[45] <<std::endl;
sakthipriya 6:036d08b62785 390 // printf("\n\r outside %d %d %d %d", BAE_data[42],BAE_data[43],BAE_data[44],BAE_data[45]);
sakthipriya 5:bb592f3185cc 391 FCTN_CONVERT_FLOAT(quant_data.AngularSpeed_quant[2],&BAE_data[46]);
sakthipriya 6:036d08b62785 392 //printf("\n\r outside %d %d %d %d", BAE_data[46],BAE_data[47],BAE_data[48],BAE_data[49]);
sakthipriya 6:036d08b62785 393 //std:: cout << "\n\r uint8 outside " << BAE_data[46] << '\t' << BAE_data[47] << '\t' << BAE_data[48] << '\t' << BAE_data[49] <<std::endl;
sakthipriya 5:bb592f3185cc 394 FCTN_CONVERT_FLOAT(quant_data.Bvalue_quant[0],&BAE_data[50]);
sakthipriya 5:bb592f3185cc 395 FCTN_CONVERT_FLOAT(quant_data.Bvalue_quant[1],&BAE_data[54]);
sakthipriya 5:bb592f3185cc 396 FCTN_CONVERT_FLOAT(quant_data.Bvalue_quant[2],&BAE_data[58]);
sakthipriya 5:bb592f3185cc 397 BAE_data[62] = quant_data.Batt_voltage_quant;
sakthipriya 5:bb592f3185cc 398 BAE_data[63] = (uint8_t)actual_data.power_mode;
sakthipriya 5:bb592f3185cc 399 BAE_data[64] = actual_data.faultPoll_status;
sakthipriya 5:bb592f3185cc 400 BAE_data[65] = actual_data.faultIr_status;
sakthipriya 5:bb592f3185cc 401 // archived data
sakthipriya 5:bb592f3185cc 402 BAE_data[66] = arch_data.Batt_1_temp; //verify if uint8_t is right
sakthipriya 5:bb592f3185cc 403 BAE_data[67] = arch_data.Batt_2_temp;
sakthipriya 5:bb592f3185cc 404 BAE_data[68] = arch_data.EPS_PCB_temp;
sakthipriya 5:bb592f3185cc 405 BAE_data[69] = arch_data.Batt_SOC;
sakthipriya 5:bb592f3185cc 406 BAE_data[70] = (uint8_t)arch_data.power_mode;
sakthipriya 5:bb592f3185cc 407 BAE_data[71] = arch_data.faultPoll_status;
sakthipriya 5:bb592f3185cc 408 BAE_data[72] = arch_data.faultIr_status;
sakthipriya 5:bb592f3185cc 409 BAE_data[73] = arch_data.Batt_voltage;
sakthipriya 6:036d08b62785 410 for(int i=0; i<73;i++)
sakthipriya 6:036d08b62785 411 BAE_chardata[i] = (char)BAE_data[i];
sakthipriya 6:036d08b62785 412 BAE_chardata[73] = '\0';
sakthipriya 7:a46a1dee4497 413 printf("\n\r bae ats data %c %c %c", BAE_chardata[38],BAE_chardata[39],BAE_chardata[40]);
sakthipriya 6:036d08b62785 414 printf("\n\r BAE data is %s", BAE_chardata);
sakthipriya 5:bb592f3185cc 415
sakthipriya 5:bb592f3185cc 416 }
sakthipriya 5:bb592f3185cc 417
sakthipriya 5:bb592f3185cc 418 uint8_t quantiz(float start,float step,float x)
sakthipriya 0:7b4c00e3912f 419 {
sakthipriya 0:7b4c00e3912f 420 int y=(x-start)/step;
sakthipriya 0:7b4c00e3912f 421 if(y<=0)y=0;
sakthipriya 0:7b4c00e3912f 422 if(y>=255)y=255;
sakthipriya 0:7b4c00e3912f 423 return y;
sakthipriya 0:7b4c00e3912f 424 }
sakthipriya 0:7b4c00e3912f 425
sakthipriya 3:07e15677a75c 426 bool firstCount=true; // goes to EPS init
sakthipriya 3:07e15677a75c 427
sakthipriya 3:07e15677a75c 428
sakthipriya 3:07e15677a75c 429 void saveMin(char x,char y){
sakthipriya 3:07e15677a75c 430 if(y<x){
sakthipriya 3:07e15677a75c 431 x=y;
sakthipriya 3:07e15677a75c 432 }
sakthipriya 3:07e15677a75c 433
sakthipriya 3:07e15677a75c 434 }
sakthipriya 3:07e15677a75c 435 void saveMax(char x,char y){
sakthipriya 3:07e15677a75c 436 if (y>x)
sakthipriya 3:07e15677a75c 437 {
sakthipriya 3:07e15677a75c 438 x=y;
sakthipriya 3:07e15677a75c 439 }
sakthipriya 0:7b4c00e3912f 440 }
sakthipriya 0:7b4c00e3912f 441
sakthipriya 3:07e15677a75c 442
sakthipriya 3:07e15677a75c 443 void minMaxHkData(){
sakthipriya 3:07e15677a75c 444 if(firstCount==true){
sakthipriya 3:07e15677a75c 445 for (int i = 0; i < 16; ++i){
sakthipriya 3:07e15677a75c 446 bae_HK_minmax.voltage_min[i] = quant_data.voltage_quant[i];
sakthipriya 3:07e15677a75c 447 bae_HK_minmax.voltage_max[i] = quant_data.voltage_quant[i];
sakthipriya 3:07e15677a75c 448 }
sakthipriya 3:07e15677a75c 449 for (int i = 0; i < 12; ++i){
sakthipriya 3:07e15677a75c 450 bae_HK_minmax.current_min[i] = quant_data.current_quant[i];
sakthipriya 3:07e15677a75c 451 bae_HK_minmax.current_max[i] = quant_data.current_quant[i];
sakthipriya 3:07e15677a75c 452 }
sakthipriya 3:07e15677a75c 453
sakthipriya 3:07e15677a75c 454 for (int i = 0; i < 2; ++i){
sakthipriya 3:07e15677a75c 455 bae_HK_minmax.Batt_temp_min[i] = quant_data.Batt_temp_quant[i];
sakthipriya 3:07e15677a75c 456 bae_HK_minmax.Batt_temp_max[i] = quant_data.Batt_temp_quant[i];
sakthipriya 3:07e15677a75c 457 }
sakthipriya 3:07e15677a75c 458 for (int i = 0; i < 3; ++i){
sakthipriya 3:07e15677a75c 459 bae_HK_minmax.Batt_gauge_min[i] = quant_data.Batt_gauge_quant[i];
sakthipriya 3:07e15677a75c 460 bae_HK_minmax.Batt_gauge_max[i] = quant_data.Batt_gauge_quant[i];
sakthipriya 3:07e15677a75c 461 }
sakthipriya 3:07e15677a75c 462 for (int i = 0; i < 3; ++i){
sakthipriya 3:07e15677a75c 463 bae_HK_minmax.AngularSpeed_min[i] = quant_data.AngularSpeed_quant[i];
sakthipriya 3:07e15677a75c 464 bae_HK_minmax.AngularSpeed_max[i] = quant_data.AngularSpeed_quant[i];
sakthipriya 3:07e15677a75c 465 }
sakthipriya 3:07e15677a75c 466 for (int i = 0; i < 3; ++i){
sakthipriya 3:07e15677a75c 467 bae_HK_minmax.Bvalue_min[i] = quant_data.Bvalue_quant[i];
sakthipriya 3:07e15677a75c 468 bae_HK_minmax.Bvalue_max[i] = quant_data.Bvalue_quant[i];
sakthipriya 3:07e15677a75c 469 }
sakthipriya 3:07e15677a75c 470 bae_HK_minmax.BAE_temp_min=quant_data.BAE_temp_quant;
sakthipriya 3:07e15677a75c 471 bae_HK_minmax.BAE_temp_max=quant_data.BAE_temp_quant;
sakthipriya 3:07e15677a75c 472 bae_HK_minmax.Batt_voltage_min=quant_data.Batt_voltage_quant;
sakthipriya 3:07e15677a75c 473 bae_HK_minmax.Batt_voltage_max=quant_data.Batt_voltage_quant;
sakthipriya 3:07e15677a75c 474
sakthipriya 3:07e15677a75c 475 }
sakthipriya 3:07e15677a75c 476 else {
sakthipriya 3:07e15677a75c 477 for (int i = 0; i < 16; ++i)
sakthipriya 3:07e15677a75c 478 {
sakthipriya 3:07e15677a75c 479 saveMin(bae_HK_minmax.voltage_min[i],quant_data.voltage_quant[i]);
sakthipriya 3:07e15677a75c 480 saveMax(bae_HK_minmax.voltage_max[i],quant_data.voltage_quant[i]);
sakthipriya 3:07e15677a75c 481 }
sakthipriya 3:07e15677a75c 482 for (int i = 0; i < 12; ++i)
sakthipriya 3:07e15677a75c 483 {
sakthipriya 3:07e15677a75c 484 saveMin(bae_HK_minmax.current_min[i],quant_data.current_quant[i]);
sakthipriya 3:07e15677a75c 485 saveMax(bae_HK_minmax.current_max[i],quant_data.current_quant[i]);
sakthipriya 3:07e15677a75c 486 }
sakthipriya 3:07e15677a75c 487
sakthipriya 3:07e15677a75c 488 for (int i = 0; i < 2; ++i)
sakthipriya 3:07e15677a75c 489 {
sakthipriya 3:07e15677a75c 490 saveMin(bae_HK_minmax.Batt_temp_min[i],quant_data.Batt_temp_quant[i]);
sakthipriya 3:07e15677a75c 491 saveMax(bae_HK_minmax.Batt_temp_max[i],quant_data.Batt_temp_quant[i]);
sakthipriya 3:07e15677a75c 492 }
sakthipriya 3:07e15677a75c 493 for (int i = 0; i < 3; ++i)
sakthipriya 3:07e15677a75c 494 {
sakthipriya 3:07e15677a75c 495 saveMin(bae_HK_minmax.Batt_gauge_min[i], quant_data.Batt_gauge_quant[i]);
sakthipriya 3:07e15677a75c 496 saveMax(bae_HK_minmax.Batt_gauge_max[i], quant_data.Batt_gauge_quant[i]);
sakthipriya 3:07e15677a75c 497 }
sakthipriya 3:07e15677a75c 498 for (int i = 0; i < 3; ++i)
sakthipriya 3:07e15677a75c 499 {
sakthipriya 3:07e15677a75c 500 saveMin(bae_HK_minmax.AngularSpeed_min[i], quant_data.AngularSpeed_quant[i]);
sakthipriya 3:07e15677a75c 501 saveMax(bae_HK_minmax.AngularSpeed_max[i], quant_data.AngularSpeed_quant[i]);
sakthipriya 3:07e15677a75c 502 }
sakthipriya 3:07e15677a75c 503 for (int i = 0; i < 3; ++i)
sakthipriya 3:07e15677a75c 504 {
sakthipriya 3:07e15677a75c 505 saveMin(bae_HK_minmax.Bvalue_min[i], quant_data.Bvalue_quant[i]);
sakthipriya 3:07e15677a75c 506 saveMax(bae_HK_minmax.Bvalue_max[i], quant_data.Bvalue_quant[i]);
sakthipriya 3:07e15677a75c 507 }
sakthipriya 3:07e15677a75c 508 saveMin(bae_HK_minmax.BAE_temp_min,quant_data.BAE_temp_quant);
sakthipriya 3:07e15677a75c 509 saveMax(bae_HK_minmax.BAE_temp_max,quant_data.BAE_temp_quant);
sakthipriya 3:07e15677a75c 510 saveMin(bae_HK_minmax.Batt_voltage_min,quant_data.Batt_voltage_quant);
sakthipriya 3:07e15677a75c 511 saveMin(bae_HK_minmax.Batt_voltage_max,quant_data.Batt_voltage_quant);
sakthipriya 3:07e15677a75c 512
sakthipriya 3:07e15677a75c 513
sakthipriya 3:07e15677a75c 514 }
sakthipriya 3:07e15677a75c 515 firstCount=false;
sakthipriya 3:07e15677a75c 516 }
sakthipriya 3:07e15677a75c 517
sakthipriya 3:07e15677a75c 518
sakthipriya 0:7b4c00e3912f 519 //............................................BATTERY GAUGE......................................//
sakthipriya 0:7b4c00e3912f 520 void FCTN_BATTERYGAUGE_INIT()
sakthipriya 0:7b4c00e3912f 521 {
sakthipriya 0:7b4c00e3912f 522 disable_sleep();
sakthipriya 0:7b4c00e3912f 523 disable_hibernate();
sakthipriya 0:7b4c00e3912f 524 socChangeAlertEnabled(true); //enabling alert on soc changing by 1%
sakthipriya 0:7b4c00e3912f 525 emptyAlertThreshold(32);//setting empty alert threshold to 32% soc
sakthipriya 0:7b4c00e3912f 526 vAlertMinMaxThreshold();//set min, max value of Valrt register
sakthipriya 0:7b4c00e3912f 527 vResetThresholdSet();//set threshold voltage for reset
sakthipriya 0:7b4c00e3912f 528 vResetAlertEnabled(true);//enable alert on reset for V < Vreset
sakthipriya 0:7b4c00e3912f 529 }
sakthipriya 0:7b4c00e3912f 530
sakthipriya 0:7b4c00e3912f 531 void FCTN_BATTERYGAUGE_MAIN(float Battery_parameters[4])
sakthipriya 0:7b4c00e3912f 532 {
sakthipriya 1:446a959e36ce 533 printf("\n\r battery gauge \n");
sakthipriya 0:7b4c00e3912f 534
sakthipriya 3:07e15677a75c 535 float temp=30; //=Battery_temp (from temp sensor on battery board) //value of battery temperature in C currently given a dummy value. Should be updated everytime.
sakthipriya 0:7b4c00e3912f 536 tempCompensation(temp);
sakthipriya 0:7b4c00e3912f 537
sakthipriya 0:7b4c00e3912f 538
sakthipriya 0:7b4c00e3912f 539 Battery_parameters[0]=vcell();
sakthipriya 0:7b4c00e3912f 540 Battery_parameters[1]=soc();
sakthipriya 0:7b4c00e3912f 541 Battery_parameters[2]=crate();
sakthipriya 0:7b4c00e3912f 542
sakthipriya 0:7b4c00e3912f 543 printf("\nVcell=%f",vcell()); //remove this for final code
sakthipriya 0:7b4c00e3912f 544 printf("\nSOC=%f",soc()); //remove this for final code
sakthipriya 0:7b4c00e3912f 545 printf("\nC_rate=%f",crate()); //remove this for final code
sakthipriya 0:7b4c00e3912f 546
sakthipriya 0:7b4c00e3912f 547
sakthipriya 0:7b4c00e3912f 548 if (alerting()== true) //alert is on
sakthipriya 0:7b4c00e3912f 549 {
sakthipriya 0:7b4c00e3912f 550 Battery_parameters[3]=alertFlags();
sakthipriya 0:7b4c00e3912f 551 clearAlert();//clear alert
sakthipriya 0:7b4c00e3912f 552 clearAlertFlags();//clear all alert flags
sakthipriya 0:7b4c00e3912f 553 }
sakthipriya 0:7b4c00e3912f 554
sakthipriya 0:7b4c00e3912f 555 }
sakthipriya 0:7b4c00e3912f 556
sakthipriya 0:7b4c00e3912f 557 unsigned short read(char reg)
sakthipriya 0:7b4c00e3912f 558 {
sakthipriya 0:7b4c00e3912f 559
sakthipriya 0:7b4c00e3912f 560 //Create a temporary buffer
sakthipriya 0:7b4c00e3912f 561 char buff[2];
sakthipriya 0:7b4c00e3912f 562
sakthipriya 0:7b4c00e3912f 563 //Select the register
sakthipriya 0:7b4c00e3912f 564 m_I2C.write(m_ADDR, &reg, 1, true);
sakthipriya 0:7b4c00e3912f 565
sakthipriya 0:7b4c00e3912f 566 //Read the 16-bit register
sakthipriya 0:7b4c00e3912f 567 m_I2C.read(m_ADDR, buff, 2);
sakthipriya 0:7b4c00e3912f 568
sakthipriya 0:7b4c00e3912f 569 //Return the combined 16-bit value
sakthipriya 0:7b4c00e3912f 570 return (buff[0] << 8) | buff[1];
sakthipriya 0:7b4c00e3912f 571 }
sakthipriya 0:7b4c00e3912f 572
sakthipriya 3:07e15677a75c 573
sakthipriya 1:446a959e36ce 574
sakthipriya 3:07e15677a75c 575
sakthipriya 0:7b4c00e3912f 576
sakthipriya 0:7b4c00e3912f 577 void write(char reg, unsigned short data)
sakthipriya 0:7b4c00e3912f 578 {
sakthipriya 0:7b4c00e3912f 579 //Create a temporary buffer
sakthipriya 0:7b4c00e3912f 580 char buff[3];
sakthipriya 0:7b4c00e3912f 581
sakthipriya 0:7b4c00e3912f 582 //Load the register address and 16-bit data
sakthipriya 0:7b4c00e3912f 583 buff[0] = reg;
sakthipriya 0:7b4c00e3912f 584 buff[1] = data >> 8;
sakthipriya 0:7b4c00e3912f 585 buff[2] = data;
sakthipriya 0:7b4c00e3912f 586
sakthipriya 0:7b4c00e3912f 587 //Write the data
sakthipriya 0:7b4c00e3912f 588 m_I2C.write(m_ADDR, buff, 3);
sakthipriya 0:7b4c00e3912f 589 }
sakthipriya 0:7b4c00e3912f 590
sakthipriya 0:7b4c00e3912f 591
sakthipriya 0:7b4c00e3912f 592
sakthipriya 0:7b4c00e3912f 593 // Command the MAX17049 to perform a power-on reset
sakthipriya 0:7b4c00e3912f 594 void reset()
sakthipriya 0:7b4c00e3912f 595 {
sakthipriya 0:7b4c00e3912f 596 //Write the POR command
sakthipriya 0:7b4c00e3912f 597 write(REG_CMD, 0x5400);
sakthipriya 0:7b4c00e3912f 598 }
sakthipriya 0:7b4c00e3912f 599
sakthipriya 0:7b4c00e3912f 600 // Command the MAX17049 to perform a QuickStart
sakthipriya 0:7b4c00e3912f 601 void quickStart()
sakthipriya 0:7b4c00e3912f 602 {
sakthipriya 0:7b4c00e3912f 603 //Read the current 16-bit register value
sakthipriya 0:7b4c00e3912f 604 unsigned short value = read(REG_MODE);
lakshya 15:e09aaaccf134 605
sakthipriya 0:7b4c00e3912f 606 //Set the QuickStart bit
sakthipriya 0:7b4c00e3912f 607 value |= (1 << 14);
sakthipriya 0:7b4c00e3912f 608
sakthipriya 0:7b4c00e3912f 609 //Write the value back out
sakthipriya 0:7b4c00e3912f 610 write(REG_MODE, value);
sakthipriya 0:7b4c00e3912f 611 }
sakthipriya 0:7b4c00e3912f 612
sakthipriya 0:7b4c00e3912f 613
sakthipriya 0:7b4c00e3912f 614 //disable sleep
sakthipriya 0:7b4c00e3912f 615 void disable_sleep()
sakthipriya 0:7b4c00e3912f 616 {
sakthipriya 0:7b4c00e3912f 617 unsigned short value = read(REG_MODE);
sakthipriya 0:7b4c00e3912f 618 value &= ~(1 << 13);
sakthipriya 0:7b4c00e3912f 619 write(REG_MODE, value);
sakthipriya 0:7b4c00e3912f 620 }
sakthipriya 0:7b4c00e3912f 621
sakthipriya 0:7b4c00e3912f 622 //disable the hibernate of the MAX17049
sakthipriya 0:7b4c00e3912f 623 void disable_hibernate()
sakthipriya 0:7b4c00e3912f 624 {
sakthipriya 0:7b4c00e3912f 625 write(REG_HIBRT, 0x0000);
sakthipriya 0:7b4c00e3912f 626 }
sakthipriya 0:7b4c00e3912f 627
sakthipriya 0:7b4c00e3912f 628
sakthipriya 0:7b4c00e3912f 629 // Enable or disable the SOC 1% change alert on the MAX17049
sakthipriya 0:7b4c00e3912f 630 void socChangeAlertEnabled(bool enabled)
sakthipriya 0:7b4c00e3912f 631 {
sakthipriya 0:7b4c00e3912f 632 //Read the current 16-bit register value
sakthipriya 0:7b4c00e3912f 633 unsigned short value = read(REG_CONFIG);
sakthipriya 0:7b4c00e3912f 634
sakthipriya 0:7b4c00e3912f 635 //Set or clear the ALSC bit
sakthipriya 0:7b4c00e3912f 636 if (enabled)
sakthipriya 0:7b4c00e3912f 637 value |= (1 << 6);
sakthipriya 0:7b4c00e3912f 638 else
sakthipriya 0:7b4c00e3912f 639 value &= ~(1 << 6);
sakthipriya 0:7b4c00e3912f 640
sakthipriya 0:7b4c00e3912f 641 //Write the value back out
sakthipriya 0:7b4c00e3912f 642 write(REG_CONFIG, value);
sakthipriya 0:7b4c00e3912f 643 }
sakthipriya 0:7b4c00e3912f 644
sakthipriya 0:7b4c00e3912f 645
sakthipriya 0:7b4c00e3912f 646 void compensation(char rcomp)
sakthipriya 0:7b4c00e3912f 647 {
sakthipriya 0:7b4c00e3912f 648 //Read the current 16-bit register value
sakthipriya 0:7b4c00e3912f 649 unsigned short value = read(REG_CONFIG);
sakthipriya 0:7b4c00e3912f 650
sakthipriya 0:7b4c00e3912f 651 //Update the register value
sakthipriya 0:7b4c00e3912f 652 value &= 0x00FF;
sakthipriya 0:7b4c00e3912f 653 value |= rcomp << 8;
sakthipriya 0:7b4c00e3912f 654
sakthipriya 0:7b4c00e3912f 655 //Write the value back out
sakthipriya 0:7b4c00e3912f 656 write(REG_CONFIG, value);
sakthipriya 0:7b4c00e3912f 657 }
sakthipriya 0:7b4c00e3912f 658
sakthipriya 0:7b4c00e3912f 659
sakthipriya 0:7b4c00e3912f 660 void tempCompensation(float temp)
sakthipriya 0:7b4c00e3912f 661 {
sakthipriya 0:7b4c00e3912f 662 //Calculate the new RCOMP value
sakthipriya 0:7b4c00e3912f 663 char rcomp;
sakthipriya 0:7b4c00e3912f 664 if (temp > 20.0) {
sakthipriya 0:7b4c00e3912f 665 rcomp = RCOMP0 + (temp - 20.0) * -0.5;
sakthipriya 0:7b4c00e3912f 666 } else {
sakthipriya 0:7b4c00e3912f 667 rcomp = RCOMP0 + (temp - 20.0) * -5.0;
sakthipriya 0:7b4c00e3912f 668 }
sakthipriya 0:7b4c00e3912f 669
sakthipriya 0:7b4c00e3912f 670 //Update the RCOMP value
sakthipriya 0:7b4c00e3912f 671 compensation(rcomp);
sakthipriya 0:7b4c00e3912f 672 }
sakthipriya 0:7b4c00e3912f 673
sakthipriya 0:7b4c00e3912f 674 // Command the MAX17049 to de-assert the ALRT pin
sakthipriya 0:7b4c00e3912f 675 void clearAlert()
sakthipriya 0:7b4c00e3912f 676 {
sakthipriya 0:7b4c00e3912f 677 //Read the current 16-bit register value
sakthipriya 0:7b4c00e3912f 678 unsigned short value = read(REG_CONFIG);
sakthipriya 0:7b4c00e3912f 679
sakthipriya 0:7b4c00e3912f 680 //Clear the ALRT bit
sakthipriya 0:7b4c00e3912f 681 value &= ~(1 << 5);
sakthipriya 0:7b4c00e3912f 682
sakthipriya 0:7b4c00e3912f 683 //Write the value back out
sakthipriya 0:7b4c00e3912f 684 write(REG_CONFIG, value);
sakthipriya 0:7b4c00e3912f 685 }
sakthipriya 0:7b4c00e3912f 686
sakthipriya 0:7b4c00e3912f 687
sakthipriya 0:7b4c00e3912f 688 //Set the SOC empty alert threshold of the MAX17049
sakthipriya 0:7b4c00e3912f 689 void emptyAlertThreshold(char threshold)
sakthipriya 0:7b4c00e3912f 690 {
sakthipriya 0:7b4c00e3912f 691 //Read the current 16-bit register value
sakthipriya 0:7b4c00e3912f 692 unsigned short value = read(REG_CONFIG);
sakthipriya 0:7b4c00e3912f 693
sakthipriya 0:7b4c00e3912f 694 //Update the register value
sakthipriya 0:7b4c00e3912f 695 value &= 0xFFE0;
sakthipriya 0:7b4c00e3912f 696 value |= 32 - threshold;
sakthipriya 0:7b4c00e3912f 697
sakthipriya 0:7b4c00e3912f 698 //Write the 16-bit register
sakthipriya 0:7b4c00e3912f 699 write(REG_CONFIG, value);
sakthipriya 0:7b4c00e3912f 700 }
sakthipriya 0:7b4c00e3912f 701
sakthipriya 0:7b4c00e3912f 702 // Set the low and high voltage alert threshold of the MAX17049
sakthipriya 0:7b4c00e3912f 703 void vAlertMinMaxThreshold()
sakthipriya 0:7b4c00e3912f 704 {
sakthipriya 0:7b4c00e3912f 705 //Read the current 16-bit register value
sakthipriya 0:7b4c00e3912f 706 unsigned short value = read(REG_VALRT);
sakthipriya 0:7b4c00e3912f 707
sakthipriya 0:7b4c00e3912f 708 //Mask off the old value
sakthipriya 0:7b4c00e3912f 709
sakthipriya 0:7b4c00e3912f 710 value = 0x96D2;
sakthipriya 0:7b4c00e3912f 711
sakthipriya 0:7b4c00e3912f 712 //Write the 16-bit register
sakthipriya 0:7b4c00e3912f 713 write(REG_VALRT, value);
sakthipriya 0:7b4c00e3912f 714 }
sakthipriya 0:7b4c00e3912f 715
sakthipriya 0:7b4c00e3912f 716
sakthipriya 0:7b4c00e3912f 717 // Set the reset voltage threshold of the MAX17049
sakthipriya 0:7b4c00e3912f 718 void vResetThresholdSet()
sakthipriya 0:7b4c00e3912f 719 {
sakthipriya 0:7b4c00e3912f 720 //Read the current 16-bit register value
sakthipriya 0:7b4c00e3912f 721 unsigned short value = read(REG_VRESET_ID);
sakthipriya 0:7b4c00e3912f 722
sakthipriya 0:7b4c00e3912f 723 //Mask off the old //value
sakthipriya 0:7b4c00e3912f 724 value &= 0x00FF;//Dis=0
sakthipriya 0:7b4c00e3912f 725
sakthipriya 0:7b4c00e3912f 726 value |= 0x9400;//corresponding to 2.5 V
sakthipriya 0:7b4c00e3912f 727
sakthipriya 0:7b4c00e3912f 728
sakthipriya 0:7b4c00e3912f 729 //Write the 16-bit register
sakthipriya 0:7b4c00e3912f 730 write(REG_VRESET_ID, value);
sakthipriya 0:7b4c00e3912f 731 }
sakthipriya 0:7b4c00e3912f 732
sakthipriya 0:7b4c00e3912f 733
sakthipriya 0:7b4c00e3912f 734 // Enable or disable the voltage reset alert on the MAX17049
sakthipriya 0:7b4c00e3912f 735 void vResetAlertEnabled(bool enabled)
sakthipriya 0:7b4c00e3912f 736 {
sakthipriya 0:7b4c00e3912f 737 //Read the current 16-bit register value
sakthipriya 0:7b4c00e3912f 738 unsigned short value = read(REG_STATUS);
sakthipriya 0:7b4c00e3912f 739
sakthipriya 0:7b4c00e3912f 740 //Set or clear the EnVR bit
sakthipriya 0:7b4c00e3912f 741 if (enabled)
sakthipriya 0:7b4c00e3912f 742 value |= (1 << 14);
sakthipriya 0:7b4c00e3912f 743 else
sakthipriya 0:7b4c00e3912f 744 value &= ~(1 << 14);
sakthipriya 0:7b4c00e3912f 745
sakthipriya 0:7b4c00e3912f 746 //Write the value back out
sakthipriya 0:7b4c00e3912f 747 write(REG_STATUS, value);
sakthipriya 0:7b4c00e3912f 748 }
sakthipriya 0:7b4c00e3912f 749
sakthipriya 0:7b4c00e3912f 750 //Get the current alert flags on the MAX17049
sakthipriya 0:7b4c00e3912f 751 //refer datasheet-status registers section to decode it.
sakthipriya 0:7b4c00e3912f 752 char alertFlags()
sakthipriya 0:7b4c00e3912f 753 {
sakthipriya 0:7b4c00e3912f 754 //Read the 16-bit register value
sakthipriya 0:7b4c00e3912f 755 unsigned short value = read(REG_STATUS);
sakthipriya 0:7b4c00e3912f 756
sakthipriya 0:7b4c00e3912f 757 //Return only the flag bits
sakthipriya 0:7b4c00e3912f 758 return (value >> 8) & 0x3F;
sakthipriya 0:7b4c00e3912f 759 }
sakthipriya 0:7b4c00e3912f 760
sakthipriya 0:7b4c00e3912f 761 // Clear all the alert flags on the MAX17049
sakthipriya 0:7b4c00e3912f 762 void clearAlertFlags()
sakthipriya 0:7b4c00e3912f 763 {
sakthipriya 0:7b4c00e3912f 764 //Read the current 16-bit register value
sakthipriya 0:7b4c00e3912f 765 unsigned short value = read(REG_STATUS);
sakthipriya 0:7b4c00e3912f 766
sakthipriya 0:7b4c00e3912f 767 //Clear the specified flag bits
sakthipriya 0:7b4c00e3912f 768 value &= ~( 0x3F<< 8);
sakthipriya 0:7b4c00e3912f 769
sakthipriya 0:7b4c00e3912f 770 //Write the value back out
sakthipriya 0:7b4c00e3912f 771 write(REG_STATUS, value);
sakthipriya 0:7b4c00e3912f 772 }
sakthipriya 0:7b4c00e3912f 773
sakthipriya 0:7b4c00e3912f 774 // Get the current cell voltage measurement of the MAX17049
sakthipriya 0:7b4c00e3912f 775 float vcell()
sakthipriya 0:7b4c00e3912f 776 {
sakthipriya 1:446a959e36ce 777
sakthipriya 0:7b4c00e3912f 778 //Read the 16-bit raw Vcell value
sakthipriya 0:7b4c00e3912f 779 unsigned short value = read(REG_VCELL);
sakthipriya 0:7b4c00e3912f 780
sakthipriya 0:7b4c00e3912f 781 //Return Vcell in volts
sakthipriya 0:7b4c00e3912f 782 return value * 0.000078125*2;
sakthipriya 0:7b4c00e3912f 783 }
sakthipriya 0:7b4c00e3912f 784
sakthipriya 0:7b4c00e3912f 785 // Get the current state of charge measurement of the MAX17049 as a float
sakthipriya 0:7b4c00e3912f 786 float soc()
sakthipriya 0:7b4c00e3912f 787 {
sakthipriya 3:07e15677a75c 788
sakthipriya 3:07e15677a75c 789 //Create a temporary buffer
sakthipriya 0:7b4c00e3912f 790 char buff[2];
sakthipriya 3:07e15677a75c 791 int ack = 1;
sakthipriya 3:07e15677a75c 792 //Select the register
sakthipriya 3:07e15677a75c 793 char reg = REG_SOC; // cannot pass the hash defined values directly
sakthipriya 3:07e15677a75c 794 m_I2C.write(m_ADDR, &reg, 1, true);
sakthipriya 3:07e15677a75c 795
sakthipriya 3:07e15677a75c 796
sakthipriya 3:07e15677a75c 797 //Read the 16-bit register
sakthipriya 3:07e15677a75c 798
sakthipriya 3:07e15677a75c 799 ack = m_I2C.read(m_ADDR, buff, 2);
sakthipriya 3:07e15677a75c 800
sakthipriya 3:07e15677a75c 801 printf("\n\r acknow %d", ack);
sakthipriya 0:7b4c00e3912f 802
sakthipriya 0:7b4c00e3912f 803 //Return SOC in percent
sakthipriya 2:c823d84b4cb0 804 if(ack == 0)
sakthipriya 3:07e15677a75c 805 return ((buff[0] << 8) | buff[1]) * 0.00390625;
sakthipriya 2:c823d84b4cb0 806 else
sakthipriya 2:c823d84b4cb0 807 return 200;
sakthipriya 0:7b4c00e3912f 808 }
sakthipriya 0:7b4c00e3912f 809
sakthipriya 0:7b4c00e3912f 810
sakthipriya 0:7b4c00e3912f 811
sakthipriya 0:7b4c00e3912f 812 // Get the current C rate measurement of the MAX17049
sakthipriya 0:7b4c00e3912f 813 float crate()
sakthipriya 0:7b4c00e3912f 814 {
sakthipriya 0:7b4c00e3912f 815 //Read the 16-bit raw C/Rate value
sakthipriya 0:7b4c00e3912f 816 short value = read(REG_CRATE);
sakthipriya 0:7b4c00e3912f 817
sakthipriya 0:7b4c00e3912f 818 //Return C/Rate in %/hr
sakthipriya 0:7b4c00e3912f 819 return value * 0.208;
sakthipriya 0:7b4c00e3912f 820 }
sakthipriya 0:7b4c00e3912f 821
sakthipriya 0:7b4c00e3912f 822 // Determine whether or not the MAX17049 is asserting the ALRT pin
sakthipriya 0:7b4c00e3912f 823 bool alerting()
sakthipriya 0:7b4c00e3912f 824 {
sakthipriya 0:7b4c00e3912f 825 //Read the 16-bit register value
sakthipriya 0:7b4c00e3912f 826 unsigned short value = read(REG_CONFIG);
sakthipriya 0:7b4c00e3912f 827
sakthipriya 0:7b4c00e3912f 828 //Return the status of the ALRT bit
sakthipriya 0:7b4c00e3912f 829 if (value & (1 << 5))
sakthipriya 0:7b4c00e3912f 830 return true;
sakthipriya 0:7b4c00e3912f 831 else
sakthipriya 0:7b4c00e3912f 832 return false;
sakthipriya 2:c823d84b4cb0 833 }
sakthipriya 2:c823d84b4cb0 834
sakthipriya 2:c823d84b4cb0 835 //.............................Battery board Temp sensor........................//
sakthipriya 2:c823d84b4cb0 836 void FCTN_BATTTEMP_INIT()
sakthipriya 2:c823d84b4cb0 837 {
sakthipriya 2:c823d84b4cb0 838 ssn1=1;ssn2=1;
sakthipriya 2:c823d84b4cb0 839 //PS=0;
sakthipriya 2:c823d84b4cb0 840 //HS=0;
sakthipriya 2:c823d84b4cb0 841 spi_bt.format(8,3);
sakthipriya 2:c823d84b4cb0 842 spi_bt.frequency(1000000);
azaddevarm 16:5f0f2a3f3e8d 843 EPS_BATTERY_TEMP_STATUS = 1;
sakthipriya 2:c823d84b4cb0 844 }
sakthipriya 2:c823d84b4cb0 845
sakthipriya 2:c823d84b4cb0 846 void FCTN_BATT_TEMP_SENSOR_MAIN(float temp[2])
sakthipriya 2:c823d84b4cb0 847 {
sakthipriya 2:c823d84b4cb0 848 uint8_t MSB, LSB;
sakthipriya 2:c823d84b4cb0 849 int16_t bit_data;
sakthipriya 2:c823d84b4cb0 850 float sensitivity=0.0078125; //1 LSB = sensitivity degree celcius
sakthipriya 2:c823d84b4cb0 851 wait_ms(320);
sakthipriya 2:c823d84b4cb0 852 ssn1=0;
sakthipriya 2:c823d84b4cb0 853
sakthipriya 2:c823d84b4cb0 854 spi_bt.write(0x80);//Reading digital data from Sensor 1
sakthipriya 2:c823d84b4cb0 855 LSB = spi_bt.write(0x00);//LSB first
sakthipriya 2:c823d84b4cb0 856 wait_ms(0);
sakthipriya 2:c823d84b4cb0 857 MSB = spi_bt.write(0x00);
sakthipriya 2:c823d84b4cb0 858 wait_ms(10);
sakthipriya 2:c823d84b4cb0 859 pc_eps.printf("%d %d\n",MSB,LSB);
sakthipriya 2:c823d84b4cb0 860 bit_data= ((uint16_t)MSB<<8)|LSB;
sakthipriya 2:c823d84b4cb0 861 wait_ms(10);
sakthipriya 2:c823d84b4cb0 862 temp[0]=(float)bit_data*sensitivity;//Converting into decimal value
sakthipriya 2:c823d84b4cb0 863 ssn1=1;
sakthipriya 2:c823d84b4cb0 864 wait_ms(10);
sakthipriya 2:c823d84b4cb0 865 ssn2=0;//Reading data from sensor 2
sakthipriya 2:c823d84b4cb0 866 spi_bt.write(0x80);
sakthipriya 2:c823d84b4cb0 867 LSB = spi_bt.write(0x00);
sakthipriya 2:c823d84b4cb0 868 wait_ms(10);
sakthipriya 2:c823d84b4cb0 869 MSB = spi_bt.write(0x00);
sakthipriya 2:c823d84b4cb0 870 wait_ms(10);
sakthipriya 2:c823d84b4cb0 871 bit_data= ((int16_t)MSB<<8)|LSB;
sakthipriya 2:c823d84b4cb0 872 wait_ms(10);
sakthipriya 2:c823d84b4cb0 873 temp[1]=(float)bit_data*sensitivity;
sakthipriya 2:c823d84b4cb0 874 ssn2=1;
sakthipriya 2:c823d84b4cb0 875
sakthipriya 2:c823d84b4cb0 876 }