foxBMS - Unit Tests  1.5.0
The foxBMS Unit Tests 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-02-03 (date of last update)
47  * @version v1.5.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 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 /** Value of the balancing resistors on the slave-board */
134 #define BS_BALANCING_RESISTANCE_ohm (100.0)
135 
136 /**
137  * @def BS_NR_OF_GPIOS_PER_MODULE
138  * @brief Defines the number of GPIOs
139  */
140 #define BS_NR_OF_GPIOS_PER_MODULE (10u)
141 
142 /**
143  * @def BS_NR_OF_GPAS_PER_MODULE
144  * @brief Defines the number of GPA inputs
145  */
146 #define BS_NR_OF_GPAS_PER_MODULE (2u)
147 
148 /**
149  * @brief number of temperature sensors per battery module
150  * @ptype int
151  */
152 #define BS_NR_OF_TEMP_SENSORS_PER_MODULE (8u)
153 
154 #if BS_NR_OF_TEMP_SENSORS_PER_MODULE > BS_NR_OF_GPIOS_PER_MODULE
155 #error "Number of temperature inputs cannot be higher than number of GPIOs"
156 #endif
157 
158 /** number of battery cells in the system */
159 #define BS_NR_OF_CELL_BLOCKS_PER_STRING (BS_NR_OF_MODULES_PER_STRING * BS_NR_OF_CELL_BLOCKS_PER_MODULE)
160 /** number of temperature sensors in a string */
161 #define BS_NR_OF_TEMP_SENSORS_PER_STRING (BS_NR_OF_MODULES_PER_STRING * BS_NR_OF_TEMP_SENSORS_PER_MODULE)
162 /** number of temperature sensors in the battery system */
163 #define BS_NR_OF_TEMP_SENSORS (BS_NR_OF_TEMP_SENSORS_PER_STRING * BS_NR_OF_STRINGS)
164 
165 /**
166  * @details - If set to false, foxBMS does not check for the presence of a
167  * current sensor.
168  * - If set to true, foxBMS checks for the presence of a current
169  * sensor. If sensor stops responding during runtime, an error is
170  * raised.
171  */
172 #define BS_CURRENT_SENSOR_PRESENT (false)
173 
174 #if BS_CURRENT_SENSOR_PRESENT == true
175 /**
176  * defines if the Isabellenhuette current sensor is used in cyclic or triggered mode
177  */
178 #define CURRENT_SENSOR_ISABELLENHUETTE_CYCLIC
179 /* #define CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED */
180 
181 /** Delay in ms after which it is considered the current measurement is not responding anymore. */
182 #define BS_CURRENT_MEASUREMENT_RESPONSE_TIMEOUT_ms (200u)
183 
184 /** Delay in ms after which it is considered the coulomb counting is not responding anymore. */
185 #define BS_COULOMB_COUNTING_MEASUREMENT_RESPONSE_TIMEOUT_ms (2000u)
186 
187 /** Delay in ms after which it is considered the energy counting is not responding anymore. */
188 #define BS_ENERGY_COUNTING_MEASUREMENT_RESPONSE_TIMEOUT_ms (2000u)
189 
190 #endif /* BS_CURRENT_SENSOR_PRESENT == true */
191 
192 /**
193  * @brief Maximum break current of main contactors.
194  * @details The contacts of the main contactors can be welded, when attempting
195  * to interrupt the current flow while a current higher than the
196  * maximum break current of the contactor is flowing.
197  *
198  * Thus, the contactors will not be opened if the floating current is
199  * above this value. The fuse should trigger to interrupt current
200  * flows above this value.
201  */
202 #define BS_MAIN_CONTACTORS_MAXIMUM_BREAK_CURRENT_mA (500000)
203 
204 /**
205  * @brief Maximum fuse trigger duration
206  * @details If the current is above #BS_MAIN_CONTACTORS_MAXIMUM_BREAK_CURRENT_mA,
207  * the BMS state machine will wait this time until the fuse triggers so
208  * that the current will be interrupted by the fuse and not the
209  * contactors. After this time, the BMS will nevertheless try to open
210  * the contactors.
211  */
212 #define BS_MAIN_FUSE_MAXIMUM_TRIGGER_DURATION_ms (30000u)
213 
214 /**
215  * @brief Maximum string current limit in mA that is used in the SOA module
216  * to check for string overcurrent
217 * @details When maximum safety limit (MSL) is violated, error state is
218  * requested and contactors will open.
219  */
220 #define BS_MAXIMUM_STRING_CURRENT_mA (10000u)
221 
222 /**
223  * @brief Maximum pack current limit in mA that is used in the SOA module
224  * to check for pack overcurrent
225  * @details When maximum safety limit (MSL) is violated, error state is
226  * requested and contactors will open.
227  */
228 #define BS_MAXIMUM_PACK_CURRENT_mA (10000u * BS_NR_OF_STRINGS)
229 
230 /**
231  * @brief Define if interlock feedback should be discarded or not
232  * @details True: interlock feedback will be discarded
233  * False: interlock feedback will evaluated
234  */
235 #define BS_IGNORE_INTERLOCK_FEEDBACK (false)
236 
237 /**
238  * @brief Defines whether CAN timing shall be evaluated or not
239  * @details - If set to false, foxBMS does not check CAN timing.
240  * - If set to true, foxBMS checks CAN timing. A valid request must
241  * come every 100ms, within the 95-150ms window.
242  */
243 #define BS_CHECK_CAN_TIMING (true)
244 
245 /**
246  * @brief Defines whether balancing shall be available or not
247  * @details - If set to true, balancing is deactivated completely.
248  * - If set to false, foxBMS checks when balancing must be done and
249  * activates it accordingly.
250  */
251 #define BS_BALANCING_DEFAULT_INACTIVE (true)
252 
253 /**
254  * @brief number of high voltage inputs measured by current sensors (like
255  * IVT-MOD)
256  * @ptype int
257  */
258 #define BS_NR_OF_VOLTAGES_FROM_CURRENT_SENSOR (3u)
259 
260 /** Number of contactors in addition to string contactors (e.g., PRECHARGE).*/
261 #define BS_NR_OF_CONTACTORS_OUTSIDE_STRINGS (1u)
262 
263 /** Total number of contactors in system:
264  * - Two contactors per string (string+ and string-)
265  * - One optional precharge contactor for each string */
266 #define BS_NR_OF_CONTACTORS ((2u * BS_NR_OF_STRINGS) + BS_NR_OF_CONTACTORS_OUTSIDE_STRINGS)
267 
268 /**
269  * @brief current threshold for determining rest state of battery. If absolute
270  * current is below this limit value the battery is resting.
271  */
272 #define BS_REST_CURRENT_mA (200)
273 
274 /**
275  * @brief Wait time in 10ms before battery system is at rest. Balancing for
276  * example only starts if battery system is at rest.
277  */
278 #define BS_RELAXATION_PERIOD_10ms (60000u)
279 
280 /**
281  * @brief current sensor threshold for 0 current in mA as the sensor has a
282  * jitter.
283  */
284 #define BS_CS_THRESHOLD_NO_CURRENT_mA (200u)
285 
286 /**
287  * @brief Maximum voltage drop over fuse.
288  * @details If the measured voltage difference between battery voltage
289  * voltage after fuse is larger than this value. It can be concluded,
290  * that the fuse has tripped. The voltage difference can be estimated
291  * by the maximum current and the resistance.
292  * For a Cooper Bussmann 1000A fuse the voltage drop can be estimated
293  * to: I_max = 1000A and P_loss = 206W
294  * -> voltage drop at 1000A roughly 206mV
295  * -> select 500mV because of measurement inaccuracies
296  */
297 #define BS_MAX_VOLTAGE_DROP_OVER_FUSE_mV (500)
298 
299 /**
300  * @brief TODO
301  * @details Set to true if fuse in NORMAL path should be checked. This can only
302  * be done if one dedicated HV measurement is used to monitor the
303  * voltage directly after the fuse. Then a voltage difference between
304  * V_bat and V_fuse indicates a tripped fuse.
305  *
306  * V_bat +------+ V_fuse Precharge/Main+ contactor
307  * -----+---| FUSE |-----+------------/ -----------------
308  * +------+
309  */
310 #define BS_CHECK_FUSE_PLACED_IN_NORMAL_PATH (true)
311 
312 /**
313  * @brief TODO
314  * @details Set to true if fuse in CHARGE path should be checked. This can only
315  * be done if one dedicated HV measurement is used to monitor
316  * voltage directly after the fuse. Then a voltage difference between
317  * V_bat and V_fuse indicates a tripped fuse.
318  *
319  * V_bat +------+ V_fuse Precharge/Charge+ contactor
320  * -----+---| FUSE |-----+------------/ -----------------
321  * +------+
322  */
323 #define BS_CHECK_FUSE_PLACED_IN_CHARGE_PATH (false)
324 
325 /**
326  * \defgroup open wire check configuration
327  * @details If open-wire check is performed, depending on the AFE
328  * implementation, cell voltages and temperatures are not updated
329  * and thus old values can be transmitted on the CAN bus. Check
330  * time is dependent on module configuration and external
331  * capacitance. Activate open-wire check with care! See the AFE
332  * implementation for details.
333  * @{
334  */
335 /** enable open-wire checks during standby */
336 #define BS_STANDBY_PERIODIC_OPEN_WIRE_CHECK (false)
337 
338 /** Periodic open-wire check time in STANDBY state in ms */
339 #define BS_STANDBY_OPEN_WIRE_PERIOD_ms (600000)
340 
341 /** open-wire check in normal mode (set to true or false) */
342 #define BS_NORMAL_PERIODIC_OPEN_WIRE_CHECK (false)
343 
344 /** Periodic open-wire check time in NORMAL state in ms */
345 #define BS_NORMAL_OPEN_WIRE_PERIOD_ms (600000)
346 
347 /** open-wire check in charge mode (set to true or false) */
348 #define BS_CHARGE_PERIODIC_OPEN_WIRE_CHECK (false)
349 
350 /** Periodic open-wire check time in CHARGE state in ms */
351 #define BS_CHARGE_OPEN_WIRE_PERIOD_ms (600000)
352 
353 /** Periodic open-wire check time in ERROR state in ms */
354 #define BS_ERROR_OPEN_WIRE_PERIOD_ms (30000)
355 /**@}*/
356 
357 FAS_STATIC_ASSERT((BS_NR_OF_STRINGS <= (uint8_t)UINT8_MAX), "This code assumes BS_NR_OF_STRINGS fits into uint8_t");
358 
359 /*========== Extern Constant and Variable Declarations ======================*/
360 /** Defines whether a string can be used to precharge or not */
362 
363 /*========== Extern Function Prototypes =====================================*/
364 
365 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
366 #ifdef UNITY_UNIT_TEST
367 #endif
368 
369 #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.