Implement SoC estimation (UNTESTED!)

This commit is contained in:
jazzpi
2022-07-03 23:47:14 +02:00
parent b1c21a981c
commit 1d70429708
7 changed files with 135 additions and 5 deletions

View File

@ -25,7 +25,8 @@
#define TOGGLE_STATUS_LED 0x06
#define NUMBEROFSLAVES 6
#define NUMBEROFCELLS 10
#define N_CELLS_SERIES 10
#define N_CELLS_PARALLEL 9
#define NUMBEROFTEMPS 32
#define SLAVE_TIMEOUT 200
@ -33,7 +34,7 @@
typedef struct {
uint16_t slaveID;
uint16_t cellVoltages[NUMBEROFCELLS];
uint16_t cellVoltages[N_CELLS_SERIES];
uint16_t cellTemps[NUMBEROFTEMPS];
uint32_t timestamp;
uint8_t error;

15
Core/Inc/SoC_Estimation.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef INC_SOC_ESTIMATION_H
#define INC_SOC_ESTIMATION_H
#include "SPI_Communication.h"
#define SOCE_SHUNT_CURRENT_OFF_THRESH 20 /* mA */
#define CELL_VOLTAGE_CONVERSION_FACTOR 5.0f / 65535 /* V/quantum */
#define BATTERY_CAPACITY (N_CELLS_PARALLEL * 2.5f * 3600) /* As */
extern uint8_t current_soc;
void estimate_soc();
float calculate_soc_for_ocv(float ocv);
#endif // INC_SOC_ESTIMATION_H

17
Core/Inc/util.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef INC_UTIL_H
#define INC_UTIL_H
#include <stdint.h>
/**
* @brief Perform linear interpolation.
*
* @param n_points Size of source_x and source_y
* @param source_x x values for the interpolation source (sorted ascending)
* @param source_y y values corresponding to source_x
* @param target_x x value that a y value should be interpolated for
*/
float interp(uint32_t n_points, const float* source_x, const float* source_y,
float target_x);
#endif // INC_UTIL_H