4.24. Insulation Measurement Device

Several different Insulation Measurement Devices (IMD) are supported.

A superimposed state machine is implemented that interacts with the actual IMD implementation. There a different reasons for the state machine to transition between the states. Generally three cases can happen:

  • an external request to the state machine is received to either initialize the IMD or to start/stop the insulation resistance measurement

  • the IMD implementation request a transition e.g., when the initialization is finished

  • inherent determined transitions e.g., IMD_FSM_STATE_HAS_NEVER_RUN transitions to state IMD_FSM_STATE_UNINITIALIZED

The state machine consists of the following states:

  • IMD_FSM_STATE_HAS_NEVER_RUN

  • IMD_FSM_STATE_UNINITIALIZED

  • IMD_FSM_STATE_INITIALIZATION

  • IMD_FSM_STATE_IMD_ENABLE

  • IMD_FSM_STATE_SHUTDOWN

  • IMD_FSM_STATE_RUNNING

  • IMD_FSM_STATE_ERROR

The transitions between the main states of the IMD state machine is depicted below.

# Copyright (c) 2010 - 2023, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
#    list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
#    contributors may be used to endorse or promote products derived from
#    this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# We kindly request you to use one or more of the following phrases to refer to
# foxBMS in your hardware, software, documentation or advertising materials:
#
# - "This product uses parts of foxBMS®"
# - "This product includes parts of foxBMS®"
# - "This product is derived from foxBMS®"

digraph imd_fsm {
    rankdir=TB;
    size="8,16"
    compound=true;
    node [shape = doublecircle]     nd_initialization
                                    nd_imd_enable;
                                    nd_shutdown;
                                    nd_running;
    node [shape = circle]           nd_never_run
                                    nd_uninitialized
                                    nd_error

    nd_never_run                    [label=<<B>Startup</B>>];
    nd_uninitialized                [label=<<B>Uninitialized</B>>];
    nd_initialization               [label=<<B>Initialization </B>>];
    nd_imd_enable                   [label=<<B>IMD enable</B>>];
    nd_running                      [label=<<B>Running</B>>];
    nd_shutdown                     [label=<<B>Shutdown</B>>];
    nd_error                        [label=<<B>Error</B>>];

    nd_never_run -> nd_uninitialized
    nd_uninitialized -> nd_initialization  [label=<<B>Request</B>>];
    nd_initialization -> nd_imd_enable
    nd_initialization -> nd_error
    nd_imd_enable -> nd_running  [label=<<B>Request</B>>];
    nd_imd_enable -> nd_error
    nd_running -> nd_running
    nd_running -> nd_shutdown  [label=<<B>Request</B>>];
    nd_running -> nd_error
    nd_shutdown -> nd_imd_enable
    nd_shutdown -> nd_error
}

Fig. 4.9 IMD state flow diagram

These transitions will either be performed automatically or on request. The following requests can be made to the state machine:

  • IMD_STATE_INITIALIZE_REQUEST

  • IMD_STATE_SWITCH_ON_REQUEST

  • IMD_STATE_SHUTDOWN_REQUEST

4.24.4. Brief state machine description

The state machine trigger function IMD_Trigger() is called periodically from the 100|_||ms| task. It starts in state IMD_FSM_STATE_HAS_NEVER_RUN after startup and transitions with the next call automatically to state IMD_FSM_STATE_UNINITIALIZED. The state machine waits in this state until the IMD_STATE_INITIALIZE_REQUEST has been submitted to the state machine during the startup phase from the sys module. The state machine transitions to state IMD_FSM_STATE_IMD_ENABLE after a successful initialization of the required peripherals and the software modules of the selected IMD driver implementation in state IMD_FSM_STATE_INITIALIZATION. Now, the state machine waits again to receive the IMD_STATE_SWITCH_ON_REQUEST from the application state machine activate the IMD device and begin with the insulation resistance measurement and the evaluation of the measurement results from IMD. The state machine continuously monitors the insulation resistance of the battery system in this state until the IMD_STATE_SHUTDOWN_REQUEST is submitted to the state machine. This can be necessary to prevent a mutual interference if multiple insulation monitoring devices would be monitoring the battery system, e.g., when a vehicle is connected to a charging station.

4.24.5. Description of the IMD state machine

In the following, the implementations of all cases are explained in detail.

4.24.5.1. IMD_FSM_STATE_HAS_NEVER_RUN

This is the default state after the startup of the BMS. The state machine will immediately transition to state IMD_FSM_STATE_UNINITIALIZED with the next call.

4.24.5.2. IMD_FSM_STATE_UNINITIALIZED

The state machine will wait until an IMD_STATE_INITIALIZE_REQUEST is received. This request is submitted from the sys state machine during the startup phase of the BMS.

4.24.5.3. IMD_FSM_STATE_INITIALIZATION

The IMD_FSM_STATE_INITIALIZATION state is responsible to only initialize the required peripherals and the software module of the selected IMD to prepare the module for the measurement. The actual measurement of the IMD shall not be started. The state machine will switch to IMD_FSM_STATE_ERROR in case an error is detected during the initialization. The interface is utilized using function IMD_ProcessInitializationState.

4.24.5.4. IMD_FSM_STATE_IMD_ENABLE

This state is responsible to activate the IMD device and start the insulation measurement after a successful initialization. Before this is done, the state request IMD_STATE_SWITCH_ON_REQUEST need to be submitted to the state machine. In the default software, this will be done by the bms state machine during its initialization phase. The imd state machine will switch to IMD_FSM_STATE_ERROR in case an error is detected during the activation. The state machine will switch to IMD_FSM_STATE_RUNNING once the IMD is enabled. The function IMD_ProcessEnableState provides the required interface for the IMD implementation.

4.24.5.5. IMD_FSM_STATE_SHUTDOWN

The insulation measurement and the IMD are switched off in this case using the interface function IMD_ProcessShutdownState. If this this successful, state IMD_FSM_STATE_IMD_ENABLE is executed next, otherwise a transition into state IMD_FSM_STATE_ERROR will be done.

4.24.5.6. IMD_FSM_STATE_RUNNING

This the main state of the superimposed IMD state machine. This state acquires the measurement results from the selected IMD implementation using the function IMD_ProcessRunningState() and evaluates the measurement results in function IMD_EvaluateInsulationMeasurement. This way the evaluation is encapsulated from the insulation measurement performed by the IMD. Additionally, the state machine will react on a IMD_STATE_SHUTDOWN_REQUEST request and subsequently switch to state IMD_FSM_STATE_SHUTDOWN.

4.24.5.7. IMD_FSM_STATE_ERROR

This section of the documentation is not yet complete.

4.24.6. Interfaces for IMD driver implementation

The following functions are used to interface the actual IMD implementation:

Listing 4.8 Interface description for IMD implementations
 1/**
 2 * @brief   Processes the initialization state
 3 * @details This function needs to be implemented in the dedicated driver. This
 4 *          function initializes the required SW modules and peripherals but
 5 *          does not start the actual IMD measurement.
 6 * @return  #IMD_FSM_STATE_INITIALIZATION if initialization not finished and
 7 *          another call is required. #IMD_FSM_STATE_IMD_ENABLE if
 8 *          initialization is finished and #IMD_FSM_STATE_ERROR if an error is
 9 *          detected that prohibits a working IMD driver.
10 */
11extern IMD_FSM_STATES_e IMD_ProcessInitializationState(void);
12
13/**
14 * @brief   Processes the IMD enable state
15 * @details This function needs to be implemented in the dedicated driver. This
16 *          function enables the actual IMD device to start the insulation
17 *          measurement. Functionality need to be fulfilled after one call.
18 * @return  #IMD_FSM_STATE_RUNNING if startup has been completed. Returns #IMD_FSM_STATE_ERROR if an error is
19 *          detected that prohibits a working IMD driver.
20 */
21extern IMD_FSM_STATES_e IMD_ProcessEnableState(void);
22
23/**
24 * @brief   Processes the running state
25 * @details This function needs to be implemented in the dedicated driver
26 * @param   pTableInsulationMonitoring   pointer to insulation monitoring
27 *                                       database entry
28 * @return  #IMD_FSM_STATE_RUNNING if measurement works as expected, otherwise
29 *          #IMD_FSM_STATE_ERROR if an error is detected that prohibits a
30 *          further execution of the IMD driver.
31 */
32extern IMD_FSM_STATES_e IMD_ProcessRunningState(DATA_BLOCK_INSULATION_MONITORING_s *pTableInsulationMonitoring);
33
34/**
35 * @brief   Processes the shutdown state
36 * @details This function needs to be implemented in the dedicated driver. This
37 *          function disables the actual IMD device to stop the insulation
38 *          measurement.
39 * @return  #IMD_FSM_STATE_SHUTDOWN if shutdown state is not finished and
40 *          another call is required. #IMD_FSM_STATE_IMD_ENABLE if shut down
41 *          has been completed and #IMD_FSM_STATE_ERROR if an error is detected
42 *          that prohibits a working IMD driver.
43 */
44extern IMD_FSM_STATES_e IMD_ProcessShutdownState(void);