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