foxBMS - Unit Tests  1.2.0
The foxBMS Unit Tests API Documentation
soc_counting.c File Reference

SOC module responsible for calculation of SOC. More...

#include "soc_counting.h"
#include "bms.h"
#include "database.h"
#include "foxmath.h"
#include "fram.h"
Include dependency graph for soc_counting.c:

Go to the source code of this file.

Data Structures

struct  SOC_STATE
 

Macros

#define MAXIMUM_SOC_PERC   (100.0f)
 
#define MINIMUM_SOC_PERC   (0.0f)
 

Typedefs

typedef struct SOC_STATE SOC_STATE_s
 

Functions

static float SOC_GetStringSocPercentageFromCharge (uint32_t charge_As)
 calculates string SOC in percentage from passed string charge in As More...
 
static void SOC_RecalibrateViaLookupTable (DATA_BLOCK_SOX_s *pTableSoc)
 initializes database and FRAM SOC values via lookup table (average, minimum and maximum). More...
 
static void SOC_SetValue (DATA_BLOCK_SOX_s *pTableSoc, float socMinimumValue_perc, float socMaximumValue_perc, float socAverageValue_perc, uint8_t stringNumber)
 sets SOC value with a parameter between 0.0 and 100.0. More...
 
static void SOC_CheckDatabaseSocPercentageLimits (DATA_BLOCK_SOX_s *pTableSoc, uint8_t stringNumber)
 Check if all database SOC percentage values are within [0.0, 100.0] Limits SOC values to limit values if outside of this range. More...
 
static void SOC_UpdateNvmValues (DATA_BLOCK_SOX_s *pTableSoc, uint8_t stringNumber)
 Set SOC-related values in non-volatile memory. More...
 
void SOC_Init (DATA_BLOCK_SOX_s *pSocValues, bool ccPresent, uint8_t stringNumber)
 initializes startup SOC-related values like lookup from nonvolatile ram at startup More...
 
void SOC_Calculation (DATA_BLOCK_SOX_s *pSocValues)
 periodically called algorithm to calculate state-of-charge (SOC) More...
 
float SOC_GetFromVoltage (int16_t voltage_mV)
 look-up table for SOC initialization More...
 

Variables

static SOC_STATE_s soc_state
 
static DATA_BLOCK_CURRENT_SENSOR_s soc_tableCurrentSensor = {.header.uniqueId = DATA_BLOCK_ID_CURRENT_SENSOR}
 

Detailed Description

SOC module responsible for calculation of SOC.

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®″
Author
foxBMS Team
Date
2020-10-07 (date of creation)
Updated
2021-08-06 (date of last update)
Prefix
SOC

Definition in file soc_counting.c.

Macro Definition Documentation

◆ MAXIMUM_SOC_PERC

#define MAXIMUM_SOC_PERC   (100.0f)

defines for maximum and minimum SOC

Definition at line 74 of file soc_counting.c.

◆ MINIMUM_SOC_PERC

#define MINIMUM_SOC_PERC   (0.0f)

Definition at line 75 of file soc_counting.c.

Typedef Documentation

◆ SOC_STATE_s

typedef struct SOC_STATE SOC_STATE_s

This structure contains all the variables relevant for the SOX

Function Documentation

◆ SOC_Calculation()

void SOC_Calculation ( DATA_BLOCK_SOX_s pSocValues)

periodically called algorithm to calculate state-of-charge (SOC)

Parameters
[out]pSocValuespointer to SOC values

Definition at line 278 of file soc_counting.c.

Here is the call graph for this function:

◆ SOC_CheckDatabaseSocPercentageLimits()

static void SOC_CheckDatabaseSocPercentageLimits ( DATA_BLOCK_SOX_s pTableSoc,
uint8_t  stringNumber 
)
static

Check if all database SOC percentage values are within [0.0, 100.0] Limits SOC values to limit values if outside of this range.

Parameters
[in,out]pTableSocpointer to database struct with SOC values
[in]stringNumberstring that is checked

Definition at line 202 of file soc_counting.c.

◆ SOC_GetFromVoltage()

float SOC_GetFromVoltage ( int16_t  voltage_mV)

look-up table for SOC initialization

Parameters
[in]voltage_mVvoltage in mV of battery cell
Returns
returns SOC value in percentage from 0.0% to 100.0%

Definition at line 368 of file soc_counting.c.

Here is the call graph for this function:

◆ SOC_GetStringSocPercentageFromCharge()

static float SOC_GetStringSocPercentageFromCharge ( uint32_t  charge_As)
static

calculates string SOC in percentage from passed string charge in As

Parameters
[in]charge_Ascharge in As
Returns
returns corresponding string SOC in percentage [0.0, 100.0]

Definition at line 145 of file soc_counting.c.

◆ SOC_Init()

void SOC_Init ( DATA_BLOCK_SOX_s pSocValues,
bool  cc_present,
uint8_t  stringNumber 
)

initializes startup SOC-related values like lookup from nonvolatile ram at startup

Parameters
[out]pSocValuespointer to SOC database entry
[in]cc_presenttrue if current sensor present, false otherwise
[in]stringNumberstring addressed

Definition at line 236 of file soc_counting.c.

Here is the call graph for this function:

◆ SOC_RecalibrateViaLookupTable()

static void SOC_RecalibrateViaLookupTable ( DATA_BLOCK_SOX_s pTableSoc)
static

initializes database and FRAM SOC values via lookup table (average, minimum and maximum).

Parameters
[out]pTableSocpointer to database enty with SOC values

Definition at line 150 of file soc_counting.c.

Here is the call graph for this function:

◆ SOC_SetValue()

static void SOC_SetValue ( DATA_BLOCK_SOX_s pTableSoc,
float  socMinimumValue_perc,
float  socMaximumValue_perc,
float  socAverageValue_perc,
uint8_t  stringNumber 
)
static

sets SOC value with a parameter between 0.0 and 100.0.

limits the SOE value to 0.0 respectively 100.0 if a value outside of the allowed SOE range is passed. Updates local fram and database struct but does NOT write them

Parameters
[out]pTableSocpointer to SOC database entry
[in]socMinimumValue_percSOC min value to set
[in]socMaximumValue_percSOC max value to set
[in]socAverageValue_percSOC average value to set
[in]stringNumberaddressed string

Definition at line 166 of file soc_counting.c.

Here is the call graph for this function:

◆ SOC_UpdateNvmValues()

static void SOC_UpdateNvmValues ( DATA_BLOCK_SOX_s pTableSoc,
uint8_t  stringNumber 
)
static

Set SOC-related values in non-volatile memory.

Parameters
[in]pTableSocpointer to database struct with SOC values
[in]stringNumberaddressed string

Definition at line 226 of file soc_counting.c.

Variable Documentation

◆ soc_state

SOC_STATE_s soc_state
static
Initial value:
= {
.socInitialized = false,
.sensorCcUsed = {REPEAT_U(false, STRIP(BS_NR_OF_STRINGS))},
.ccScalingAverage = {REPEAT_U(0.0f, STRIP(BS_NR_OF_STRINGS))},
.ccScalingMinimum = {REPEAT_U(0.0f, STRIP(BS_NR_OF_STRINGS))},
.ccScalingMaximum = {REPEAT_U(0.0f, STRIP(BS_NR_OF_STRINGS))},
.previousTimestamp = {REPEAT_U(0u, STRIP(BS_NR_OF_STRINGS))},
}
#define BS_NR_OF_STRINGS
#define STRIP(x)
Definition: general.h:274
#define REPEAT_U(x, n)
Macro that helps to generate a series of literals (for array initializers).
Definition: general.h:262

state variable for SOC module

Definition at line 79 of file soc_counting.c.

◆ soc_tableCurrentSensor

DATA_BLOCK_CURRENT_SENSOR_s soc_tableCurrentSensor = {.header.uniqueId = DATA_BLOCK_ID_CURRENT_SENSOR}
static

local copies of database tables

Definition at line 90 of file soc_counting.c.