foxBMS  1.1.2
The foxBMS Battery Management System API Documentation
plausibility.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, 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 plausibility.c
44  * @author foxBMS Team
45  * @date 2020-02-24 (date of creation)
46  * @updated 2020-02-24 (date of last update)
47  * @ingroup APPLICATION
48  * @prefix PL
49  *
50  * @brief plausibility checks for cell voltage and cell temperatures
51  *
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "plausibility.h"
56 
57 #include "battery_system_cfg.h"
58 
59 #include "diag.h"
60 #include "foxmath.h"
61 
62 /*========== Macros and Definitions =========================================*/
63 
64 /*========== Static Constant and Variable Definitions =======================*/
65 
66 /*========== Extern Constant and Variable Definitions =======================*/
67 
68 /*========== Static Function Prototypes =====================================*/
69 
70 /*========== Static Function Implementations ================================*/
71 
72 /*========== Extern Function Implementations ================================*/
73 extern STD_RETURN_TYPE_e PL_CheckStringVoltage(int32_t voltageMic_mV, int32_t voltageCurrentSensor_mV) {
75 
76  /* Get deviation between these two measurements */
77  int32_t diff_mV = voltageMic_mV - voltageCurrentSensor_mV;
78 
79  if (abs(diff_mV) < PL_STRING_VOLTAGE_TOLERANCE_mV) {
80  result = STD_OK;
81  }
82  return result;
83 }
84 
86  int16_t baseCellVoltage,
87  int16_t redundancy0CellVoltage,
88  int16_t *pCellVoltage) {
89  STD_RETURN_TYPE_e retval = STD_OK;
90 
91  /* Pointer validity check */
92  FAS_ASSERT(pCellVoltage != NULL_PTR);
93 
94  if (abs(baseCellVoltage - redundancy0CellVoltage) > PL_CELL_VOLTAGE_TOLERANCE_mV) {
95  retval = STD_NOT_OK;
96  }
97  /* Take the average value of base and redundant measurement value */
98  *pCellVoltage = (baseCellVoltage + redundancy0CellVoltage) / 2;
99  return retval;
100 }
101 
103  int16_t baseCelltemperature,
104  int16_t redundancy0Celltemperature,
105  int16_t *pCelltemperature) {
106  /* Pointer validity check */
107  FAS_ASSERT(pCelltemperature != NULL_PTR);
108 
109  STD_RETURN_TYPE_e retval = STD_OK;
110 
111  if (abs(baseCelltemperature - redundancy0Celltemperature) > PL_CELL_TEMPERATURE_TOLERANCE_dK) {
112  retval = STD_NOT_OK;
113  }
114  /* Take the average value of base and redundant measurement value */
115  *pCelltemperature = (baseCelltemperature + redundancy0Celltemperature) / 2;
116  return retval;
117 }
118 
120  DATA_BLOCK_CELL_VOLTAGE_s *pCellvoltages,
121  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues) {
122  /* Pointer validity check */
123  FAS_ASSERT(pCellvoltages != NULL_PTR);
124  FAS_ASSERT(pMinMaxAverageValues != NULL_PTR);
125 
126  STD_RETURN_TYPE_e retval = STD_OK;
127 
128  /* Iterate over all cells */
129  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
130  STD_RETURN_TYPE_e plausibilityIssueDetected = STD_OK;
131  for (uint8_t m = 0u; m < BS_NR_OF_MODULES; m++) {
132  for (uint8_t c = 0u; c < BS_NR_OF_CELLS_PER_MODULE; c++) {
133  /* Only do check for valid voltages */
134  if ((pCellvoltages->invalidCellVoltage[s][m] & (0x01u << c)) == 0) {
135  if (abs(pCellvoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELLS_PER_MODULE) + c] -
136  pMinMaxAverageValues->averageCellVoltage_mV[s]) > PL_CELL_VOLTAGE_SPREAD_TOLERANCE_mV) {
137  /* Voltage difference too large */
138  plausibilityIssueDetected = STD_NOT_OK;
139  retval = STD_NOT_OK;
140  /* Set this cell voltage invalid */
141  pCellvoltages->invalidCellVoltage[s][m] |= (0x01u << c);
142  }
143  }
144  }
145  }
147  }
148  return retval;
149 }
150 
152  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatures,
153  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues) {
154  /* Pointer validity check */
155  FAS_ASSERT(pCellTemperatures != NULL_PTR);
156  FAS_ASSERT(pMinMaxAverageValues != NULL_PTR);
157 
158  STD_RETURN_TYPE_e retval = STD_OK;
159 
160  /* Iterate over all cells */
161  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
162  STD_RETURN_TYPE_e plausibilityIssueDetected = STD_OK;
163  for (uint8_t m = 0u; m < BS_NR_OF_MODULES; m++) {
164  for (uint8_t c = 0u; c < BS_NR_OF_TEMP_SENSORS_PER_MODULE; c++) {
165  /* Only do check for valid temperatures */
166  if ((pCellTemperatures->invalidCellTemperature[s][m] & (0x01u << c)) == 0) {
167  if (abs(pCellTemperatures->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c] -
168  (int16_t)pMinMaxAverageValues->averageTemperature_ddegC[s]) >
170  /* temperature difference too large */
171  plausibilityIssueDetected = STD_NOT_OK;
172  retval = STD_NOT_OK;
173  /* Set this cell temperature invalid */
174  pCellTemperatures->invalidCellTemperature[s][m] |= (0x01u << c);
175  } else {
176  pCellTemperatures->nrValidTemperatures[s]++;
177  }
178  }
179  }
180  }
182  }
183  return retval;
184 }
185 
186 /*========== Externalized Static Function Implementations (Unit Test) =======*/
Configuration of the battery system (e.g., number of battery modules, battery cells,...
#define BS_NR_OF_STRINGS
#define BS_NR_OF_CELLS_PER_MODULE
number of battery cells per battery module (parallel cells are counted as one)
#define BS_NR_OF_MODULES
number of modules in battery pack
#define BS_NR_OF_TEMP_SENSORS_PER_MODULE
number of temperature sensors per battery module
STD_RETURN_TYPE_e DIAG_CheckEvent(STD_RETURN_TYPE_e cond, DIAG_ID_e diag_id, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_CheckEvent provides a simple interface to check an event for STD_OK.
Definition: diag.c:353
Diagnosis driver header.
@ DIAG_STRING
Definition: diag_cfg.h:248
@ DIAG_ID_PLAUSIBILITY_CELL_TEMPERATURE_SPREAD
Definition: diag_cfg.h:174
@ DIAG_ID_PLAUSIBILITY_CELL_VOLTAGE_SPREAD
Definition: diag_cfg.h:173
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:237
math library for often used math functions
@ STD_NOT_OK
Definition: fstd_types.h:73
@ STD_OK
Definition: fstd_types.h:72
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:66
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
STD_RETURN_TYPE_e PL_CheckStringVoltage(int32_t voltageMic_mV, int32_t voltageCurrentSensor_mV)
Pack voltage plausibility check between LTC and current sensor values.
Definition: plausibility.c:73
STD_RETURN_TYPE_e PL_CheckTemperatureSpread(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatures, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Cell temperature spread plausibility check.
Definition: plausibility.c:151
STD_RETURN_TYPE_e PL_CheckCellvoltage(int16_t baseCellVoltage, int16_t redundancy0CellVoltage, int16_t *pCellVoltage)
Cell voltage plausibility check between two redundant cell voltage measurement values.
Definition: plausibility.c:85
STD_RETURN_TYPE_e PL_CheckCelltemperature(int16_t baseCelltemperature, int16_t redundancy0Celltemperature, int16_t *pCelltemperature)
Cell temperature plausibility check between two redundant cell temperature measurement values.
Definition: plausibility.c:102
STD_RETURN_TYPE_e PL_CheckVoltageSpread(DATA_BLOCK_CELL_VOLTAGE_s *pCellvoltages, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Cell voltage spread plausibility check.
Definition: plausibility.c:119
plausibility checks for cell voltage and cell temperatures
#define PL_CELL_TEMPERATURE_TOLERANCE_dK
Maximum difference between redundant cell temperature measurements in deci kelvin.
#define PL_CELL_VOLTAGE_TOLERANCE_mV
Maximum difference between redundant cell voltage measurement.
#define PL_STRING_VOLTAGE_TOLERANCE_mV
Maximum difference between pack voltage measurement from Measurement IC and current sensor.
#define PL_CELL_TEMPERATURE_SPREAD_TOLERANCE_dK
Maximum deviation between a single cell temperature measurement and the average cell temperature in d...
#define PL_CELL_VOLTAGE_SPREAD_TOLERANCE_mV
Maximum deviation between a single cell voltage measurement and the average cell voltage.
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS_PER_STRING]
Definition: database_cfg.h:138
uint16_t invalidCellTemperature[BS_NR_OF_STRINGS][BS_NR_OF_MODULES]
Definition: database_cfg.h:140
uint16_t nrValidTemperatures[BS_NR_OF_STRINGS]
Definition: database_cfg.h:141
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_BAT_CELLS]
Definition: database_cfg.h:123
uint64_t invalidCellVoltage[BS_NR_OF_STRINGS][BS_NR_OF_MODULES]
Definition: database_cfg.h:125
float averageTemperature_ddegC[BS_NR_OF_STRINGS]
Definition: database_cfg.h:175
int16_t averageCellVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:165