Cell voltages fork (SoC)
Dependencies: CUER_CAN CUER_DS1820 LTC2943 LTC6804 mbed PowerControl
Data_Types_BMU.h@66:c884fba9eaea, 2017-09-16 (annotated)
- Committer:
- DasSidG
- Date:
- Sat Sep 16 01:10:01 2017 +0000
- Revision:
- 66:c884fba9eaea
- Parent:
- 65:95f21910cf9d
Added more flags to the BMU status; Removed some unused functions, re-ordered some functions slightly; Tidied up some bits that were generating warnings
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lcockerton62 | 0:0a5f554d2a16 | 1 | #ifndef Data_Types_BMU_H |
lcockerton62 | 0:0a5f554d2a16 | 2 | #define Data_Types_BMU_H |
lcockerton62 | 0:0a5f554d2a16 | 3 | |
lcockerton62 | 0:0a5f554d2a16 | 4 | #include "CAN_Data.h" |
lcockerton62 | 0:0a5f554d2a16 | 5 | #include "CAN_IDs.h" |
lcockerton62 | 0:0a5f554d2a16 | 6 | #include "mbed.h" |
lcockerton62 | 0:0a5f554d2a16 | 7 | |
DasSidG | 12:fa9b1a459e47 | 8 | #define NO_CMUS 3 |
msharma97 | 9:82ba050a7e13 | 9 | #define NO_READINGS_PER_CMU 12 |
DasSidG | 37:fae62a2773a1 | 10 | #define NUM_MISSING_CELLS 3 //the number of cells short of 12 that are attached to the top CMU |
DasSidG | 52:63e84c6a9cfd | 11 | #define NO_TEMPERATURE_SENSORS 85 |
DasSidG | 38:b1f5bfe38d70 | 12 | #define TEMPERATURE_MEASUREMENT_FREQ 4 //how often we measure temperature relative to the normal loop (note this isn't actually a frequency) |
lcockerton62 | 0:0a5f554d2a16 | 13 | |
DasSidG | 54:f18d3af300ba | 14 | #define BATTERY_CAPACITY 42 //in Ah |
DasSidG | 54:f18d3af300ba | 15 | |
lcockerton62 | 0:0a5f554d2a16 | 16 | // CAN pins |
lcockerton62 | 0:0a5f554d2a16 | 17 | #define CAN_WRITE_PIN p29 |
lcockerton62 | 0:0a5f554d2a16 | 18 | #define CAN_READ_PIN p30 |
lcockerton62 | 0:0a5f554d2a16 | 19 | |
DasSidG | 62:c7bc95aa818a | 20 | #define BATTERY_FAN_CONTROL_PIN p13 |
DasSidG | 62:c7bc95aa818a | 21 | |
lcockerton62 | 1:51477fe4851b | 22 | // EEPROM addresses |
lcockerton62 | 1:51477fe4851b | 23 | #define START_WRITE_ADDRESS 0x0040 |
lcockerton62 | 30:d90895e96226 | 24 | /* When writing to the eeprom, the data will be written to memory twice to reduce the chance of errors. |
lcockerton62 | 30:d90895e96226 | 25 | The second set of data will be stored SECOND_ADDRESS_OFFSET after the first set of data. This should |
lcockerton62 | 30:d90895e96226 | 26 | be longer than than the number of bytes written to memory (otherwise data is overwritten) |
lcockerton62 | 30:d90895e96226 | 27 | but less than the page length */ |
lcockerton62 | 30:d90895e96226 | 28 | #define SECOND_ADDRESS_OFFSET 20 |
lcockerton62 | 1:51477fe4851b | 29 | #define MAX_WRITE_ADDRESS 0x7FC0 |
lcockerton62 | 1:51477fe4851b | 30 | |
DasSidG | 66:c884fba9eaea | 31 | // Limit values |
DasSidG | 66:c884fba9eaea | 32 | |
DasSidG | 66:c884fba9eaea | 33 | //Note: there are three categories of limiting values, for which the vehicle and driver response will differ: |
DasSidG | 66:c884fba9eaea | 34 | |
DasSidG | 66:c884fba9eaea | 35 | //Dangerous errors, which will trigger a car shutdown and tell the driver to leave immediately |
DasSidG | 66:c884fba9eaea | 36 | |
DasSidG | 66:c884fba9eaea | 37 | #define MAX_CELL_SAFE_VOLTAGE 4300 //mV |
DasSidG | 66:c884fba9eaea | 38 | #define MIN_CELL_SAFE_VOLTAGE 2300 //mV |
DasSidG | 66:c884fba9eaea | 39 | #define MAX_CELL_SAFE_TEMPERATURE 70 |
DasSidG | 66:c884fba9eaea | 40 | #define MAX_TEMPERATURE_DIFFERENCE 5 //this threshold also indicates a a dangerous situation i.e. suspected battery fire |
DasSidG | 66:c884fba9eaea | 41 | |
DasSidG | 66:c884fba9eaea | 42 | //Moderate errors, which will trigger a car shutdown, but the driver can remain in the vehicle |
DasSidG | 66:c884fba9eaea | 43 | |
DasSidG | 66:c884fba9eaea | 44 | #define MAX_CELL_VOLTAGE 4200 //mV |
DasSidG | 66:c884fba9eaea | 45 | #define MIN_CELL_VOLTAGE 2500 //mV |
DasSidG | 66:c884fba9eaea | 46 | #define MAX_CELL_DISCHARGE_TEMPERATURE 55 |
DasSidG | 66:c884fba9eaea | 47 | #define MIN_CELL_DISCHARGE_TEMPERATURE -20 |
DasSidG | 66:c884fba9eaea | 48 | #define OVERCURRENT_THRESHOLD 60000 //mA |
DasSidG | 52:63e84c6a9cfd | 49 | |
DasSidG | 66:c884fba9eaea | 50 | //Low priority errors, for which the vehicle can continue driving, but some functionality may be reduced (e.g. array may be disabled) |
DasSidG | 66:c884fba9eaea | 51 | |
DasSidG | 66:c884fba9eaea | 52 | #define MAX_CELL_CHARGE_VOLTAGE 4150 //mV |
DasSidG | 66:c884fba9eaea | 53 | #define MAX_CELL_CHARGE_TEMPERATURE 45 |
DasSidG | 66:c884fba9eaea | 54 | #define MIN_CELL_CHARGE_TEMPERATURE 10 |
lcockerton62 | 1:51477fe4851b | 55 | |
DasSidG | 66:c884fba9eaea | 56 | // Error states |
DasSidG | 66:c884fba9eaea | 57 | #define NONE 0x00000000 |
DasSidG | 66:c884fba9eaea | 58 | #define CELL_OVER_VOLTAGE 0x00000001 //Moderate error |
DasSidG | 66:c884fba9eaea | 59 | #define CELL_UNDER_VOLTAGE 0x00000002 //Moderate error |
DasSidG | 66:c884fba9eaea | 60 | #define CELL_OVER_CHARGE_TEMPERATURE 0x00000004 //Low priority error |
DasSidG | 66:c884fba9eaea | 61 | #define CELL_OVER_DISCHARGE_TEMPERATURE 0x00000008 //Moderate error |
DasSidG | 66:c884fba9eaea | 62 | #define CELL_UNDER_CHARGE_TEMPERATURE 0x00000010 //Low priority error |
DasSidG | 66:c884fba9eaea | 63 | #define CELL_UNDER_DISCHARGE_TEMPERATURE 0x00000020 //Moderate error |
DasSidG | 66:c884fba9eaea | 64 | #define MAX_TEMPERATURE_DIFFERENCE_ERROR 0x00000040 //Dangerous error |
DasSidG | 66:c884fba9eaea | 65 | #define OVERCURRENT_ERROR 0x00000080 //Moderate error |
DasSidG | 66:c884fba9eaea | 66 | #define CELL_OVER_CHARGE_VOLTAGE 0x00000100 //Low priority error |
DasSidG | 66:c884fba9eaea | 67 | #define CELL_DANGEROUSLY_OVER_VOLTAGE 0x00000200 //Dangerous error |
DasSidG | 66:c884fba9eaea | 68 | #define CELL_DANGEROUSLY_UNDER_VOLTAGE 0x00000400 //Dangerous error |
DasSidG | 66:c884fba9eaea | 69 | #define CELL_DANGEROUSLY_OVER_TEMPERATURE 0x00000800 //Dangerous error |
lcockerton62 | 1:51477fe4851b | 70 | |
maxv008 | 14:e0e88a009f4c | 71 | //CAN Buffer |
maxv008 | 14:e0e88a009f4c | 72 | #define CAN_BUFFER_SIZE 255 //Setting this to be quite large, should be equal to max # of ids expected to recieve |
maxv008 | 14:e0e88a009f4c | 73 | |
lcockerton62 | 1:51477fe4851b | 74 | // Delay |
DasSidG | 39:34be1b8f46be | 75 | #define LOOP_DELAY_S 1 // TODO is this delay the correct length? |
lcockerton62 | 1:51477fe4851b | 76 | |
lcockerton62 | 1:51477fe4851b | 77 | struct individual_temperature{ |
lcockerton62 | 1:51477fe4851b | 78 | // Structure that will store a temperature value and also an ID |
maxv008 | 14:e0e88a009f4c | 79 | char ROMID[8]; //ROM array for temperature sensor, subset of it is useful as ID |
maxv008 | 14:e0e88a009f4c | 80 | //ROMID 1-6 are the useful values for this case, ignore the rest |
lcockerton62 | 1:51477fe4851b | 81 | float measurement; |
maxv008 | 17:94dd9a0d3870 | 82 | long ID; //This field is only filled when CAN message is decoded, just a re-encoding of ROMID |
lcockerton62 | 1:51477fe4851b | 83 | }; |
lcockerton62 | 1:51477fe4851b | 84 | |
lcockerton62 | 1:51477fe4851b | 85 | struct CMU_voltage{ |
lcockerton62 | 1:51477fe4851b | 86 | // Structure that contains voltage information suitable for CAN bus |
lcockerton62 | 1:51477fe4851b | 87 | uint8_t ID; // CMU serial number |
lcockerton62 | 1:51477fe4851b | 88 | uint8_t CMU_number; // Number CMU's from 0-(N-1) (N is number of CMU's) it will aid CAN communications the ID and CMU number may be the same not sure yet |
msharma97 | 9:82ba050a7e13 | 89 | |
msharma97 | 9:82ba050a7e13 | 90 | //to be removed |
maxv008 | 17:94dd9a0d3870 | 91 | //uint16_t first_cell_voltages[4]; // Split the cell voltages up easier to send over CAN |
maxv008 | 17:94dd9a0d3870 | 92 | //uint16_t last_cell_voltages[4]; |
msharma97 | 9:82ba050a7e13 | 93 | |
msharma97 | 9:82ba050a7e13 | 94 | //this now |
maxv008 | 10:1079f8e52d65 | 95 | uint16_t voltages[NO_READINGS_PER_CMU]; |
lcockerton62 | 1:51477fe4851b | 96 | }; |
lcockerton62 | 1:51477fe4851b | 97 | |
lcockerton62 | 1:51477fe4851b | 98 | struct pack_voltage_extremes{ |
lcockerton62 | 1:51477fe4851b | 99 | // structure useful for CAN ID 0x6F8 |
lcockerton62 | 1:51477fe4851b | 100 | uint16_t voltage; // maximum or minimum voltage |
lcockerton62 | 1:51477fe4851b | 101 | uint8_t CMU_number; // CMU number of extreme voltage |
lcockerton62 | 1:51477fe4851b | 102 | uint8_t cell_number; // cell number of extreme voltage |
lcockerton62 | 1:51477fe4851b | 103 | }; |
lcockerton62 | 1:51477fe4851b | 104 | |
lcockerton62 | 1:51477fe4851b | 105 | struct pack_temperature_extremes{ |
maxv008 | 53:4277cdcff69b | 106 | float temperature; // maxiumum or minimum temperature |
DasSidG | 58:40d318825b0d | 107 | //uint8_t CMU_number; // CMU number of extreme voltage |
maxv008 | 23:a1af4439c1fc | 108 | char ROMID[8]; //Since we arent tracking CMU numbers uses this instead |
maxv008 | 53:4277cdcff69b | 109 | unsigned long ID; //Same as temperature measurement, makes it much easier to compare probes. |
lcockerton62 | 1:51477fe4851b | 110 | }; |
lcockerton62 | 1:51477fe4851b | 111 | |
lcockerton62 | 0:0a5f554d2a16 | 112 | struct BMU_data{ |
lcockerton62 | 0:0a5f554d2a16 | 113 | // Data for the CAN bus see Tritium Communications Protocol |
lcockerton62 | 0:0a5f554d2a16 | 114 | // Cell voltage |
lcockerton62 | 1:51477fe4851b | 115 | CMU_voltage cell_voltages[NO_CMUS]; // Store all voltage measurements in here |
lcockerton62 | 1:51477fe4851b | 116 | pack_voltage_extremes max_cell_voltage; |
lcockerton62 | 1:51477fe4851b | 117 | pack_voltage_extremes min_cell_voltage; |
lcockerton62 | 1:51477fe4851b | 118 | uint32_t battery_voltage; // 5.9 Tritium data sheet |
maxv008 | 31:888b2602aab2 | 119 | float battery_current; //changed to a float because conversion is unnatural and pointless |
lcockerton62 | 0:0a5f554d2a16 | 120 | |
lcockerton62 | 0:0a5f554d2a16 | 121 | // SOC |
lcockerton62 | 0:0a5f554d2a16 | 122 | float SOC; |
lcockerton62 | 0:0a5f554d2a16 | 123 | float percentage_SOC; |
lcockerton62 | 0:0a5f554d2a16 | 124 | |
lcockerton62 | 1:51477fe4851b | 125 | // Cell Temperature |
lcockerton62 | 1:51477fe4851b | 126 | individual_temperature temperature_measurements[NO_TEMPERATURE_SENSORS]; // Store all of the temperature measurements in here |
lcockerton62 | 1:51477fe4851b | 127 | pack_temperature_extremes max_cell_temp; |
lcockerton62 | 1:51477fe4851b | 128 | pack_temperature_extremes min_cell_temp; |
maxv008 | 45:c288d7cbdb4a | 129 | |
DasSidG | 62:c7bc95aa818a | 130 | individual_temperature ambient_temperature; |
DasSidG | 62:c7bc95aa818a | 131 | |
maxv008 | 45:c288d7cbdb4a | 132 | int32_t ivta_current; |
lcockerton62 | 0:0a5f554d2a16 | 133 | }; |
lcockerton62 | 0:0a5f554d2a16 | 134 | |
lcockerton62 | 0:0a5f554d2a16 | 135 | #endif |