|
2 | 2 |
|
3 | 3 | #include "mbed.h"
|
4 | 4 |
|
| 5 | + |
| 6 | +// Global pointer to serial object |
| 7 | +// |
| 8 | +// This allows for all files to access the serial output |
5 | 9 | extern Serial* serial;
|
6 | 10 |
|
7 |
| -// TODO: So there's an issue here. |
8 | 11 |
|
| 12 | +// |
9 | 13 | // BMS Master Configuration
|
| 14 | +// |
| 15 | + |
| 16 | +// Number of LTC6811 battery banks to communicate with |
| 17 | +#ifndef BMS_BANK_COUNT |
| 18 | +#define BMS_BANK_COUNT 4 |
| 19 | +#endif |
10 | 20 |
|
11 |
| -#define BMS_BANK_COUNT 1 |
| 21 | +// Number of cell voltage readings per LTC6811 |
| 22 | +#ifndef BMS_BANK_CELL_COUNT |
12 | 23 | #define BMS_BANK_CELL_COUNT 7
|
| 24 | +#endif |
| 25 | + |
| 26 | +// Number of cell temperature readings per LTC6811 |
| 27 | +#ifndef BMS_BANK_TEMP_COUNT |
13 | 28 | #define BMS_BANK_TEMP_COUNT BMS_BANK_CELL_COUNT
|
| 29 | +#endif |
14 | 30 |
|
| 31 | +// Upper threshold when fault will be thrown for cell temperature |
| 32 | +// |
| 33 | +// Units: degrees celcius |
| 34 | +#ifndef BMS_FAULT_TEMP_THRESHOLD_HIGH |
15 | 35 | #define BMS_FAULT_TEMP_THRESHOLD_HIGH 55
|
| 36 | +#endif |
| 37 | + |
| 38 | +// Upper threshold when fault will be thrown for cell temperature |
| 39 | +// |
| 40 | +// Units: degrees celcius |
| 41 | +#ifndef BMS_FAULT_TEMP_THRESHOLD_LOW |
16 | 42 | #define BMS_FAULT_TEMP_THRESHOLD_LOW 0
|
| 43 | +#endif |
17 | 44 |
|
18 |
| -// Threshold when fault will be thrown for cell voltage |
| 45 | +// Upper threshold when fault will be thrown for cell voltage |
19 | 46 | //
|
20 | 47 | // Units: millivolts
|
| 48 | +#ifndef BMS_FAULT_VOLTAGE_THRESHOLD_HIGH |
21 | 49 | #define BMS_FAULT_VOLTAGE_THRESHOLD_HIGH 4200
|
| 50 | +#endif |
| 51 | + |
| 52 | +// Lower threshold when fault will be thrown for cell voltage |
| 53 | +// |
| 54 | +// Units: millivolts |
| 55 | +#ifndef BMS_FAULT_VOLTAGE_THRESHOLD_LOW |
22 | 56 | #define BMS_FAULT_VOLTAGE_THRESHOLD_LOW 2550
|
| 57 | +#endif |
23 | 58 |
|
24 | 59 | // Threshold when cells will be discharged when discharging is enabled.
|
25 | 60 | //
|
26 | 61 | // Units: millivolts
|
| 62 | +#ifndef BMS_DISCHARGE_THRESHOLD |
27 | 63 | #define BMS_DISCHARGE_THRESHOLD 15
|
| 64 | +#endif |
| 65 | + |
| 66 | +// BMS Cell lookup |
| 67 | +// |
| 68 | +// This defines the mapping from LTC6811 pins to cell indicies. |
| 69 | +// Values of -1 indicate the pin is not connected. |
| 70 | +const int BMS_CELL_MAP[12] = {0, 1, 2, 3, -1, -1, 4, 5, 6, -1, -1, -1}; |
28 | 71 |
|
| 72 | + |
| 73 | +// |
29 | 74 | // IO Configuration
|
| 75 | +// |
| 76 | + |
| 77 | +// BMS fault line |
| 78 | +// |
| 79 | +// To be set high and held high when software enters fault state |
| 80 | +#ifndef BMS_PIN_BMS_FLT |
| 81 | +#define BMS_PIN_BMS_FLT NC |
| 82 | +#endif |
30 | 83 |
|
31 |
| -/* |
32 |
| -#define LINE_BMS_FLT PAL_LINE(GPIOB, 0) |
33 |
| -#define LINE_BMS_FLT_LAT PAL_LINE(GPIOF, 1) |
34 |
| -#define LINE_IMD_STATUS PAL_LINE(GPIOF, 0) |
35 |
| -#define LINE_IMD_FLT_LAT PAL_LINE(GPIOA, 8) |
36 |
| -#define LINE_CHARGER_CONTROL PAL_LINE(GPIOB, 1) |
37 |
| -#define LINE_SIG_CURRENT LINE_ARD_A0 // => (GPIOA, 0) |
| 84 | +// BMS fault latch |
| 85 | +// |
| 86 | +// Readback from BMS fault relay to be broadcasted on CAN bus |
| 87 | +#ifndef BMS_PIN_BMS_FLT_LAT |
| 88 | +#define BMS_PIN_BMS_FLT_LAT NC |
| 89 | +#endif |
| 90 | + |
| 91 | +// IMD status input |
| 92 | +// |
| 93 | +// Reads PWM output from IMD board |
| 94 | +#ifndef BMS_PIN_IMD_STATUS |
| 95 | +#define BMS_PIN_IMD_STATUS NC |
| 96 | +#endif |
38 | 97 |
|
| 98 | +// IMD fault latch |
| 99 | +// |
| 100 | +// Readback from IMD fault relay to be broadcasted on CAN bus |
| 101 | +#ifndef BMS_PIN_IMD_FLT_LAT |
| 102 | +#define BMS_PIN_IMD_FLT_LAT NC |
| 103 | +#endif |
| 104 | + |
| 105 | +// Charger output |
| 106 | +// |
| 107 | +// To be pulled high to enable charger |
| 108 | +#ifndef BMS_PIN_CHARGER_CONTROL |
| 109 | +#define BMS_PIN_CHARGER_CONTROL NC |
| 110 | +#endif |
| 111 | + |
| 112 | +// Current input |
| 113 | +// |
| 114 | +// Input from analog current sensor |
| 115 | +#ifndef BMS_PIN_SIG_CURRENT |
| 116 | +#define BMS_PIN_SIG_CURRENT NC |
| 117 | +#endif |
| 118 | + |
| 119 | + |
| 120 | +// |
39 | 121 | // SPI Configuration
|
| 122 | +// |
| 123 | + |
| 124 | +// SPI master out slave in |
| 125 | +#ifndef BMS_PIN_SPI_MOSI |
| 126 | +#define BMS_PIN_SPI_MOSI p5 |
| 127 | +#endif |
| 128 | + |
| 129 | +// SPI master in slave out |
| 130 | +#ifndef BMS_PIN_SPI_MISO |
| 131 | +#define BMS_PIN_SPI_MISO p6 |
| 132 | +#endif |
40 | 133 |
|
41 |
| -#define BMS_SPI_DRIVER SPID1 |
42 |
| -#define BMS_SPI_CR1 (SPI_CR1_BR_2 | SPI_CR1_BR_1) // Prescalar of 128 |
43 |
| -#define BMS_SPI_CR2 (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0) // 8 bits data |
| 134 | +// SPI clock |
| 135 | +#ifndef BMS_PIN_SPI_SCLK |
| 136 | +#define BMS_PIN_SPI_SCLK p7 |
| 137 | +#endif |
44 | 138 |
|
45 |
| -#define LINE_SPI_MOSI PAL_LINE(GPIOA, 7) |
46 |
| -#define LINE_SPI_MISO PAL_LINE(GPIOA, 6) |
47 |
| -#define LINE_SPI_SCLK PAL_LINE(GPIOA, 5) |
48 |
| -#define LINE_SPI_SSEL PAL_LINE(GPIOA, 4) |
| 139 | +// SPI chip select |
| 140 | +#ifndef BMS_PIN_SPI_SSEL |
| 141 | +#define BMS_PIN_SPI_SSEL p8 |
| 142 | +#endif |
49 | 143 |
|
| 144 | + |
| 145 | +// |
50 | 146 | // CAN Configuration
|
51 |
| -#define BMS_CAN_DRIVER CAND1 |
52 |
| -#define BMS_CAN_CR1 CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP |
53 |
| -#define BMS_CAN_CR2 CAN_BTR_SJW(1) | CAN_BTR_TS1(5) | CAN_BTR_TS2(0) | CAN_BTR_BRP(2) |
| 147 | +// |
54 | 148 |
|
55 |
| -#define LINE_CAN_TX PAL_LINE(GPIOA, 12) |
56 |
| -#define LINE_CAN_RX PAL_LINE(GPIOA, 11) |
57 |
| -*/ |
| 149 | +// CAN TX pin to transceiver |
| 150 | +#ifndef BMS_PIN_CAN_TX |
| 151 | +#define BMS_PIN_CAN_TX p29 |
| 152 | +#endif |
| 153 | + |
| 154 | +// CAN RX pin from transceiver |
| 155 | +#ifndef BMS_PIN_CAN_RX |
| 156 | +#define BMS_PIN_CAN_RX p30 |
| 157 | +#endif |
| 158 | + |
| 159 | +// CAN frequency to used |
| 160 | +// default: 500k |
| 161 | +#ifndef BMS_CAN_FREQUENCY |
| 162 | +#define BMS_CAN_FREQUENCY 500000 |
| 163 | +#endif |
58 | 164 |
|
59 |
| -// BMS Cell lookup |
60 |
| -const int BMS_CELL_MAP[12] = {0, 1, 2, 3, -1, -1, 4, 5, 6, -1, -1, -1}; |
|
0 commit comments