foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
bender_ir155.c
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 bender_ir155.c
44  * @author foxBMS Team
45  * @date 2014-02-11 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup DRIVERS
49  * @prefix IR155
50  *
51  * @brief Driver for the insulation monitoring
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "bender_ir155.h"
56 
57 #include "bender_ir155_cfg.h"
58 
59 #include "bender_ir155_helper.h"
60 #include "database.h"
61 #include "fram.h"
62 #include "io.h"
63 
64 #include <stdbool.h>
65 #include <stdint.h>
66 
67 /*========== Macros and Definitions =========================================*/
68 
69 /**
70  * Duty cycle - resistance table
71  * for Bender IR155-3204 (Art. No. B91068139)
72  *
73  * dc | resistance/kOhm | description |
74  * ---|------------------|------------------------|
75  * 100| -63,16 | not valid |
76  * 98 | -38,71 | invalid |
77  * 95 | =0,00 | invalid |
78  * 95 | >0,00 | shortcut |
79  * 90 | 70,59 | very low resistance |
80  * 80 | 240,00 | low resistance |
81  * 70 | 461,54 | low resistance |
82  * 60 | 763,64 | lowmid resistance |
83  * 50 | 1200,00 | highmid resistance |
84  * 40 | 1885,71 | highmid resistance |
85  * 30 | 3120,00 | high resistance |
86  * 20 | 6000,00 | high resistance |
87  * 10 | 20400,00 | very high resistance |
88  * 5 | oo | very high resistance |
89  * 3 |-55200,00 | invalid |
90  * 0 |-22800,00 | invalid |
91  *
92  */
93 #define IR155_MINIMUM_INSULATION_RESISTANCE_kOhm (0u)
94 
95 /*========== Static Constant and Variable Definitions =======================*/
96 
97 /*========== Extern Constant and Variable Definitions =======================*/
98 
99 /*========== Static Function Prototypes =====================================*/
100 /** Initialize function for Bender IR155 driver */
102 
103 /** Acquire measurement results from Bender IR155 and write them into the database */
105 
106 /*========== Static Function Implementations ================================*/
108  /* Initialize Software-Module */
111 }
112 
114  FAS_ASSERT(pTableInsulationMonitoring != NULL_PTR);
115  pTableInsulationMonitoring->isInsulationMeasurementValid = true;
117  pTableInsulationMonitoring->areDeviceFlagsValid = true;
118  pTableInsulationMonitoring->dfIsCriticalResistanceDetected = false;
119  pTableInsulationMonitoring->dfIsChassisFaultDetected = false;
120  pTableInsulationMonitoring->dfIsDeviceErrorDetected = false;
121  /* Bender IR155 does not support a digital warning threshold -> check measured insulation resistance */
122  pTableInsulationMonitoring->dfIsWarnableResistanceDetected = false;
123 
124  /* Evaluate input pwm signal */
126 
127  /* Measurement is not valid, either because of startup delay or detected ground error before startup */
132  } else {
133  /* 0 < hysteresisCounter < measCycleTime
134  * Measurement is valid from that moment on */
136  }
137 
139  /* If hysteresis is over, reset diag flag and reset ground error flag */
140  /* TODO: How to handle the ground error fault after reset? Do this in diag callback?*/
141  /* Reset non-volatile ground error flag - Do this in diag callback? */
143  }
144  }
145 
146  /* Evaluate if resistance measurement is valid or not */
148  /* Measurement result is not valid */
149  pTableInsulationMonitoring->isInsulationMeasurementValid = false;
150  } else {
151  pTableInsulationMonitoring->isInsulationMeasurementValid = true;
152  }
153 
154  /* Set measured resistance value */
156 
157  /* Evaluate device state */
160  /* Mark device flags and insulation measurement as invalid if a device error is detected */
161  pTableInsulationMonitoring->areDeviceFlagsValid = false;
162  pTableInsulationMonitoring->isInsulationMeasurementValid = false;
163  } else {
164  pTableInsulationMonitoring->areDeviceFlagsValid = true;
165  }
166 
167  /* Set error flag if Pin OHKS detects an error
168  * Pin state high: No fault; Insulation resistance > response value
169  * Pin state low: Insulation resistance <= response value detected;
170  * Device error; Fault in the earth connection
171  * Undervoltage detected or device switched off
172  */
174  pTableInsulationMonitoring->dfIsCriticalResistanceDetected = true;
175  } else {
176  pTableInsulationMonitoring->dfIsCriticalResistanceDetected = false;
177  }
178 
179  /* Check for device error: invalid measurement period or duty-cycle detected */
184  pTableInsulationMonitoring->dfIsDeviceErrorDetected = true;
185  } else {
186  pTableInsulationMonitoring->dfIsDeviceErrorDetected = false;
187  }
188 
189  /* Check for chassis fault */
190  pTableInsulationMonitoring->dfIsChassisShortToHvPlus = false; /* This feature is not supported by the device */
191  pTableInsulationMonitoring->dfIsChassisShortToHvMinus = false; /* This feature is not supported by the device */
193  pTableInsulationMonitoring->dfIsChassisFaultDetected = true;
194  } else {
195  pTableInsulationMonitoring->dfIsDeviceErrorDetected = false;
196  }
197 
198  /* No digital signal for warning threshold available for this device -> use measured insulation resistance */
200  pTableInsulationMonitoring->dfIsWarnableResistanceDetected = true;
201  } else {
202  pTableInsulationMonitoring->dfIsWarnableResistanceDetected = false;
203  }
204 
205  /* TODO: bool dfIsMeasurementUpToDate; Check if measurement result is up to data */
206  return IMD_FSM_STATE_RUNNING;
207 }
208 
209 /*========== Extern Function Implementations ================================*/
211  return IR155_InitializeModule();
212 }
213 
215  /* Enable supply for Bender */
217  return IMD_FSM_STATE_RUNNING;
218 }
219 
221  FAS_ASSERT(pTableInsulationMonitoring != NULL_PTR);
222  return IR155_MeasureInsulation(pTableInsulationMonitoring);
223 }
224 
226  /* Disable supply for Bender */
229 }
230 
231 /*========== Externalized Static Function Implementations (Unit Test) =======*/
232 #ifdef UNITY_UNIT_TEST
233 #endif
#define IR155_MINIMUM_INSULATION_RESISTANCE_kOhm
Definition: bender_ir155.c:93
IMD_FSM_STATES_e IMD_ProcessInitializationState(void)
Processes the initialization state.
Definition: bender_ir155.c:210
static IMD_FSM_STATES_e IR155_InitializeModule(void)
Definition: bender_ir155.c:107
IMD_FSM_STATES_e IMD_ProcessShutdownState(void)
Processes the shutdown state.
Definition: bender_ir155.c:225
IMD_FSM_STATES_e IMD_ProcessEnableState(void)
Processes the IMD enable state.
Definition: bender_ir155.c:214
static IMD_FSM_STATES_e IR155_MeasureInsulation(DATA_BLOCK_INSULATION_MONITORING_s *pTableInsulationMonitoring)
Definition: bender_ir155.c:113
IMD_FSM_STATES_e IMD_ProcessRunningState(DATA_BLOCK_INSULATION_MONITORING_s *pTableInsulationMonitoring)
Processes the running state.
Definition: bender_ir155.c:220
Headers for the Bender IR155 driver for the insulation monitoring.
Headers for the configuration for the insulation monitoring.
#define IR155_SUPPLY_ENABLE_PORT
#define IR155_SUPPLY_ENABLE_PIN
void IR155_Initialize(uint8_t triggerTime_ms)
Software initialization of Timer-module.
IR155_MEASUREMENT_s IR155_GetMeasurementValues(void)
Interface function which delivers the actual signal measurement (duty cyle) and evaluation....
IR155_STATE_s ir155_state
Headers for the configuration for the insulation monitoring.
@ IR155_IMD_ERROR_MEASUREMENT_UNKNOWN
@ IR155_UNDERVOLTAGE_MEASUREMENT_UNKNOWN
@ IR155_IMD_ERROR_MEASUREMENT
@ IR155_RESISTANCE_ESTIMATION_UNKNOWN
@ IR155_GROUND_ERROR_STATE_UNKNOWN
@ IR155_MEASUREMENT_NOT_VALID
@ IR155_RESISTANCE_MEASUREMENT_UNKNOWN
@ IR155_GROUND_ERROR_STATE
Database module header.
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:255
Header for the driver for the FRAM module.
FRAM_INSULATION_FLAG_s fram_insulationFlags
Definition: fram_cfg.c:79
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:77
@ STD_PIN_LOW
Definition: fstd_types.h:89
#define IMD_WARNING_THRESHOLD_INSULATION_RESISTANCE_kOhm
Definition: imd.h:74
IMD_FSM_STATES_e
Definition: imd.h:93
@ IMD_FSM_STATE_RUNNING
Definition: imd.h:100
@ IMD_FSM_STATE_IMD_ENABLE
Definition: imd.h:98
#define IMD_PERIODIC_CALL_TIME_ms
Definition: imd.h:68
void IO_PinSet(volatile uint32_t *pRegisterAddress, uint32_t pin)
Set pin by writing in pin output register.
Definition: io.c:91
void IO_PinReset(volatile uint32_t *pRegisterAddress, uint32_t pin)
Reset pin by writing in pin output register.
Definition: io.c:98
Header for the driver for the IO module.
STD_PIN_STATE_e digitalStatusPin
IR155_MEASUREMENT_STATE_e measurementState
uint16_t periodTriggerTime_ms
IR155_MEASUREMENT_s measurement
uint32_t timeUntilValidMeasurement_ms