Compare commits

...

2 Commits

Author SHA1 Message Date
ae54db62e0 fix: make adbms overtemp threshold configurable 2025-03-27 16:56:54 +01:00
8a82ad4cee further optimize ntc math 2025-03-27 16:53:11 +01:00
4 changed files with 7 additions and 6 deletions

View File

@ -1,18 +1,20 @@
#include <math.h>
#include <stdint.h>
#define NTC_A1 0.003354016f // see NTC RT csv from Vishay
#define NTC_B1 0.000300131f
#define NTC_C1 5.08516E-06f
#define NTC_D1 2.18765E-07f
#define VREF 3000.0
#define VREF 3000.0f
// More efficient (?) calc using:
// R_T = R_Pullup / (V_REF / ADC - 1)
// With R_T/R_0 and R_0 = R_T@25C
// R_T/R_0 = 1 / V_REF / ADC - 1
[[gnu::optimize("fast-math")]]
static inline int ntc_mv_to_celsius(int16_t adc) {
float log_ohms = logf(1/((VREF/adc)-1));
float log_ohms = logf(1 / ((VREF / adc) - 1));
return 1.0f / (NTC_A1 + NTC_B1 * log_ohms + NTC_C1 * log_ohms * log_ohms + NTC_D1 * log_ohms * log_ohms * log_ohms) - 273.15f;
}

View File

@ -4,7 +4,7 @@
#include "main.h"
#define N_BMS 1
#define ADBMS_SPI_TIMEOUT 100 // Timeout in ms
#define ADBMS_MAX_CHIP_TEMP 110 // max temperature of ADBMS6830B (not battery) in C
[[maybe_unused]] static inline void mcuAdbmsCSLow() {
HAL_GPIO_WritePin(AMS_CS_GPIO_Port, AMS_CS_Pin, GPIO_PIN_RESET);

View File

@ -81,7 +81,7 @@ typedef struct {
int16_t auxVoltages[MAXIMUM_AUX_VOLTAGES];
struct ADBMS6830_Internal_Status status;
uint16_t internalDieTemp;
int16_t internalDieTemp;
uint16_t analogSupplyVoltage;
uint16_t digitalSupplyVoltage;
uint16_t sumOfCellMeasurements;

View File

@ -106,8 +106,7 @@ ADBMS_DetailedStatus AMS_Idle_Loop() {
return (ADBMS_DetailedStatus){ADBMS_UNDERVOLT, match - 1};
}
// TODO: replace with the correct threshold for the internal die temperature
if ((match = any(module.internalDieTemp > 28000 || module.status.THSD))) {
if ((match = any(module.internalDieTemp > ADBMS_MAX_CHIP_TEMP || module.status.THSD))) {
return (ADBMS_DetailedStatus){ADBMS_INTERNAL_BMS_OVERTEMP, match - 1};
}