foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
battery_system_cfg.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2023, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file battery_system_cfg.h
44  * @author foxBMS Team
45  * @date 2019-12-10 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup BATTERY_SYSTEM_CONFIGURATION
49  * @prefix BS
50  *
51  * @brief Configuration of the battery system (e.g., number of battery
52  * modules, battery cells, temperature sensors)
53  *
54  * @details This files contains basic macros of the battery system in order to
55  * derive needed inputs in other parts of the software. These macros
56  * are all depended on the hardware.
57  *
58  */
59 
60 #ifndef FOXBMS__BATTERY_SYSTEM_CFG_H_
61 #define FOXBMS__BATTERY_SYSTEM_CFG_H_
62 
63 /*========== Includes =======================================================*/
64 #include "general.h"
65 
66 #include "fassert.h"
67 
68 #include <stdbool.h>
69 #include <stdint.h>
70 
71 /*========== Macros and Definitions =========================================*/
72 
73 /** Symbolic identifiers for strings with precharge */
74 typedef enum {
78 
79 /** Symbolic identifiers for strings. */
80 typedef enum {
81  BS_STRING0 = 0u,
82  BS_STRING1 = 1u,
83  BS_STRING2 = 2u,
86 
87 /** Define if discharge current is seen as positive or negative */
88 #define BS_POSITIVE_DISCHARGE_CURRENT (true)
89 
90 /**
91  * @brief Number of parallel strings in the battery pack
92  * @details For details see
93  * <a href="../../../../introduction/naming-conventions.html" target="_blank">Naming Conventions</a>.
94  * Implementation detail: The number of parallel strings cannot exceed
95  * #GEN_REPEAT_MAXIMUM_REPETITIONS unless the implementation of the
96  * repetition macro is adapted.
97  * @ptype uint
98  */
99 #define BS_NR_OF_STRINGS (1u)
100 
101 /* safety check: due to implementation BS_NR_OF_STRINGS may not be larger than GEN_REPEAT_MAXIMUM_REPETITIONS */
102 #if (BS_NR_OF_STRINGS > GEN_REPEAT_MAXIMUM_REPETITIONS)
103 #error "Too large number of strings, please check implementation of GEN_REPEAT_U()."
104 #endif
105 
106 /**
107  * @brief number of modules in a string
108  * @details For details see
109  * <a href="../../../../introduction/naming-conventions.html" target="_blank">Naming Conventions</a>.
110  * @ptype uint
111  */
112 #define BS_NR_OF_MODULES_PER_STRING (1u)
113 
114 /**
115  * @brief number of cells per module
116  * @details number of cells per module, where parallel cells are
117  * counted as one cell block.
118  * For details see
119  * <a href="../../../../introduction/naming-conventions.html" target="_blank">Naming Conventions</a>.
120  * @ptype uint
121  */
122 #define BS_NR_OF_CELL_BLOCKS_PER_MODULE (18u)
123 
124 /**
125  * @brief number of parallel connected battery cells in a cell block
126  * @details For details see
127  * <a href="../../../../introduction/naming-conventions.html" target="_blank">Naming Conventions</a>.
128  * @ptype uint
129  */
130 #define BS_NR_OF_PARALLEL_CELLS_PER_CELL_BLOCK (1u)
131 
132 /** Value of the balancing resistors on the slave-board */
133 #define BS_BALANCING_RESISTANCE_ohm (100.0)
134 
135 /**
136  * @def BS_NR_OF_GPIOS_PER_MODULE
137  * @brief Defines the number of GPIOs
138  */
139 #define BS_NR_OF_GPIOS_PER_MODULE (10u)
140 
141 /**
142  * @def BS_NR_OF_GPAS_PER_MODULE
143  * @brief Defines the number of GPA inputs
144  */
145 #define BS_NR_OF_GPAS_PER_MODULE (2u)
146 
147 /**
148  * @brief number of temperature sensors per battery module
149  * @ptype int
150  */
151 #define BS_NR_OF_TEMP_SENSORS_PER_MODULE (8u)
152 
153 #if BS_NR_OF_TEMP_SENSORS_PER_MODULE > BS_NR_OF_GPIOS_PER_MODULE
154 #error "Number of temperature inputs cannot be higher than number of GPIOs"
155 #endif
156 
157 /** number of battery cells in the system */
158 #define BS_NR_OF_CELL_BLOCKS_PER_STRING (BS_NR_OF_MODULES_PER_STRING * BS_NR_OF_CELL_BLOCKS_PER_MODULE)
159 /** number of temperature sensors in a string */
160 #define BS_NR_OF_TEMP_SENSORS_PER_STRING (BS_NR_OF_MODULES_PER_STRING * BS_NR_OF_TEMP_SENSORS_PER_MODULE)
161 /** number of temperature sensors in the battery system */
162 #define BS_NR_OF_TEMP_SENSORS (BS_NR_OF_TEMP_SENSORS_PER_STRING * BS_NR_OF_STRINGS)
163 
164 /**
165  * @details - If set to false, foxBMS does not check for the presence of a
166  * current sensor.
167  * - If set to true, foxBMS checks for the presence of a current
168  * sensor. If sensor stops responding during runtime, an error is
169  * raised.
170  */
171 #define BS_CURRENT_SENSOR_PRESENT (false)
172 
173 #if BS_CURRENT_SENSOR_PRESENT == true
174 /**
175  * defines if the Isabellenhuette current sensor is used in cyclic or triggered mode
176  */
177 #define CURRENT_SENSOR_ISABELLENHUETTE_CYCLIC
178 /* #define CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED */
179 
180 /** Delay in ms after which it is considered the current measurement is not responding anymore. */
181 #define BS_CURRENT_MEASUREMENT_RESPONSE_TIMEOUT_ms (200u)
182 
183 /** Delay in ms after which it is considered the coulomb counting is not responding anymore. */
184 #define BS_COULOMB_COUNTING_MEASUREMENT_RESPONSE_TIMEOUT_ms (2000u)
185 
186 /** Delay in ms after which it is considered the energy counting is not responding anymore. */
187 #define BS_ENERGY_COUNTING_MEASUREMENT_RESPONSE_TIMEOUT_ms (2000u)
188 
189 #endif /* BS_CURRENT_SENSOR_PRESENT == true */
190 
191 /**
192  * @brief Maximum break current of main contactors.
193  * @details The contacts of the main contactors can be welded, when attempting
194  * to interrupt the current flow while a current higher than the
195  * maximum break current of the contactor is flowing.
196  *
197  * Thus, the contactors will not be opened if the floating current is
198  * above this value. The fuse should trigger to interrupt current
199  * flows above this value.
200  */
201 #define BS_MAIN_CONTACTORS_MAXIMUM_BREAK_CURRENT_mA (500000)
202 
203 /**
204  * @brief Maximum fuse trigger duration
205  * @details If the current is above #BS_MAIN_CONTACTORS_MAXIMUM_BREAK_CURRENT_mA,
206  * the BMS state machine will wait this time until the fuse triggers so
207  * that the current will be interrupted by the fuse and not the
208  * contactors. After this time, the BMS will nevertheless try to open
209  * the contactors.
210  */
211 #define BS_MAIN_FUSE_MAXIMUM_TRIGGER_DURATION_ms (30000u)
212 
213 /**
214  * @brief Maximum string current limit in mA that is used in the SOA module
215  * to check for string overcurrent
216 * @details When maximum safety limit (MSL) is violated, error state is
217  * requested and contactors will open.
218  */
219 #define BS_MAXIMUM_STRING_CURRENT_mA (10000u)
220 
221 /**
222  * @brief Maximum pack current limit in mA that is used in the SOA module
223  * to check for pack overcurrent
224  * @details When maximum safety limit (MSL) is violated, error state is
225  * requested and contactors will open.
226  */
227 #define BS_MAXIMUM_PACK_CURRENT_mA (10000u * BS_NR_OF_STRINGS)
228 
229 /**
230  * @brief Define if interlock feedback should be discarded or not
231  * @details True: interlock feedback will be discarded
232  * False: interlock feedback will evaluated
233  */
234 #define BS_IGNORE_INTERLOCK_FEEDBACK (false)
235 
236 /**
237  * @brief Defines whether CAN timing shall be evaluated or not
238  * @details - If set to false, foxBMS does not check CAN timing.
239  * - If set to true, foxBMS checks CAN timing. A valid request must
240  * come every 100ms, within the 95-150ms window.
241  */
242 #define BS_CHECK_CAN_TIMING (true)
243 
244 /**
245  * @brief Defines whether balancing shall be available or not
246  * @details - If set to true, balancing is deactivated completely.
247  * - If set to false, foxBMS checks when balancing must be done and
248  * activates it accordingly.
249  */
250 #define BS_BALANCING_DEFAULT_INACTIVE (true)
251 
252 /**
253  * @brief number of high voltage inputs measured by current sensors (like
254  * IVT-MOD)
255  * @ptype int
256  */
257 #define BS_NR_OF_VOLTAGES_FROM_CURRENT_SENSOR (3u)
258 
259 /** Number of contactors in addition to string contactors (e.g., PRECHARGE).*/
260 #define BS_NR_OF_CONTACTORS_OUTSIDE_STRINGS (1u)
261 
262 /** Total number of contactors in system:
263  * - Two contactors per string (string+ and string-)
264  * - One optional precharge contactor for each string */
265 #define BS_NR_OF_CONTACTORS ((2u * BS_NR_OF_STRINGS) + BS_NR_OF_CONTACTORS_OUTSIDE_STRINGS)
266 
267 /**
268  * @brief current threshold for determining rest state of battery. If absolute
269  * current is below this limit value the battery is resting.
270  */
271 #define BS_REST_CURRENT_mA (200)
272 
273 /**
274  * @brief Wait time in 10ms before battery system is at rest. Balancing for
275  * example only starts if battery system is at rest.
276  */
277 #define BS_RELAXATION_PERIOD_10ms (60000u)
278 
279 /**
280  * @brief current sensor threshold for 0 current in mA as the sensor has a
281  * jitter.
282  */
283 #define BS_CS_THRESHOLD_NO_CURRENT_mA (200u)
284 
285 /**
286  * @brief Maximum voltage drop over fuse.
287  * @details If the measured voltage difference between battery voltage
288  * voltage after fuse is larger than this value. It can be concluded,
289  * that the fuse has tripped. The voltage difference can be estimated
290  * by the maximum current and the resistance.
291  * For a Cooper Bussmann 1000A fuse the voltage drop can be estimated
292  * to: I_max = 1000A and P_loss = 206W
293  * -> voltage drop at 1000A roughly 206mV
294  * -> select 500mV because of measurement inaccuracies
295  */
296 #define BS_MAX_VOLTAGE_DROP_OVER_FUSE_mV (500)
297 
298 /**
299  * @brief TODO
300  * @details Set to true if fuse in NORMAL path should be checked. This can only
301  * be done if one dedicated HV measurement is used to monitor the
302  * voltage directly after the fuse. Then a voltage difference between
303  * V_bat and V_fuse indicates a tripped fuse.
304  *
305  * V_bat +------+ V_fuse Precharge/Main+ contactor
306  * -----+---| FUSE |-----+------------/ -----------------
307  * +------+
308  */
309 #define BS_CHECK_FUSE_PLACED_IN_NORMAL_PATH (true)
310 
311 /**
312  * @brief TODO
313  * @details Set to true if fuse in CHARGE path should be checked. This can only
314  * be done if one dedicated HV measurement is used to monitor
315  * voltage directly after the fuse. Then a voltage difference between
316  * V_bat and V_fuse indicates a tripped fuse.
317  *
318  * V_bat +------+ V_fuse Precharge/Charge+ contactor
319  * -----+---| FUSE |-----+------------/ -----------------
320  * +------+
321  */
322 #define BS_CHECK_FUSE_PLACED_IN_CHARGE_PATH (false)
323 
324 /**
325  * \defgroup open wire check configuration
326  * @details If open-wire check is performed, depending on the AFE
327  * implementation, cell voltages and temperatures are not updated
328  * and thus old values can be transmitted on the CAN bus. Check
329  * time is dependent on module configuration and external
330  * capacitance. Activate open-wire check with care! See the AFE
331  * implementation for details.
332  * @{
333  */
334 /** enable open-wire checks during standby */
335 #define BS_STANDBY_PERIODIC_OPEN_WIRE_CHECK (false)
336 
337 /** Periodic open-wire check time in STANDBY state in ms */
338 #define BS_STANDBY_OPEN_WIRE_PERIOD_ms (600000)
339 
340 /** open-wire check in normal mode (set to true or false) */
341 #define BS_NORMAL_PERIODIC_OPEN_WIRE_CHECK (false)
342 
343 /** Periodic open-wire check time in NORMAL state in ms */
344 #define BS_NORMAL_OPEN_WIRE_PERIOD_ms (600000)
345 
346 /** open-wire check in charge mode (set to true or false) */
347 #define BS_CHARGE_PERIODIC_OPEN_WIRE_CHECK (false)
348 
349 /** Periodic open-wire check time in CHARGE state in ms */
350 #define BS_CHARGE_OPEN_WIRE_PERIOD_ms (600000)
351 
352 /** Periodic open-wire check time in ERROR state in ms */
353 #define BS_ERROR_OPEN_WIRE_PERIOD_ms (30000)
354 /**@}*/
355 
356 FAS_STATIC_ASSERT((BS_NR_OF_STRINGS <= (uint8_t)UINT8_MAX), "This code assumes BS_NR_OF_STRINGS fits into uint8_t");
357 
358 /*========== Extern Constant and Variable Declarations ======================*/
359 /** Defines whether a string can be used to precharge or not */
361 
362 /*========== Extern Function Prototypes =====================================*/
363 
364 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
365 #ifdef UNITY_UNIT_TEST
366 #endif
367 
368 #endif /* FOXBMS__BATTERY_SYSTEM_CFG_H_ */
FAS_STATIC_ASSERT((BS_NR_OF_STRINGS<=(uint8_t) UINT8_MAX), "This code assumes BS_NR_OF_STRINGS fits into uint8_t")
BS_STRING_PRECHARGE_PRESENT_e bs_stringsWithPrecharge[BS_NR_OF_STRINGS]
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
BS_STRING_PRECHARGE_PRESENT_e
@ BS_STRING_WITHOUT_PRECHARGE
@ BS_STRING_WITH_PRECHARGE
BS_STRING_ID_e
@ BS_STRING2
@ BS_STRING1
@ BS_STRING0
@ BS_STRING_MAX
Assert macro implementation.
General macros and definitions for the whole platform.