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:
Fri Jun 23 17:41:17 2017 +0000
Revision:
12:fa9b1a459e47
Parent:
10:1079f8e52d65
Child:
14:e0e88a009f4c
now works with 33 cells;

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
lcockerton62 1:51477fe4851b 41 // Delay
lcockerton62 1:51477fe4851b 42 #define LOOP_DELAY_S 0.1 // TODO is this delay the correct length?
lcockerton62 1:51477fe4851b 43
lcockerton62 1:51477fe4851b 44 struct individual_temperature{
lcockerton62 1:51477fe4851b 45 // Structure that will store a temperature value and also an ID
lcockerton62 1:51477fe4851b 46 uint8_t ID; // CMU number
lcockerton62 1:51477fe4851b 47 float measurement;
lcockerton62 1:51477fe4851b 48 };
lcockerton62 1:51477fe4851b 49
lcockerton62 1:51477fe4851b 50 struct CMU_voltage{
lcockerton62 1:51477fe4851b 51 // Structure that contains voltage information suitable for CAN bus
lcockerton62 1:51477fe4851b 52 uint8_t ID; // CMU serial number
lcockerton62 1:51477fe4851b 53 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 54
msharma97 9:82ba050a7e13 55 //to be removed
lcockerton62 1:51477fe4851b 56 uint16_t first_cell_voltages[4]; // Split the cell voltages up easier to send over CAN
msharma97 9:82ba050a7e13 57 uint16_t last_cell_voltages[4];
msharma97 9:82ba050a7e13 58
msharma97 9:82ba050a7e13 59 //this now
maxv008 10:1079f8e52d65 60 uint16_t voltages[NO_READINGS_PER_CMU];
lcockerton62 1:51477fe4851b 61 };
lcockerton62 1:51477fe4851b 62
lcockerton62 1:51477fe4851b 63 struct pack_voltage_extremes{
lcockerton62 1:51477fe4851b 64 // structure useful for CAN ID 0x6F8
lcockerton62 1:51477fe4851b 65 uint16_t voltage; // maximum or minimum voltage
lcockerton62 1:51477fe4851b 66 uint8_t CMU_number; // CMU number of extreme voltage
lcockerton62 1:51477fe4851b 67 uint8_t cell_number; // cell number of extreme voltage
lcockerton62 1:51477fe4851b 68 };
lcockerton62 1:51477fe4851b 69
lcockerton62 1:51477fe4851b 70 struct pack_temperature_extremes{
lcockerton62 1:51477fe4851b 71 uint16_t temperature; // maxiumum or minimum temperature
lcockerton62 1:51477fe4851b 72 uint8_t CMU_number; // CMU number of extreme voltage
lcockerton62 1:51477fe4851b 73 };
lcockerton62 1:51477fe4851b 74
lcockerton62 0:0a5f554d2a16 75 struct BMU_data{
lcockerton62 0:0a5f554d2a16 76 // Data for the CAN bus see Tritium Communications Protocol
lcockerton62 0:0a5f554d2a16 77 // Cell voltage
lcockerton62 1:51477fe4851b 78 CMU_voltage cell_voltages[NO_CMUS]; // Store all voltage measurements in here
lcockerton62 1:51477fe4851b 79 pack_voltage_extremes max_cell_voltage;
lcockerton62 1:51477fe4851b 80 pack_voltage_extremes min_cell_voltage;
lcockerton62 1:51477fe4851b 81 uint32_t battery_voltage; // 5.9 Tritium data sheet
lcockerton62 1:51477fe4851b 82 uint32_t battery_current;
lcockerton62 0:0a5f554d2a16 83
lcockerton62 0:0a5f554d2a16 84 // SOC
lcockerton62 0:0a5f554d2a16 85 float SOC;
lcockerton62 0:0a5f554d2a16 86 float percentage_SOC;
lcockerton62 0:0a5f554d2a16 87
lcockerton62 1:51477fe4851b 88 // Cell Temperature
lcockerton62 1:51477fe4851b 89 individual_temperature temperature_measurements[NO_TEMPERATURE_SENSORS]; // Store all of the temperature measurements in here
lcockerton62 1:51477fe4851b 90 pack_temperature_extremes max_cell_temp;
lcockerton62 1:51477fe4851b 91 pack_temperature_extremes min_cell_temp;
lcockerton62 0:0a5f554d2a16 92 };
lcockerton62 0:0a5f554d2a16 93
lcockerton62 1:51477fe4851b 94
lcockerton62 0:0a5f554d2a16 95 // @TODO are both the battery status and extended status used or just one of them
lcockerton62 0:0a5f554d2a16 96 enum BMU_CAN_flags{
lcockerton62 0:0a5f554d2a16 97 // Think this is used for legacy software
lcockerton62 0:0a5f554d2a16 98 };
lcockerton62 0:0a5f554d2a16 99
lcockerton62 0:0a5f554d2a16 100 #endif