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: FreescaleIAP mbed-rtos mbed
Fork of workinQM_5thJan_azad by
EPS.h@30:22b338b027de, 2016-07-01 (annotated)
- Committer:
- azaddevarm
- Date:
- Fri Jul 01 14:59:12 2016 +0000
- Revision:
- 30:22b338b027de
- Parent:
- 28:5f0f2a3f3e8d
- Child:
- 31:046685b48b71
Final code for EPS;
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| sakthipriya | 0:7b4c00e3912f | 1 | #include <mbed.h> | 
| sakthipriya | 0:7b4c00e3912f | 2 | |
| azaddevarm | 30:22b338b027de | 3 | /* | 
| azaddevarm | 30:22b338b027de | 4 | Tasks left: | 
| azaddevarm | 30:22b338b027de | 5 | |
| azaddevarm | 30:22b338b027de | 6 | 2. EPS battery heater automation with customised timer | 
| azaddevarm | 30:22b338b027de | 7 | |
| azaddevarm | 30:22b338b027de | 8 | */ | 
| azaddevarm | 30:22b338b027de | 9 | /* | 
| azaddevarm | 30:22b338b027de | 10 | //EPS STATES// | 
| azaddevarm | 30:22b338b027de | 11 | |
| azaddevarm | 30:22b338b027de | 12 | if (EPS_STATUS==0) | 
| azaddevarm | 30:22b338b027de | 13 | Set EPS_ERR_BATTERY_TEMP | 
| azaddevarm | 30:22b338b027de | 14 | else if (EPS_STATUS==1) | 
| azaddevarm | 30:22b338b027de | 15 | Set EPS_BATTERY_HEATER_DISABLED | 
| azaddevarm | 30:22b338b027de | 16 | else if (EPS_STATUS==2) | 
| azaddevarm | 30:22b338b027de | 17 | Set EPS_ERR_HEATER_SWITCH_OFF | 
| azaddevarm | 30:22b338b027de | 18 | else if (EPS_STATUS==3) | 
| azaddevarm | 30:22b338b027de | 19 | Set EPS_ERR_HEATER_SWITCH_ON | 
| azaddevarm | 30:22b338b027de | 20 | else if (EPS_STATUS==4) | 
| azaddevarm | 30:22b338b027de | 21 | Set EPS_BATTERY_HEATER_OFF | 
| azaddevarm | 30:22b338b027de | 22 | else if (EPS_STATUS==5) | 
| azaddevarm | 30:22b338b027de | 23 | Set EPS_BATTERY_HEATER_ON | 
| azaddevarm | 30:22b338b027de | 24 | */ | 
| azaddevarm | 30:22b338b027de | 25 | |
| sakthipriya | 0:7b4c00e3912f | 26 | #define tstart -40 | 
| sakthipriya | 0:7b4c00e3912f | 27 | #define tstep 8 | 
| sakthipriya | 0:7b4c00e3912f | 28 | #define tstep_thermistor 8 //verify everything!! | 
| sakthipriya | 0:7b4c00e3912f | 29 | #define tstart_thermistor -40 | 
| sakthipriya | 0:7b4c00e3912f | 30 | #define vstart 3.3 | 
| sakthipriya | 0:7b4c00e3912f | 31 | #define vstep 0.84667 | 
| sakthipriya | 0:7b4c00e3912f | 32 | #define cstart 0.0691 | 
| sakthipriya | 0:7b4c00e3912f | 33 | #define cstep 0.09133 | 
| sakthipriya | 2:c823d84b4cb0 | 34 | #define vcell_start 5 //check | 
| sakthipriya | 2:c823d84b4cb0 | 35 | #define vcell_step 0.0133 //check | 
| sakthipriya | 2:c823d84b4cb0 | 36 | #define soc_start 0 | 
| sakthipriya | 2:c823d84b4cb0 | 37 | #define soc_step 0.3921 | 
| sakthipriya | 2:c823d84b4cb0 | 38 | #define crate_start 0 //check | 
| sakthipriya | 2:c823d84b4cb0 | 39 | #define crate_step 1 //check | 
| sakthipriya | 2:c823d84b4cb0 | 40 | #define AngularSpeed_start 0 //check | 
| sakthipriya | 2:c823d84b4cb0 | 41 | #define AngularSpeed_step 0.1 //check | 
| sakthipriya | 0:7b4c00e3912f | 42 | #define rsens 0.095 | 
| sakthipriya | 0:7b4c00e3912f | 43 | |
| sakthipriya | 2:c823d84b4cb0 | 44 | |
| sakthipriya | 0:7b4c00e3912f | 45 | #define m_ADDR (0x6C) //slave address | 
| sakthipriya | 0:7b4c00e3912f | 46 | |
| sakthipriya | 0:7b4c00e3912f | 47 | //I2C register addresses | 
| sakthipriya | 0:7b4c00e3912f | 48 | #define REG_VCELL 0x02 | 
| sakthipriya | 0:7b4c00e3912f | 49 | #define REG_SOC 0x04 | 
| sakthipriya | 0:7b4c00e3912f | 50 | #define REG_MODE 0x06 | 
| sakthipriya | 0:7b4c00e3912f | 51 | #define REG_VERSION 0x08 | 
| sakthipriya | 0:7b4c00e3912f | 52 | #define REG_HIBRT 0x0A | 
| sakthipriya | 0:7b4c00e3912f | 53 | #define REG_CONFIG 0x0C | 
| sakthipriya | 0:7b4c00e3912f | 54 | #define REG_VALRT 0x14 | 
| sakthipriya | 0:7b4c00e3912f | 55 | #define REG_CRATE 0x16 | 
| sakthipriya | 0:7b4c00e3912f | 56 | #define REG_VRESET_ID 0x18 | 
| sakthipriya | 0:7b4c00e3912f | 57 | #define REG_STATUS 0x1A | 
| sakthipriya | 0:7b4c00e3912f | 58 | #define REG_TABLE 0x40 | 
| sakthipriya | 0:7b4c00e3912f | 59 | #define REG_CMD 0xFE | 
| sakthipriya | 0:7b4c00e3912f | 60 | |
| sakthipriya | 0:7b4c00e3912f | 61 | //.............Power switching.......... | 
| sakthipriya | 0:7b4c00e3912f | 62 | #define TRXY_DR_EN PIN82 //torque rod driver enable | 
| sakthipriya | 0:7b4c00e3912f | 63 | #define TRZ_DR_EN PIN88 | 
| sakthipriya | 0:7b4c00e3912f | 64 | #define ENBL3V3A PIN33 | 
| sakthipriya | 3:07e15677a75c | 65 | //#define VBATT PIN20 | 
| sakthipriya | 0:7b4c00e3912f | 66 | #define BATT_HEAT PIN96 | 
| sakthipriya | 0:7b4c00e3912f | 67 | //#define BATT_HEAT_OUTPUT | 
| sakthipriya | 5:bb592f3185cc | 68 | extern void FCTN_CONVERT_FLOAT(float input, uint8_t* output); | 
| sakthipriya | 5:bb592f3185cc | 69 | |
| sakthipriya | 1:446a959e36ce | 70 | void FCTN_EPS_INIT(); | 
| azaddevarm | 28:5f0f2a3f3e8d | 71 | void FCTN_EPS_HANDLE_CDMS_FAULT(); | 
| azaddevarm | 28:5f0f2a3f3e8d | 72 | void FCTN_EPS_HANDLE_HW_FAULTS(); | 
| sakthipriya | 0:7b4c00e3912f | 73 | |
| sakthipriya | 0:7b4c00e3912f | 74 | void FCTN_EPS_POWERMODE(float soc) ; | 
| sakthipriya | 0:7b4c00e3912f | 75 | |
| sakthipriya | 3:07e15677a75c | 76 | void FCTN_HK_MAIN(); | 
| sakthipriya | 5:bb592f3185cc | 77 | void FCTN_APPEND_HKDATA(); | 
| sakthipriya | 5:bb592f3185cc | 78 | uint8_t quantiz(float start,float step,float x); | 
| sakthipriya | 0:7b4c00e3912f | 79 | |
| sakthipriya | 2:c823d84b4cb0 | 80 | void saveMin(); | 
| sakthipriya | 2:c823d84b4cb0 | 81 | void saveMax(); | 
| sakthipriya | 2:c823d84b4cb0 | 82 | void minMaxHkData(); | 
| sakthipriya | 2:c823d84b4cb0 | 83 | |
| sakthipriya | 0:7b4c00e3912f | 84 | void FCTN_BATTERYGAUGE_INIT(); | 
| azaddevarm | 30:22b338b027de | 85 | int FCTN_BATTERYGAUGE_MAIN(float*Battery_parameters, float); | 
| sakthipriya | 0:7b4c00e3912f | 86 | |
| sakthipriya | 1:446a959e36ce | 87 | // unsigned short read_soc(char , bool ); | 
| sakthipriya | 1:446a959e36ce | 88 | unsigned short read_soc(char,bool ack); | 
| sakthipriya | 0:7b4c00e3912f | 89 | unsigned short read(char reg); | 
| azaddevarm | 30:22b338b027de | 90 | int write(char reg, unsigned short data); | 
| sakthipriya | 0:7b4c00e3912f | 91 | void reset(); //not used | 
| sakthipriya | 0:7b4c00e3912f | 92 | void quickStart(); //not used | 
| sakthipriya | 0:7b4c00e3912f | 93 | void disable_sleep(); | 
| sakthipriya | 0:7b4c00e3912f | 94 | void disable_hibernate(); | 
| sakthipriya | 0:7b4c00e3912f | 95 | void socChangeAlertEnabled(bool); | 
| sakthipriya | 0:7b4c00e3912f | 96 | void compensation(char rcomp); | 
| sakthipriya | 0:7b4c00e3912f | 97 | void tempCompensation(float temp); | 
| sakthipriya | 0:7b4c00e3912f | 98 | void clearAlert(); | 
| sakthipriya | 0:7b4c00e3912f | 99 | void emptyAlertThreshold(char threshold); | 
| sakthipriya | 0:7b4c00e3912f | 100 | void vAlertMinMaxThreshold(); | 
| sakthipriya | 0:7b4c00e3912f | 101 | void vResetThresholSet(); | 
| sakthipriya | 0:7b4c00e3912f | 102 | void vResetAlertEnabled(bool enabled); | 
| sakthipriya | 0:7b4c00e3912f | 103 | char alertFlags(); | 
| sakthipriya | 0:7b4c00e3912f | 104 | void clearAlertFlags(); | 
| sakthipriya | 0:7b4c00e3912f | 105 | float vcell(); | 
| sakthipriya | 0:7b4c00e3912f | 106 | float soc(); | 
| sakthipriya | 0:7b4c00e3912f | 107 | float crate(); | 
| sakthipriya | 0:7b4c00e3912f | 108 | bool alerting(); | 
| sakthipriya | 0:7b4c00e3912f | 109 | void vResetThresholdSet(); | 
| sakthipriya | 0:7b4c00e3912f | 110 | |
| sakthipriya | 2:c823d84b4cb0 | 111 | void FCTN_BATTTEMP_INIT(); | 
| sakthipriya | 3:07e15677a75c | 112 | void FCTN_BATT_TEMP_SENSOR_MAIN(float*); | 
| sakthipriya | 2:c823d84b4cb0 | 113 | |
| sakthipriya | 0:7b4c00e3912f | 114 | typedef struct BAE_HK_actual{ | 
| sakthipriya | 0:7b4c00e3912f | 115 | float voltage_actual[16]; | 
| sakthipriya | 0:7b4c00e3912f | 116 | float current_actual[12]; | 
| sakthipriya | 0:7b4c00e3912f | 117 | float Batt_temp_actual[2]; | 
| sakthipriya | 0:7b4c00e3912f | 118 | float Batt_gauge_actual[4]; | 
| sakthipriya | 0:7b4c00e3912f | 119 | float BAE_temp_actual; | 
| sakthipriya | 4:39a4ae8c7ecd | 120 | char power_mode; | 
| sakthipriya | 5:bb592f3185cc | 121 | uint8_t faultPoll_status; | 
| sakthipriya | 5:bb592f3185cc | 122 | uint8_t faultIr_status; | 
| sakthipriya | 0:7b4c00e3912f | 123 | float AngularSpeed_actual[3]; | 
| sakthipriya | 0:7b4c00e3912f | 124 | float Bvalue_actual[3]; | 
| sakthipriya | 0:7b4c00e3912f | 125 | float Batt_voltage_actual; | 
| sakthipriya | 5:bb592f3185cc | 126 | |
| sakthipriya | 0:7b4c00e3912f | 127 | }BAE_HK_actual; | 
| sakthipriya | 0:7b4c00e3912f | 128 | |
| sakthipriya | 0:7b4c00e3912f | 129 | typedef struct BAE_HK_quant{ | 
| sakthipriya | 5:bb592f3185cc | 130 | uint8_t voltage_quant[16]; //power_mode + faults should be appended to sd card | 
| sakthipriya | 5:bb592f3185cc | 131 | uint8_t current_quant[12]; | 
| sakthipriya | 5:bb592f3185cc | 132 | uint8_t Batt_temp_quant[2]; | 
| sakthipriya | 5:bb592f3185cc | 133 | uint8_t Batt_gauge_quant[3]; // why only 3 here?? | 
| sakthipriya | 9:194afacf7449 | 134 | float Batt_gauge_alerts; //why is this float?? | 
| sakthipriya | 5:bb592f3185cc | 135 | uint8_t BAE_temp_quant; | 
| sakthipriya | 5:bb592f3185cc | 136 | float AngularSpeed_quant[3]; | 
| sakthipriya | 0:7b4c00e3912f | 137 | float Bvalue_quant[3]; | 
| sakthipriya | 5:bb592f3185cc | 138 | uint8_t Batt_voltage_quant; | 
| sakthipriya | 0:7b4c00e3912f | 139 | }BAE_HK_quant; | 
| sakthipriya | 0:7b4c00e3912f | 140 | |
| sakthipriya | 5:bb592f3185cc | 141 | typedef struct BAE_HK_arch{ //power_mode + faults should be appended to sd card | 
| sakthipriya | 0:7b4c00e3912f | 142 | |
| sakthipriya | 5:bb592f3185cc | 143 | uint8_t Batt_1_temp; //verify if uint8_t is right | 
| sakthipriya | 5:bb592f3185cc | 144 | uint8_t Batt_2_temp; | 
| sakthipriya | 5:bb592f3185cc | 145 | uint8_t EPS_PCB_temp; | 
| sakthipriya | 5:bb592f3185cc | 146 | uint8_t Batt_SOC; | 
| sakthipriya | 0:7b4c00e3912f | 147 | char power_mode; | 
| sakthipriya | 5:bb592f3185cc | 148 | uint8_t faultPoll_status; | 
| sakthipriya | 5:bb592f3185cc | 149 | uint8_t faultIr_status; | 
| sakthipriya | 5:bb592f3185cc | 150 | uint8_t Batt_voltage; | 
| sakthipriya | 5:bb592f3185cc | 151 | |
| sakthipriya | 0:7b4c00e3912f | 152 | //char Batt_voltage2; | 
| sakthipriya | 0:7b4c00e3912f | 153 | // char Digital power bus voltage; | 
| sakthipriya | 0:7b4c00e3912f | 154 | |
| sakthipriya | 0:7b4c00e3912f | 155 | |
| sakthipriya | 0:7b4c00e3912f | 156 | }BAE_HK_arch; | 
| sakthipriya | 0:7b4c00e3912f | 157 | |
| sakthipriya | 0:7b4c00e3912f | 158 | typedef struct BAE_HK_min_max{ | 
| sakthipriya | 5:bb592f3185cc | 159 | uint8_t voltage_max[16]; | 
| sakthipriya | 5:bb592f3185cc | 160 | uint8_t current_max[12]; | 
| sakthipriya | 5:bb592f3185cc | 161 | uint8_t Batt_temp_max[2]; | 
| sakthipriya | 5:bb592f3185cc | 162 | uint8_t Batt_gauge_max[3]; | 
| sakthipriya | 5:bb592f3185cc | 163 | uint8_t BAE_temp_max; | 
| sakthipriya | 5:bb592f3185cc | 164 | float AngularSpeed_max[3]; | 
| sakthipriya | 0:7b4c00e3912f | 165 | float Bvalue_max[3]; | 
| sakthipriya | 5:bb592f3185cc | 166 | uint8_t Batt_voltage_max; | 
| sakthipriya | 0:7b4c00e3912f | 167 | |
| sakthipriya | 5:bb592f3185cc | 168 | uint8_t voltage_min[16]; | 
| sakthipriya | 5:bb592f3185cc | 169 | uint8_t current_min[12]; | 
| sakthipriya | 5:bb592f3185cc | 170 | uint8_t Batt_temp_min[2]; | 
| sakthipriya | 5:bb592f3185cc | 171 | uint8_t Batt_gauge_min[3]; | 
| sakthipriya | 5:bb592f3185cc | 172 | uint8_t BAE_temp_min; | 
| sakthipriya | 5:bb592f3185cc | 173 | float AngularSpeed_min[3]; | 
| sakthipriya | 0:7b4c00e3912f | 174 | float Bvalue_min[3]; | 
| sakthipriya | 5:bb592f3185cc | 175 | uint8_t Batt_voltage_min; | 
| sakthipriya | 0:7b4c00e3912f | 176 | |
| sakthipriya | 0:7b4c00e3912f | 177 | }BAE_HK_min_max; | 
| sakthipriya | 0:7b4c00e3912f | 178 | 
