foxBMS  1.0.0
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
4  * angewandten Forschung e.V. All rights reserved.
5  *
6  * BSD 3-Clause License
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * We kindly request you to use one or more of the following phrases to refer
31  * to foxBMS in your hardware, software, documentation or advertising
32  * materials:
33  *
34  * ″This product uses parts of foxBMS®″
35  *
36  * ″This product includes parts of foxBMS®″
37  *
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) =======*/
DATA_BLOCK_CELL_TEMPERATURE::nrValidTemperatures
uint16_t nrValidTemperatures[BS_NR_OF_STRINGS]
Definition: database_cfg.h:140
PL_CheckVoltageSpread
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
BS_NR_OF_MODULES
#define BS_NR_OF_MODULES
number of modules in battery pack
Definition: battery_system_cfg.h:96
STD_RETURN_TYPE_e
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
diag.h
Diagnosis driver header.
BS_NR_OF_TEMP_SENSORS_PER_MODULE
#define BS_NR_OF_TEMP_SENSORS_PER_MODULE
number of temperature sensors per battery module
Definition: battery_system_cfg.h:153
battery_system_cfg.h
Configuration of the battery system (e.g., number of battery modules, battery cells,...
DIAG_ID_PLAUSIBILITY_CELL_TEMPERATURE_SPREAD
@ DIAG_ID_PLAUSIBILITY_CELL_TEMPERATURE_SPREAD
Definition: diag_cfg.h:141
BS_NR_OF_CELLS_PER_MODULE
#define BS_NR_OF_CELLS_PER_MODULE
number of battery cells per battery module (parallel cells are counted as one)
Definition: battery_system_cfg.h:104
DATA_BLOCK_MIN_MAX::averageCellVoltage_mV
int16_t averageCellVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:164
PL_CELL_TEMPERATURE_SPREAD_TOLERANCE_dK
#define PL_CELL_TEMPERATURE_SPREAD_TOLERANCE_dK
Maximum deviation between a single cell temperature measurement and the average cell temperature in d...
Definition: plausibility_cfg.h:108
PL_CELL_TEMPERATURE_TOLERANCE_dK
#define PL_CELL_TEMPERATURE_TOLERANCE_dK
Maximum difference between redundant cell temperature measurements in deci kelvin.
Definition: plausibility_cfg.h:88
DATA_BLOCK_MIN_MAX::averageTemperature_ddegC
float averageTemperature_ddegC[BS_NR_OF_STRINGS]
Definition: database_cfg.h:174
FAS_ASSERT
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:237
PL_CELL_VOLTAGE_TOLERANCE_mV
#define PL_CELL_VOLTAGE_TOLERANCE_mV
Maximum difference between redundant cell voltage measurement.
Definition: plausibility_cfg.h:78
PL_CheckTemperatureSpread
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
PL_CheckCelltemperature
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
DIAG_STRING
@ DIAG_STRING
Definition: diag_cfg.h:215
foxmath.h
math library for often used math functions
STD_OK
@ STD_OK
Definition: fstd_types.h:72
DIAG_CheckEvent
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:326
STD_NOT_OK
@ STD_NOT_OK
Definition: fstd_types.h:73
DATA_BLOCK_CELL_VOLTAGE::cellVoltage_mV
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_BAT_CELLS]
Definition: database_cfg.h:122
DATA_BLOCK_CELL_TEMPERATURE::invalidCellTemperature
uint16_t invalidCellTemperature[BS_NR_OF_STRINGS][BS_NR_OF_MODULES]
Definition: database_cfg.h:139
DATA_BLOCK_CELL_VOLTAGE::invalidCellVoltage
uint64_t invalidCellVoltage[BS_NR_OF_STRINGS][BS_NR_OF_MODULES]
Definition: database_cfg.h:124
DATA_BLOCK_CELL_TEMPERATURE
Definition: database_cfg.h:131
PL_CheckCellvoltage
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
DATA_BLOCK_CELL_VOLTAGE
Definition: database_cfg.h:115
DIAG_ID_PLAUSIBILITY_CELL_VOLTAGE_SPREAD
@ DIAG_ID_PLAUSIBILITY_CELL_VOLTAGE_SPREAD
Definition: diag_cfg.h:140
DATA_BLOCK_MIN_MAX
Definition: database_cfg.h:158
NULL_PTR
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:66
PL_STRING_VOLTAGE_TOLERANCE_mV
#define PL_STRING_VOLTAGE_TOLERANCE_mV
Maximum difference between pack voltage measurement from Measurement IC and current sensor.
Definition: plausibility_cfg.h:69
BS_NR_OF_STRINGS
#define BS_NR_OF_STRINGS
Definition: battery_system_cfg.h:89
plausibility.h
plausibility checks for cell voltage and cell temperatures
DATA_BLOCK_CELL_TEMPERATURE::cellTemperature_ddegC
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS]
Definition: database_cfg.h:137
PL_CELL_VOLTAGE_SPREAD_TOLERANCE_mV
#define PL_CELL_VOLTAGE_SPREAD_TOLERANCE_mV
Maximum deviation between a single cell voltage measurement and the average cell voltage.
Definition: plausibility_cfg.h:98
PL_CheckStringVoltage
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