foxBMS  1.4.1
The foxBMS Battery Management System API Documentation
bender_ir155.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2022, 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 2022-10-27 (date of last update)
47  * @version v1.4.1
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 /*========== Macros and Definitions =========================================*/
65 
66 /**
67  * Dutycycle - resistance table
68  * for Bender IR155-3204 (Art. No. B91068139)
69  *
70  * dc | resistance/kOhm | description |
71  * ---|------------------|------------------------|
72  * 100| -63,16 | not valid |
73  * 98 | -38,71 | invalid |
74  * 95 | =0,00 | invalid |
75  * 95 | >0,00 | shortcut |
76  * 90 | 70,59 | very low resistance |
77  * 80 | 240,00 | low resistance |
78  * 70 | 461,54 | low resistance |
79  * 60 | 763,64 | lowmid resistance |
80  * 50 | 1200,00 | highmid resistance |
81  * 40 | 1885,71 | highmid resistance |
82  * 30 | 3120,00 | high resistance |
83  * 20 | 6000,00 | high resistance |
84  * 10 | 20400,00 | very high resistance |
85  * 5 | oo | very high resistance |
86  * 3 |-55200,00 | invalid |
87  * 0 |-22800,00 | invalid |
88  *
89  */
90 #define IR155_MINIMUM_INSULATION_RESISTANCE_kOhm (0u)
91 
92 /*========== Static Constant and Variable Definitions =======================*/
93 
94 /*========== Extern Constant and Variable Definitions =======================*/
95 
96 /*========== Static Function Prototypes =====================================*/
97 /** Initialize function for Bender IR155 driver */
99 
100 /** Acquire measurement results from Bender IR155 and write them into the database */
102 
103 /*========== Static Function Implementations ================================*/
105  /* Initialize Software-Module */
108 }
109 
111  FAS_ASSERT(pTableInsulationMonitoring != NULL_PTR);
112  pTableInsulationMonitoring->isInsulationMeasurementValid = true;
114  pTableInsulationMonitoring->areDeviceFlagsValid = true;
115  pTableInsulationMonitoring->dfIsCriticalResistanceDetected = false;
116  pTableInsulationMonitoring->dfIsChassisFaultDetected = false;
117  pTableInsulationMonitoring->dfIsDeviceErrorDetected = false;
118  /* Bender IR155 does not support a digital warning threshold -> check measured insulation resistance */
119  pTableInsulationMonitoring->dfIsWarnableResistanceDetected = false;
120 
121  /* Evaluate input pwm signal */
123 
124  /* Measurement is not valid, either because of startup delay or detected ground error before startup */
129  } else {
130  /* 0 < hysteresisCounter < measCycleTime
131  * Measurement is valid from that moment on */
133  }
134 
136  /* If hysteresis is over, reset diag flag and reset grounderror flag */
137  /* TODO: How to handle the ground error fault after reset? Do this in diag callback?*/
138  /* Reset non-volatile ground error flag - Do this in diag callback? */
140  }
141  }
142 
143  /* Evaluate if resistance measurement is valid or not */
145  /* Measurement result is not valid */
146  pTableInsulationMonitoring->isInsulationMeasurementValid = false;
147  } else {
148  pTableInsulationMonitoring->isInsulationMeasurementValid = true;
149  }
150 
151  /* Set measured resistance value */
153 
154  /* Evaluate device state */
157  /* Mark device flags and insulation measurement as invalid if a device error is detected */
158  pTableInsulationMonitoring->areDeviceFlagsValid = false;
159  pTableInsulationMonitoring->isInsulationMeasurementValid = false;
160  } else {
161  pTableInsulationMonitoring->areDeviceFlagsValid = true;
162  }
163 
164  /* Set error flag if Pin OHKS detects an error
165  * Pin state high: No fault; Insulation resistance > response value
166  * Pin state low: Insulation resistance <= response value detected;
167  * Device error; Fault in the earth connection
168  * Undervoltage detected or device switched off
169  */
171  pTableInsulationMonitoring->dfIsCriticalResistanceDetected = true;
172  } else {
173  pTableInsulationMonitoring->dfIsCriticalResistanceDetected = false;
174  }
175 
176  /* Check for device error: invalid measurement period or duty-cycle detected */
181  pTableInsulationMonitoring->dfIsDeviceErrorDetected = true;
182  } else {
183  pTableInsulationMonitoring->dfIsDeviceErrorDetected = false;
184  }
185 
186  /* Check for chassis fault */
187  pTableInsulationMonitoring->dfIsChassisShortToHvPlus = false; /* This feature is not supported by the device */
188  pTableInsulationMonitoring->dfIsChassisShortToHvMinus = false; /* This feature is not supported by the device */
190  pTableInsulationMonitoring->dfIsChassisFaultDetected = true;
191  } else {
192  pTableInsulationMonitoring->dfIsDeviceErrorDetected = false;
193  }
194 
195  /* No digital signal for warning threshold available for this device -> use measured insulation resistance */
197  pTableInsulationMonitoring->dfIsWarnableResistanceDetected = true;
198  } else {
199  pTableInsulationMonitoring->dfIsWarnableResistanceDetected = false;
200  }
201 
202  /* TODO: bool dfIsMeasurmentedUpToDate; Check if measurement result is up to data */
203  return IMD_FSM_STATE_RUNNING;
204 }
205 
206 /*========== Extern Function Implementations ================================*/
208  return IR155_InitializeModule();
209 }
210 
212  /* Enable supply for Bender */
214  return IMD_FSM_STATE_RUNNING;
215 }
216 
218  FAS_ASSERT(pTableInsulationMonitoring != NULL_PTR);
219  return IR155_MeasureInsulation(pTableInsulationMonitoring);
220 }
221 
223  /* Disable supply for Bender */
226 }
227 
228 /*========== Externalized Static Function Implementations (Unit Test) =======*/
#define IR155_MINIMUM_INSULATION_RESISTANCE_kOhm
Definition: bender_ir155.c:90
IMD_FSM_STATES_e IMD_ProcessInitializationState(void)
Processes the initialization state.
Definition: bender_ir155.c:207
static IMD_FSM_STATES_e IR155_InitializeModule(void)
Definition: bender_ir155.c:104
IMD_FSM_STATES_e IMD_ProcessShutdownState(void)
Processes the shutdown state.
Definition: bender_ir155.c:222
IMD_FSM_STATES_e IMD_ProcessEnableState(void)
Processes the IMD enable state.
Definition: bender_ir155.c:211
static IMD_FSM_STATES_e IR155_MeasureInsulation(DATA_BLOCK_INSULATION_MONITORING_s *pTableInsulationMonitoring)
Definition: bender_ir155.c:110
IMD_FSM_STATES_e IMD_ProcessRunningState(DATA_BLOCK_INSULATION_MONITORING_s *pTableInsulationMonitoring)
Processes the running state.
Definition: bender_ir155.c:217
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_GROUND_ERROR_MODE_UNKNOWN
@ IR155_IMD_ERROR_MEASUREMENT_UNKNOWN
@ IR155_UNDERVOLTAGE_MEASUREMENT_UNKNOWN
@ IR155_IMD_ERROR_MEASUREMENT
@ IR155_RESISTANCE_ESTIMATION_UNKNOWN
@ IR155_MEASUREMENT_NOT_VALID
@ IR155_RESISTANCE_MEASUREMENT_UNKNOWN
@ IR155_GROUND_ERROR_MODE
Database module header.
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:252
Header for the driver for the FRAM module.
FRAM_INSULATION_FLAG_s fram_insulationFlags
Definition: fram_cfg.c:77
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:76
@ STD_PIN_LOW
Definition: fstd_types.h:88
#define IMD_WARNING_THRESHOLD_INSULATION_RESISTANCE_kOhm
Definition: imd.h:73
IMD_FSM_STATES_e
Definition: imd.h:92
@ IMD_FSM_STATE_RUNNING
Definition: imd.h:99
@ IMD_FSM_STATE_IMD_ENABLE
Definition: imd.h:97
#define IMD_PERIODIC_CALL_TIME_ms
Definition: imd.h:67
void IO_PinSet(volatile uint32_t *pRegisterAddress, uint32_t pin)
Set pin by writing in pin output register.
Definition: io.c:87
void IO_PinReset(volatile uint32_t *pRegisterAddress, uint32_t pin)
Reset pin by writing in pin output register.
Definition: io.c:94
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