foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
ltc_6813-1_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 ltc_6813-1_cfg.h
44  * @author foxBMS Team
45  * @date 2015-02-18 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup DRIVERS_CONFIGURATION
49  * @prefix LTC
50  *
51  * @brief Header for the configuration for the LTC 6804-1 6811-1, 6812-1,
52  * and 6813-1 monitoring IC.
53  *
54  */
55 
56 #ifndef FOXBMS__LTC_6813_1_CFG_H_
57 #define FOXBMS__LTC_6813_1_CFG_H_
58 
59 /*========== Includes =======================================================*/
60 /* clang-format off */
61 #include "ltc_cfg.h"
62 /* clang-format on */
63 
64 #include "ltc_defs.h"
65 #include "battery_system_cfg.h"
66 
67 #include "ltc_afe_dma.h"
68 #include "spi.h"
69 
70 #include <stdbool.h>
71 #include <stdint.h>
72 
73 /*========== Macros and Definitions =========================================*/
74 /**
75  * If set to 1 LTC driver is configured to use foxBMS slave boards version 1.x
76  * If set to 2 LTC driver is configured to use foxBMS slave boards version 2.x
77  */
78 #define SLAVE_BOARD_VERSION (2)
79 
80 #if SLAVE_BOARD_VERSION == 1
81 #elif SLAVE_BOARD_VERSION == 2
82 #else
83 #error Please select the slave board version you want to use. Configuration file: \src\module\config\ltc_cfg.h
84 #endif
85 
86 /**
87  * @def LTC_6813_MAX_SUPPORTED_CELLS
88  * @brief Defines the maximal number of supported cells per module
89  */
90 #define LTC_6813_MAX_SUPPORTED_CELLS (18u)
91 
92 #if BS_NR_OF_CELL_BLOCKS_PER_MODULE > LTC_6813_MAX_SUPPORTED_CELLS
93 #error "Number of cell blocks per module cannot be higher than maximum number of cells per module"
94 #endif
95 
96 /**
97  * If set to 0 LTC driver is configured to use PCA8574 port expander
98  * If set to 1 LTC driver is configured to use TCA6408A port expander
99  */
100 #define LTC_PORTEXPANDER_VERSION (1u)
101 
102 /** Address of TI port expander (0 or 1) */
103 #define LTC_PORTEXPANDER_ADR_TI (0u)
104 
105 /** Controls if PEC should be discarded (true) or not (false) */
106 #define LTC_DISCARD_PEC (false)
107 
108 /* set to true or false */
109 #define LTC_GOTO_MUX_CHECK (true)
110 
111 /* set to true or false */
112 #define LTC_DISCARD_MUX_CHECK (false)
113 
114 /** Number of multiplexer used per LTC-IC */
115 #define LTC_N_MUX_PER_LTC (3u)
116 
117 /** Number of channels per multiplexer */
118 #define LTC_N_MUX_CHANNELS_PER_MUX (8u)
119 
120 /** Number of multiplexer measurements per LTC cycle */
121 #define LTC_NUMBER_OF_MUX_MEASUREMENTS_PER_CYCLE (8u)
122 
123 /** Number of multiplexed channels per LTC-IC */
124 #define LTC_N_MUX_CHANNELS_PER_LTC (LTC_N_MUX_PER_LTC * LTC_N_MUX_CHANNELS_PER_MUX)
125 
126 /** Number of LTC-ICs per battery module */
127 #define LTC_NUMBER_OF_LTC_PER_MODULE (1u)
128 
129 /** Open-wire detection threshold */
130 #define LTC_ADOW_THRESHOLD (-400)
131 
132 /**
133  * Measurement modus for voltages, possible values:
134  * - LTC_ADCMODE_NORMAL_DCP0
135  * - LTC_ADCMODE_FILTERED_DCP0
136  * - LTC_ADCMODE_FAST_DCP0
137  */
138 #define LTC_VOLTAGE_MEASUREMENT_MODE (LTC_ADCMODE_NORMAL_DCP0)
139 
140 /**
141  * Measurement modus for GPIOs, possible values:
142  * - LTC_ADCMODE_NORMAL_DCP0
143  * - LTC_ADCMODE_FILTERED_DCP0
144  * - LTC_ADCMODE_FAST_DCP0
145  */
146 #define LTC_GPIO_MEASUREMENT_MODE (LTC_ADCMODE_NORMAL_DCP0)
147 
148 /**
149  * Measurement modus for Open-wire check, possible values:
150  * - LTC_ADCMODE_NORMAL_DCP0
151  * - LTC_ADCMODE_FILTERED_DCP0
152  */
153 #define LTC_OW_MEASUREMENT_MODE (LTC_ADCMODE_NORMAL_DCP0)
154 
155 /**
156  * Timeout in milliseconds added to the transmission time for interrupt-based
157  * SPI transmission.
158  */
159 #define LTC_TRANSMISSION_TIMEOUT (10)
160 
161 /**
162  * SPI1 is used for communication with LTC
163  * @{
164  */
165 #define LTC_SPI_HANDLE (&spi_devices[0])
166 #define LTC_SPI_INSTANCE (*LTC_SPI_HANDLE.Instance)
167 #define LTC_SPI_PRESCALER (*LTC_SPI_HANDLE.Init.BaudRatePrescaler)
168 /**@}*/
169 
170 /** start definition of LTC timings; Twake (see LTC data sheet) */
171 #define LTC_TWAKE_US (300)
172 /** start definition of LTC timings; Tready (see LTC data sheet) */
173 #define LTC_TREADY_US (10)
174 /** start definition of LTC timings; Tidle (see LTC data sheet) */
175 #define LTC_TIDLE_US (6700)
176 
177 /** LTC SPI wakeup time */
178 #define LTC_SPI_WAKEUP_WAIT_TIME_US (30u)
179 
180 /** LTC state machine short time definition in ms */
181 #define LTC_STATEMACH_SHORTTIME (1)
182 
183 /**
184  * time for the first initialization of the daisy chain
185  * see LTC6804 data sheet page 41
186  */
187 #define LTC_STATEMACH_DAISY_CHAIN_FIRST_INITIALIZATION_TIME ((LTC_TWAKE_US * LTC_N_LTC) / 1000)
188 /**
189  * time for the second initialization of the daisy chain
190  * see LTC6804 data sheet page 41
191  */
192 #define LTC_STATEMACH_DAISY_CHAIN_SECOND_INITIALIZATION_TIME ((LTC_TREADY_US * LTC_N_LTC) / 1000)
193 
194 /*
195  * Timings of Voltage Cell and GPIO measurement for all cells or all GPIO
196  */
197 
198 /**
199  * ~1.1ms Measurement+Calibration Cycle Time When Starting from the REFUP State in Fast Mode
200  * unit: ms
201  */
202 #define LTC_STATEMACH_MEAS_ALL_CELLS_FAST_TCYCLE (2)
203 
204 /**
205  * ~2.3ms Measurement+Calibration Cycle Time When Starting from the REFUP State in Normal Mode
206  * unit: ms
207  */
208 #define LTC_STATEMACH_MEAS_ALL_CELLS_NORMAL_TCYCLE (3)
209 
210 /**
211  * ~201ms Measurement+Calibration Cycle Time When Starting from the REFUP State in Filtered Mode
212  * unit: ms
213  */
214 #define LTC_STATEMACH_MEAS_ALL_CELLS_FILTERED_TCYCLE (202)
215 
216 /**
217  * ~203us Measurement+Calibration Cycle Time When Starting from the REFUP State in Fast Mode
218  * unit: ms
219  */
220 #define LTC_STATEMACH_MEAS_TWO_CELLS_FAST_TCYCLE (1)
221 
222 /**
223  * ~407us Measurement+Calibration Cycle Time When Starting from the REFUP State in Normal Mode
224  * unit: ms
225  */
226 #define LTC_STATEMACH_MEAS_TWO_CELLS_NORMAL_TCYCLE (1)
227 
228 /**
229  * ~34ms Measurement+Calibration Cycle Time When Starting from the REFUP State in Filtered Mode
230  * unit: ms
231  */
232 #define LTC_STATEMACH_MEAS_TWO_CELLS_FILTERED_TCYCLE (35)
233 
234 /*
235  * Timings of Voltage Cell and GPIO measurement for a pair of cells or a single GPIO
236  */
237 
238 /**
239  * ~1.8ms Measurement+Calibration Cycle Time When Starting from the REFUP State in Fast Mode
240  * unit: ms
241  */
242 #define LTC_STATEMACH_MEAS_ALL_GPIOS_FAST_TCYCLE (2)
243 
244 /**
245  * ~3.9ms Measurement+Calibration Cycle Time When Starting from the REFUP State in Normal Mode
246  * unit: ms
247  */
248 #define LTC_STATEMACH_MEAS_ALL_GPIOS_NORMAL_TCYCLE (4)
249 
250 /**
251  * ~335ms Measurement+Calibration Cycle Time When Starting from the REFUP State in Filtered Mode
252  * unit: ms
253  */
254 #define LTC_STATEMACH_MEAS_ALL_GPIOS_FILTERED_TCYCLE (336)
255 
256 /**
257  * ~380us Measurement+Calibration Cycle Time When Starting from the REFUP State in Fast Mode
258  * unit: ms
259  */
260 #define LTC_STATEMACH_MEAS_SINGLE_GPIO_FAST_TCYCLE (1)
261 
262 /**
263  * ~788us Measurement+Calibration Cycle Time When Starting from the REFUP State in Normal Mode
264  * unit: ms
265  */
266 #define LTC_STATEMACH_MEAS_SINGLE_GPIO_NORMAL_TCYCLE (1)
267 
268 /**
269  * ~67.1ms Measurement+Calibration Cycle Time When Starting from the REFUP State in Filtered Mode
270  * unit: ms
271  */
272 #define LTC_STATEMACH_MEAS_SINGLE_GPIO_FILTERED_TCYCLE (68)
273 
274 /** LTC state machine sequence error timing in ms */
275 #define LTC_STATEMACH_SEQERRTTIME (5)
276 /** LTC state machine CRC-transmission error timing in ms */
277 #define LTC_STATEMACH_PECERRTIME (1)
278 
279 /**
280  * Maximum number of re-tries in case of CRC error during the communication with daisy chain
281  * before going into error state
282  */
283 #define LTC_TRANSMIT_PECERRLIMIT (10)
284 
285 /**
286  * Maximum number of re-tries in case of SPI error during the communication with daisy chain
287  * before going into error state
288  */
289 #define LTC_TRANSMIT_SPIERRLIMIT (3)
290 
291 /** If set to 1, check if multiplexers acknowledged transmission */
292 #define LTC_READCOM (0)
293 
294 /**
295  * Number of required ADOW commands because of external C-Pin capacitance and
296  * the respective duration to perform an open wire check for 14 modules with
297  * 12 cells each. During this time no cell voltages and temperatures are measured!
298  * +----------------+--------------+---------------+----------+----------+
299  * | External C pin | Normal mode | Filtered mode | Duration | Duration |
300  * | capacitance | | | normal | filtered |
301  * | ---------------+--------------+---------------+----------+----------+
302  * | <= 10nF | 2 | 2 | 32ms | 828ms |
303  * | 100nF | 10 | 2 | 112ms | 828ms |
304  * | 1uF | 100 | 2 | 1012ms | 828ms |
305  * | C | 1.5+(C/10nF) | 2 | | |
306  * +----------------+--------------+---------------+----------+----------+
307  */
308 #define LTC_NMBR_REQ_ADOW_COMMANDS (2)
309 
310 /**
311  * Transmit functions
312  * @{
313  */
314 #define LTC_TRANSMIT_WAKE_UP(spi_ltcInterface) SPI_TransmitDummyByte(spi_ltcInterface, LTC_SPI_WAKEUP_WAIT_TIME_US)
315 #define LTC_TRANSMIT_I2C_COMMAND(spi_ltcInterface, txbuf) \
316  SPI_TransmitDummyByte(spi_ltcInterface, LTC_SPI_WAKEUP_WAIT_TIME_US); \
317  SPI_TransmitData(spi_ltcInterface, txbuf, 4 + 9)
318 #define LTC_TRANSMIT_COMMAND(spi_ltcInterface, command) \
319  SPI_TransmitDummyByte(spi_ltcInterface, LTC_SPI_WAKEUP_WAIT_TIME_US); \
320  SPI_TransmitData(spi_ltcInterface, command, 4)
321 #define LTC_TRANSMIT_RECEIVE_DATA(spi_ltcInterface, txbuf, rxbuf, length) \
322  SPI_TransmitDummyByte(spi_ltcInterface, LTC_SPI_WAKEUP_WAIT_TIME_US); \
323  SPI_TransmitReceiveDataDma(spi_ltcInterface, txbuf, rxbuf, length)
324 /**@}*/
325 
326 /*========== Extern Constant and Variable Declarations ======================*/
327 
328 /**
329  * Definition of the multiplexer measurement sequence
330  */
332 
333 /**
334  * On the foxBMS slave board there are 6 multiplexer inputs dedicated to temperature
335  * sensors by default.
336  * Lookup table between temperature sensors and battery cells
337  */
339 
340 /** Lookup table to indicate which voltage inputs are used */
342 
343 /*========== Extern Function Prototypes =====================================*/
344 
345 /**
346  * @brief converts a raw voltage from multiplexer to a temperature value in
347  * deci &deg;C.
348  * @details The temperatures are read from NTC elements via voltage dividers.
349  * This function implements the look-up table between voltage and
350  * temperature, taking into account the NTC characteristics and the
351  * voltage divider.
352  * @param adcVoltage_mV voltage read from the multiplexer in mV
353  * @return temperature value in deci &deg;C
354  */
355 extern int16_t LTC_ConvertMuxVoltagesToTemperatures(uint16_t adcVoltage_mV);
356 
357 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
358 #ifdef UNITY_UNIT_TEST
359 #endif
360 
361 #endif /* FOXBMS__LTC_6813_1_CFG_H_ */
Configuration of the battery system (e.g., number of battery modules, battery cells,...
#define BS_NR_OF_TEMP_SENSORS_PER_MODULE
number of temperature sensors per battery module
const uint8_t ltc_muxsensortemperatur_cfg[BS_NR_OF_TEMP_SENSORS_PER_MODULE]
const uint8_t ltc_voltage_input_used[LTC_6813_MAX_SUPPORTED_CELLS]
Definition: ltc_6806_cfg.c:66
LTC_MUX_SEQUENCE_s ltc_mux_seq
int16_t LTC_ConvertMuxVoltagesToTemperatures(uint16_t adcVoltage_mV)
converts a raw voltage from multiplexer to a temperature value in deci °C.
#define LTC_6813_MAX_SUPPORTED_CELLS
Defines the maximal number of supported cells per module.
Headers for the driver for the DMA module for the LTC.
Headers for the configuration for the LTC analog front-end.
Headers for the driver for the LTC analog front-end.
Headers for the driver for the SPI module.