Skip to content

Commit 3821382

Browse files
committed
Update BMSConfig.h for LPC1768 and add documentation
1 parent a3f433b commit 3821382

File tree

2 files changed

+134
-26
lines changed

2 files changed

+134
-26
lines changed

bms/src/BmsConfig.h

Lines changed: 129 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,163 @@
22

33
#include "mbed.h"
44

5+
6+
// Global pointer to serial object
7+
//
8+
// This allows for all files to access the serial output
59
extern Serial* serial;
610

7-
// TODO: So there's an issue here.
811

12+
//
913
// 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
1020

11-
#define BMS_BANK_COUNT 1
21+
// Number of cell voltage readings per LTC6811
22+
#ifndef BMS_BANK_CELL_COUNT
1223
#define BMS_BANK_CELL_COUNT 7
24+
#endif
25+
26+
// Number of cell temperature readings per LTC6811
27+
#ifndef BMS_BANK_TEMP_COUNT
1328
#define BMS_BANK_TEMP_COUNT BMS_BANK_CELL_COUNT
29+
#endif
1430

31+
// Upper threshold when fault will be thrown for cell temperature
32+
//
33+
// Units: degrees celcius
34+
#ifndef BMS_FAULT_TEMP_THRESHOLD_HIGH
1535
#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
1642
#define BMS_FAULT_TEMP_THRESHOLD_LOW 0
43+
#endif
1744

18-
// Threshold when fault will be thrown for cell voltage
45+
// Upper threshold when fault will be thrown for cell voltage
1946
//
2047
// Units: millivolts
48+
#ifndef BMS_FAULT_VOLTAGE_THRESHOLD_HIGH
2149
#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
2256
#define BMS_FAULT_VOLTAGE_THRESHOLD_LOW 2550
57+
#endif
2358

2459
// Threshold when cells will be discharged when discharging is enabled.
2560
//
2661
// Units: millivolts
62+
#ifndef BMS_DISCHARGE_THRESHOLD
2763
#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};
2871

72+
73+
//
2974
// 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
3083

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
3897

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+
//
39121
// 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
40133

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
44138

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
49143

144+
145+
//
50146
// 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+
//
54148

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
58164

59-
// BMS Cell lookup
60-
const int BMS_CELL_MAP[12] = {0, 1, 2, 3, -1, -1, 4, 5, 6, -1, -1, -1};

bms/src/Main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ int main() {
5959

6060
ThisThread::sleep_for(1000);
6161

62-
SPI* spiDriver = new SPI(p5,p6,p7,p8,use_gpio_ssel);
62+
SPI* spiDriver = new SPI(BMS_PIN_SPI_MOSI,
63+
BMS_PIN_SPI_MISO,
64+
BMS_PIN_SPI_SCLK,
65+
BMS_PIN_SPI_SSEL,
66+
use_gpio_ssel);
6367
spiDriver->format(8, 0);
6468
LTC6811Bus ltcBus = LTC6811Bus(spiDriver);
6569

0 commit comments

Comments
 (0)