Has base BMU code but sends dummy temperature and voltage readings to test CAN

Dependencies:   CUER_CAN DS1820 LTC2943 LTC6804 mbed

Fork of BMS_BMUCore_Max by CUER

Committer:
DasSidG
Date:
Sun Jul 02 11:25:37 2017 +0000
Revision:
15:e901aff1f5b3
Parent:
14:e0e88a009f4c
Added temperature probe initialization

Who changed what in which revision?

UserRevisionLine numberNew 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
lcockerton62 1:51477fe4851b 10 #define NO_TEMPERATURE_SENSORS 50
lcockerton62 0:0a5f554d2a16 11
lcockerton62 0:0a5f554d2a16 12 // CAN pins
lcockerton62 0:0a5f554d2a16 13 #define CAN_WRITE_PIN p29
lcockerton62 0:0a5f554d2a16 14 #define CAN_READ_PIN p30
lcockerton62 0:0a5f554d2a16 15
lcockerton62 1:51477fe4851b 16 // EEPROM addresses
lcockerton62 1:51477fe4851b 17 #define START_WRITE_ADDRESS 0x0040
lcockerton62 1:51477fe4851b 18 #define MAX_WRITE_ADDRESS 0x7FC0
lcockerton62 1:51477fe4851b 19
lcockerton62 1:51477fe4851b 20 // Error states
lcockerton62 1:51477fe4851b 21 #define NONE = 0x00000000
lcockerton62 1:51477fe4851b 22 #define CELL_OVER_VOLTAGE 0x00000001
lcockerton62 1:51477fe4851b 23 #define CELL_UNDER_VOLTAGE 0x00000002
lcockerton62 1:51477fe4851b 24 #define CELL_OVER_TEMPERATURE 0x00000004
lcockerton62 1:51477fe4851b 25 #define MEASUREMENT_UNTRUSTED 0x00000008
lcockerton62 1:51477fe4851b 26 #define CMU_COMMUNICATION_TIMEOUT 0x00000010
lcockerton62 1:51477fe4851b 27 #define VEHICLE_COMMUNICATIONS_TIMEOUT 0x00000020
lcockerton62 1:51477fe4851b 28 #define BMU_SETUP_MODE 0x00000040
lcockerton62 1:51477fe4851b 29 #define CMU_CAN_POWER_STATUS 0x00000080
lcockerton62 1:51477fe4851b 30 #define PACK_ISOLATION_TEST_FAILURE 0x00000100
lcockerton62 1:51477fe4851b 31 #define SOC_MEASUREMENT_NOT_VALID = 0x00000200
lcockerton62 1:51477fe4851b 32 #define CAN_12V_LOW = 0x00000400
lcockerton62 1:51477fe4851b 33 #define CONTACTOR_NOT_ENGAGED = 0x00000800
lcockerton62 1:51477fe4851b 34 #define CMU_EXTRA_CELL = 0x00001000
lcockerton62 1:51477fe4851b 35
lcockerton62 1:51477fe4851b 36 // Max values
lcockerton62 1:51477fe4851b 37 #define MAX_CELL_VOLTAGE 1
lcockerton62 1:51477fe4851b 38 #define MIN_CELL_VOLTAGE 1
lcockerton62 1:51477fe4851b 39 #define MAX_CELL_TEMPERATURE 1
lcockerton62 1:51477fe4851b 40
maxv008 14:e0e88a009f4c 41 //CAN Buffer
maxv008 14:e0e88a009f4c 42 #define CAN_BUFFER_SIZE 255 //Setting this to be quite large, should be equal to max # of ids expected to recieve
maxv008 14:e0e88a009f4c 43
lcockerton62 1:51477fe4851b 44 // Delay
lcockerton62 1:51477fe4851b 45 #define LOOP_DELAY_S 0.1 // TODO is this delay the correct length?
lcockerton62 1:51477fe4851b 46
lcockerton62 1:51477fe4851b 47 struct individual_temperature{
lcockerton62 1:51477fe4851b 48 // Structure that will store a temperature value and also an ID
maxv008 14:e0e88a009f4c 49 char ROMID[8]; //ROM array for temperature sensor, subset of it is useful as ID
maxv008 14:e0e88a009f4c 50 //ROMID 1-6 are the useful values for this case, ignore the rest
lcockerton62 1:51477fe4851b 51 float measurement;
lcockerton62 1:51477fe4851b 52 };
lcockerton62 1:51477fe4851b 53
lcockerton62 1:51477fe4851b 54 struct CMU_voltage{
lcockerton62 1:51477fe4851b 55 // Structure that contains voltage information suitable for CAN bus
lcockerton62 1:51477fe4851b 56 uint8_t ID; // CMU serial number
lcockerton62 1:51477fe4851b 57 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 58
msharma97 9:82ba050a7e13 59 //to be removed
lcockerton62 1:51477fe4851b 60 uint16_t first_cell_voltages[4]; // Split the cell voltages up easier to send over CAN
msharma97 9:82ba050a7e13 61 uint16_t last_cell_voltages[4];
msharma97 9:82ba050a7e13 62
msharma97 9:82ba050a7e13 63 //this now
maxv008 10:1079f8e52d65 64 uint16_t voltages[NO_READINGS_PER_CMU];
lcockerton62 1:51477fe4851b 65 };
lcockerton62 1:51477fe4851b 66
lcockerton62 1:51477fe4851b 67 struct pack_voltage_extremes{
lcockerton62 1:51477fe4851b 68 // structure useful for CAN ID 0x6F8
lcockerton62 1:51477fe4851b 69 uint16_t voltage; // maximum or minimum voltage
lcockerton62 1:51477fe4851b 70 uint8_t CMU_number; // CMU number of extreme voltage
lcockerton62 1:51477fe4851b 71 uint8_t cell_number; // cell number of extreme voltage
lcockerton62 1:51477fe4851b 72 };
lcockerton62 1:51477fe4851b 73
lcockerton62 1:51477fe4851b 74 struct pack_temperature_extremes{
lcockerton62 1:51477fe4851b 75 uint16_t temperature; // maxiumum or minimum temperature
lcockerton62 1:51477fe4851b 76 uint8_t CMU_number; // CMU number of extreme voltage
lcockerton62 1:51477fe4851b 77 };
lcockerton62 1:51477fe4851b 78
lcockerton62 0:0a5f554d2a16 79 struct BMU_data{
lcockerton62 0:0a5f554d2a16 80 // Data for the CAN bus see Tritium Communications Protocol
lcockerton62 0:0a5f554d2a16 81 // Cell voltage
lcockerton62 1:51477fe4851b 82 CMU_voltage cell_voltages[NO_CMUS]; // Store all voltage measurements in here
lcockerton62 1:51477fe4851b 83 pack_voltage_extremes max_cell_voltage;
lcockerton62 1:51477fe4851b 84 pack_voltage_extremes min_cell_voltage;
lcockerton62 1:51477fe4851b 85 uint32_t battery_voltage; // 5.9 Tritium data sheet
lcockerton62 1:51477fe4851b 86 uint32_t battery_current;
lcockerton62 0:0a5f554d2a16 87
lcockerton62 0:0a5f554d2a16 88 // SOC
lcockerton62 0:0a5f554d2a16 89 float SOC;
lcockerton62 0:0a5f554d2a16 90 float percentage_SOC;
lcockerton62 0:0a5f554d2a16 91
lcockerton62 1:51477fe4851b 92 // Cell Temperature
lcockerton62 1:51477fe4851b 93 individual_temperature temperature_measurements[NO_TEMPERATURE_SENSORS]; // Store all of the temperature measurements in here
lcockerton62 1:51477fe4851b 94 pack_temperature_extremes max_cell_temp;
lcockerton62 1:51477fe4851b 95 pack_temperature_extremes min_cell_temp;
lcockerton62 0:0a5f554d2a16 96 };
lcockerton62 0:0a5f554d2a16 97
lcockerton62 1:51477fe4851b 98
lcockerton62 0:0a5f554d2a16 99 // @TODO are both the battery status and extended status used or just one of them
lcockerton62 0:0a5f554d2a16 100 enum BMU_CAN_flags{
lcockerton62 0:0a5f554d2a16 101 // Think this is used for legacy software
lcockerton62 0:0a5f554d2a16 102 };
lcockerton62 0:0a5f554d2a16 103
lcockerton62 0:0a5f554d2a16 104 #endif