foxBMS - Unit Tests  1.4.1
The foxBMS Unit Tests API Documentation
battery_system_cfg.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2022, 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 2022-10-27 (date of last update)
47  * @version v1.4.1
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 /*========== Macros and Definitions =========================================*/
67 
68 /** Symbolic identifiers for strings with precharge */
69 typedef enum {
73 
74 /** Symbolic identifiers for strings. */
75 typedef enum {
76  BS_STRING0 = 0u,
77  BS_STRING1 = 1u,
78  BS_STRING2 = 2u,
81 
82 /** Define if discharge current is seen as positive or negative */
83 #define POSITIVE_DISCHARGE_CURRENT (true)
84 
85 /** */
86 /**
87  * @ingroup CONFIG_BATTERYSYSTEM
88  * @brief Number of parallel strings in the battery pack
89  * @details For details see
90  * <a href="../../../../introduction/naming-conventions.html" target="_blank">Naming Conventions</a>.
91  * Implementation detail: The number of parallel strings cannot exceed
92  * #GEN_REPEAT_MAXIMUM_REPETITIONS unless the implementation of the
93  * repetition macro is adapted.
94  * @ptype uint
95  */
96 #define BS_NR_OF_STRINGS (1u)
97 
98 /* safety check: due to implementation BS_NR_OF_STRINGS may not be larger than GEN_REPEAT_MAXIMUM_REPETITIONS */
99 #if (BS_NR_OF_STRINGS > GEN_REPEAT_MAXIMUM_REPETITIONS)
100 #error "Too large number of strings, please check implementation of GEN_REPEAT_U()."
101 #endif
102 
103 /**
104  * @ingroup CONFIG_BATTERYSYSTEM
105  * @brief number of modules in a string
106  * @details For details see
107  * <a href="../../../../introduction/naming-conventions.html" target="_blank">Naming Conventions</a>.
108  * @ptype uint
109  */
110 #define BS_NR_OF_MODULES_PER_STRING (1u)
111 
112 /**
113  * @ingroup CONFIG_BATTERYSYSTEM
114  * @brief number of cells per module
115  * @details number of cells per module, where parallel cells are
116  * counted as one cell block.
117  * For details see
118  * <a href="../../../../introduction/naming-conventions.html" target="_blank">Naming Conventions</a>.
119  * @ptype uint
120  */
121 #define BS_NR_OF_CELL_BLOCKS_PER_MODULE (14u)
122 
123 /**
124  * @ingroup CONFIG_BATTERYSYSTEM
125  * @brief number of battery cells in a parallel cell connection per battery
126  * module
127  * @details For details see
128  * <a href="../../../../introduction/naming-conventions.html" target="_blank">Naming Conventions</a>.
129  * @ptype uint
130  */
131 #define BS_NR_OF_PARALLEL_CELLS_PER_MODULE (1u)
132 
133 #if BS_NR_OF_CELL_BLOCKS_PER_MODULE <= 12u
134 #define BS_MAX_SUPPORTED_CELLS (12u)
135 #elif BS_NR_OF_CELL_BLOCKS_PER_MODULE <= 14u
136 #define BS_MAX_SUPPORTED_CELLS (14u)
137 #elif BS_NR_OF_CELL_BLOCKS_PER_MODULE <= 15u
138 #define BS_MAX_SUPPORTED_CELLS (15u)
139 #elif BS_NR_OF_CELL_BLOCKS_PER_MODULE <= 16u
140 #define BS_MAX_SUPPORTED_CELLS (16u)
141 #elif BS_NR_OF_CELL_BLOCKS_PER_MODULE <= 18u
142 #define BS_MAX_SUPPORTED_CELLS (18u)
143 #elif BS_NR_OF_CELL_BLOCKS_PER_MODULE == 36u
144 #define BS_MAX_SUPPORTED_CELLS (36u)
145 #else
146 #error "Unsupported number of cells per module, higher than 18 and not 36"
147 #endif
148 
149 /**
150  * @def BS_MAX_SUPPORTED_CELLS
151  * @brief Defines the maximal number of supported cells per module
152  */
153 
154 /** Value of the balancing resistors on the slave-board */
155 #define BS_BALANCING_RESISTANCE_ohm (100.0)
156 
157 /**
158  * @def BS_NR_OF_GPIOS_PER_MODULE
159  * @brief Number of GPIOs on the LTC IC
160  * @details - 5 for 12 cell version
161  * - 9 for 18 cell version
162  */
163 #if BS_MAX_SUPPORTED_CELLS == 12u
164 #define BS_NR_OF_GPIOS_PER_MODULE (5u)
165 #elif BS_MAX_SUPPORTED_CELLS == 14u
166 #define BS_NR_OF_GPIOS_PER_MODULE (8u)
167 #else
168 #define BS_NR_OF_GPIOS_PER_MODULE (9u)
169 #endif
170 
171 /**
172  * @ingroup CONFIG_BATTERYSYSTEM
173  * @brief number of temperature sensors per battery module
174  * @ptype int
175  */
176 #define BS_NR_OF_TEMP_SENSORS_PER_MODULE (8u)
177 
178 /** number of battery cells in the system */
179 #define BS_NR_OF_CELL_BLOCKS_PER_STRING (BS_NR_OF_MODULES_PER_STRING * BS_NR_OF_CELL_BLOCKS_PER_MODULE)
180 /** number of temperature sensors in a string */
181 #define BS_NR_OF_TEMP_SENSORS_PER_STRING (BS_NR_OF_MODULES_PER_STRING * BS_NR_OF_TEMP_SENSORS_PER_MODULE)
182 /** number of temperature sensors in the battery system */
183 #define BS_NR_OF_TEMP_SENSORS (BS_NR_OF_TEMP_SENSORS_PER_STRING * BS_NR_OF_STRINGS)
184 
185 /** number of temperature sensors on each ADC0 channel of the slave-board */
186 #define BS_NR_OF_TEMP_SENSORS_ON_SADC0 (3u)
187 /** number of temperature sensors on each ADC1 channel of the slave-board */
188 #define BS_NR_OF_TEMP_SENSORS_ON_SADC1 (3u)
189 
190 /**
191  * @details - If set to false, foxBMS does not check for the presence of a
192  * current sensor.
193  * - If set to true, foxBMS checks for the presence of a current
194  * sensor. If sensor stops responding during runtime, an error is
195  * raised.
196  */
197 #define CURRENT_SENSOR_PRESENT (false)
198 
199 #if CURRENT_SENSOR_PRESENT == true
200 /**
201  * defines if the Isabellenhuette current sensor is used in cyclic or triggered mode
202  */
203 #define CURRENT_SENSOR_ISABELLENHUETTE_CYCLIC
204 /* #define CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED */
205 
206 /** Delay in ms after which it is considered the current measurement is not responding anymore. */
207 #define BS_CURRENT_MEASUREMENT_RESPONSE_TIMEOUT_MS (200u)
208 
209 /** Delay in ms after which it is considered the coulomb counting is not responding anymore. */
210 #define BS_COULOMB_COUNTING_MEASUREMENT_RESPONSE_TIMEOUT_MS (2000u)
211 
212 /** Delay in ms after which it is considered the energy counting is not responding anymore. */
213 #define BS_ENERGY_COUNTING_MEASUREMENT_RESPONSE_TIMEOUT_MS (2000u)
214 
215 #endif /* CURRENT_SENSOR_PRESENT == true */
216 
217 /**
218  * @brief Maximum break current of main contactors.
219  * @details The contacts of the main contactors can be welded, when attempting
220  * to interrupt the current flow while a current higher than the
221  * maximum break current of the contactor is flowing.
222  *
223  * Thus, the contactors will not be opened if the floating current is
224  * above this value. The fuse should trigger to interrupt current
225  * flows above this value.
226  */
227 #define BS_MAIN_CONTACTORS_MAXIMUM_BREAK_CURRENT_mA (500000)
228 
229 /**
230  * @brief Maximum fuse trigger duration
231  * @details If the current is above #BS_MAIN_CONTACTORS_MAXIMUM_BREAK_CURRENT_mA,
232  * the BMS state machine will wait this time until the fuse triggers so
233  * that the current will be interrupted by the fuse and not the
234  * contactors. After this time, the BMS will nevertheless try to open
235  * the contactors.
236  */
237 #define BS_MAIN_FUSE_MAXIMUM_TRIGGER_DURATION_ms (30000u)
238 
239 /**
240  * @brief Maximum string current limit in mA that is used in the SOA module
241  * to check for string overcurrent
242 * @details When maximum safety limit (MSL) is violated, error state is
243  * requested and contactors will open.
244  */
245 #define BS_MAXIMUM_STRING_CURRENT_mA (10000u)
246 
247 /**
248  * @brief Maximum pack current limit in mA that is used in the SOA module
249  * to check for pack overcurrent
250  * @details When maximum safety limit (MSL) is violated, error state is
251  * requested and contactors will open.
252  */
253 #define BS_MAXIMUM_PACK_CURRENT_mA (10000u * BS_NR_OF_STRINGS)
254 
255 /**
256  * @ingroup CONFIG_BATTERYSYSTEM
257  * @brief Define if interlock feedback should be discarded or not
258  * @details True: interlock feedback will be discarded
259  * False: interlock feedback will evaluated
260  */
261 #define BS_IGNORE_INTERLOCK_FEEDBACK (false)
262 
263 /**
264  * @details - If set to false, foxBMS does not check CAN timing.
265  * - If set to true, foxBMS checks CAN timing. A valid request must
266  * come every 100ms, within the 95-150ms window.
267  */
268 #define CHECK_CAN_TIMING (true)
269 
270 /**
271  * @details - If set to true, balancing is deactivated completely.
272  * - If set to false, foxBMS checks when balancing must be done and
273  * activates it accordingly.
274  */
275 #define BALANCING_DEFAULT_INACTIVE (true)
276 
277 /**
278  * @ingroup CONFIG_BATTERYSYSTEM
279  * @brief Defines behaviour if an insulation error is detected
280  * @details - If set to true: contactors will be opened
281  * - If set to false: contactors will NOT be opened
282  */
283 #define BMS_OPEN_CONTACTORS_ON_INSULATION_ERROR (false)
284 
285 /**
286  * @ingroup CONFIG_BATTERYSYSTEM
287  * @brief number of high voltage inputs measured by current sensors (like
288  * IVT-MOD)
289  * @ptype int
290  */
291 #define BS_NR_OF_VOLTAGES_FROM_CURRENT_SENSOR (3u)
292 
293 /**
294  * @ingroup CONFIG_BATTERYSYSTEM
295  * @brief number of voltages measured by MCU internal ADC
296  * @ptype int
297  */
298 #define BS_NR_OF_VOLTAGES_FROM_MCU_ADC (2)
299 
300 /** Number of contactors in addition to string contactors (e.g., PRECHARGE).*/
301 #define BS_NR_OF_CONTACTORS_OUTSIDE_STRINGS (1u)
302 
303 /** Total number of contactors in system:
304  * - Two contactors per string (string+ and string-)
305  * - One optional precharge contactor for each string */
306 #define BS_NR_OF_CONTACTORS ((2u * BS_NR_OF_STRINGS) + BS_NR_OF_CONTACTORS_OUTSIDE_STRINGS)
307 
308 /**
309  * @brief current threshold for determing rest state of battery. If absolute
310  * current is below this limit value the battery is resting.
311  */
312 #define BS_REST_CURRENT_mA (200)
313 
314 /**
315  * @brief Wait time in 10ms before battery system is at rest. Balancing for
316  * example only starts if battery system is at rest.
317  */
318 #define BS_RELAXATION_PERIOD_10ms (60000u)
319 
320 /**
321  * @brief current sensor threshold for 0 current in mA as the sensor has a
322  * jitter.
323  */
324 #define BS_CS_THRESHOLD_NO_CURRENT_mA (200u)
325 
326 /**
327  * @brief Maximum voltage drop over fuse.
328  * @details If the measured voltage difference between battery voltage
329  * voltage after fuse is larger than this value. It can be concluded,
330  * that the fuse has tripped. The voltage difference can be estimated
331  * by the maximum current and the resistance.
332  * For a Cooper Bussmann 1000A fuse the voltage drop can be estimated
333  * to: I_max = 1000A and P_loss = 206W
334  * -> voltage drop at 1000A roughly 206mV
335  * -> select 500mV because of measurement inaccuracies
336  */
337 #define BS_MAX_VOLTAGE_DROP_OVER_FUSE_mV (500)
338 
339 /**
340  * @brief TODO
341  * @details Set to true if fuse in NORMAL path should be checked. This can only
342  * be done if one dedicated HV measurement is used to monitor the
343  * voltage directly after the fuse. Then a voltage difference between
344  * V_bat and V_fuse indicates a tripped fuse.
345  *
346  * V_bat +------+ V_fuse Precharge/Main+ contactor
347  * -----+---| FUSE |-----+------------/ -----------------
348  * +------+
349  */
350 #define BS_CHECK_FUSE_PLACED_IN_NORMAL_PATH (true)
351 
352 /**
353  * @brief TODO
354  * @details Set to true if fuse in CHARGE path should be checked. This can only
355  * be done if one dedicated HV measurement is used to monitor
356  * voltage directly after the fuse. Then a voltage difference between
357  * V_bat and V_fuse indicates a tripped fuse.
358  *
359  * V_bat +------+ V_fuse Precharge/Charge+ contactor
360  * -----+---| FUSE |-----+------------/ -----------------
361  * +------+
362  */
363 #define BS_CHECK_FUSE_PLACED_IN_CHARGE_PATH (false)
364 
365 /**
366  * \defgroup open wire check configuration
367  * @details If open-wire check is performed, depending on the AFE
368  * implementation, cell voltages and temperatures are not updated
369  * and thus old values can be transmitted on the CAN bus. Check
370  * time is dependent on module configuration and external
371  * capacitance. Activate open-wire check with care! See the AFE
372  * implementation for details.
373  * @{
374  */
375 /** enable open-wire checks during standby */
376 #define BS_STANDBY_PERIODIC_OPEN_WIRE_CHECK (false)
377 
378 /** Periodic open-wire check time in STANDBY state in ms */
379 #define BS_STANDBY_OPEN_WIRE_PERIOD_ms (600000)
380 
381 /** open-wire check in normal mode (set to true or false) */
382 #define BS_NORMAL_PERIODIC_OPEN_WIRE_CHECK (false)
383 
384 /** Periodic open-wire check time in NORMAL state in ms */
385 #define BS_NORMAL_OPEN_WIRE_PERIOD_ms (600000)
386 
387 /** open-wire check in charge mode (set to true or false) */
388 #define BS_CHARGE_PERIODIC_OPEN_WIRE_CHECK (false)
389 
390 /** Periodic open-wire check time in CHARGE state in ms */
391 #define BS_CHARGE_OPEN_WIRE_PERIOD_ms (600000)
392 
393 /** Periodic open-wire check time in ERROR state in ms */
394 #define BS_ERROR_OPEN_WIRE_PERIOD_ms (30000)
395 /**@}*/
396 
397 FAS_STATIC_ASSERT((BS_NR_OF_STRINGS <= (uint8_t)UINT8_MAX), "This code assumes BS_NR_OF_STRINGS fits into uint8_t");
398 
399 /*========== Extern Constant and Variable Declarations ======================*/
400 /** Precharge presence of not for each string */
402 
403 /*========== Extern Function Prototypes =====================================*/
404 
405 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
406 
407 #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
General macros and definitions for the whole platform.