add: convert temperatures to degrees
This commit is contained in:
parent
ba1c8c5905
commit
e13e5c318b
@ -161,7 +161,7 @@ HAL_StatusTypeDef amsAuxAndStatusMeasurement(Cell_Module (*module)[N_BMS]) {
|
|||||||
CHECK_RETURN(readCMD(RDSTATA, rxbuf, STATUS_GROUP_A_SIZE));
|
CHECK_RETURN(readCMD(RDSTATA, rxbuf, STATUS_GROUP_A_SIZE));
|
||||||
for (size_t i = 0; i < N_BMS; i++) {
|
for (size_t i = 0; i < N_BMS; i++) {
|
||||||
size_t offset = BUFFER_BMS_OFFSET(i, STATUS_GROUP_A_SIZE);
|
size_t offset = BUFFER_BMS_OFFSET(i, STATUS_GROUP_A_SIZE);
|
||||||
(*module)[i].internalDieTemp = rxbuf[offset + 2] | (rxbuf[offset + 3] << 8);
|
(*module)[i].internalDieTemp = (mV_from_ADBMS6830(rxbuf[offset + 2] | (rxbuf[offset + 3] << 8)) / 7.5) + 273; //datasheet page 72
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_RETURN(readCMD(RDSTATB, rxbuf, STATUS_GROUP_B_SIZE));
|
CHECK_RETURN(readCMD(RDSTATB, rxbuf, STATUS_GROUP_B_SIZE));
|
||||||
|
@ -61,7 +61,32 @@ static void MX_SPI1_Init(void);
|
|||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
/* Private user code ---------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
uint32_t volatile logging_mask = 0b111111; // no LOG_LEVEL_NOISY
|
uint32_t volatile logging_mask = 0b11111; // no LOG_LEVEL_NOISY
|
||||||
|
|
||||||
|
#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 NTC_R25 10000.0f // 10k ohm at 25C
|
||||||
|
|
||||||
|
#define NTC_R_DIVIDER 10000.0f
|
||||||
|
#define NTC_V_DIVIDER 5.000f // 5V
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
|
static inline float ntc_ohms_to_celsius(float ohms) {
|
||||||
|
float log_ohms = logf(ohms / NTC_R25);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
|
static inline float ohms_from_ntc_v(float v) {
|
||||||
|
return (NTC_R_DIVIDER * v) / (NTC_V_DIVIDER - v);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int ntc_mv_to_celsius(int mv) {
|
||||||
|
float v = (float)mv * 0.001f;
|
||||||
|
return (int)ntc_ohms_to_celsius(ohms_from_ntc_v(v));
|
||||||
|
}
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,14 +186,17 @@ int main(void)
|
|||||||
modules[i].auxVoltages[5], modules[i].auxVoltages[6],
|
modules[i].auxVoltages[5], modules[i].auxVoltages[6],
|
||||||
modules[i].auxVoltages[7], modules[i].auxVoltages[8],
|
modules[i].auxVoltages[7], modules[i].auxVoltages[8],
|
||||||
modules[i].auxVoltages[9]);
|
modules[i].auxVoltages[9]);
|
||||||
|
|
||||||
|
// Print temperatures
|
||||||
|
debug_log(LOG_LEVEL_INFO, " GPIO as temperatures (°C):");
|
||||||
debug_log(LOG_LEVEL_INFO, " G0: %4d G1: %4d G2: %4d G3: %4d G4: %4d",
|
debug_log(LOG_LEVEL_INFO, " G0: %4d G1: %4d G2: %4d G3: %4d G4: %4d",
|
||||||
modules[i].GPIO_Values[0], modules[i].GPIO_Values[1],
|
ntc_mv_to_celsius(modules[i].auxVoltages[0]), ntc_mv_to_celsius(modules[i].auxVoltages[1]),
|
||||||
modules[i].GPIO_Values[2], modules[i].GPIO_Values[3],
|
ntc_mv_to_celsius(modules[i].auxVoltages[2]), ntc_mv_to_celsius(modules[i].auxVoltages[3]),
|
||||||
modules[i].GPIO_Values[4]);
|
ntc_mv_to_celsius(modules[i].auxVoltages[4]));
|
||||||
debug_log(LOG_LEVEL_INFO, " G5: %4d G6: %4d G7: %4d G8: %4d G9: %4d",
|
debug_log(LOG_LEVEL_INFO, " G5: %4d G6: %4d G7: %4d G8: %4d G9: %4d",
|
||||||
modules[i].GPIO_Values[5], modules[i].GPIO_Values[6],
|
ntc_mv_to_celsius(modules[i].auxVoltages[5]), ntc_mv_to_celsius(modules[i].auxVoltages[6]),
|
||||||
modules[i].GPIO_Values[7], modules[i].GPIO_Values[8],
|
ntc_mv_to_celsius(modules[i].auxVoltages[7]), ntc_mv_to_celsius(modules[i].auxVoltages[8]),
|
||||||
modules[i].GPIO_Values[9]);
|
ntc_mv_to_celsius(modules[i].auxVoltages[9]));
|
||||||
|
|
||||||
debug_log(LOG_LEVEL_INFO, " Internal temp: %d, VAnalog: %d, VDigital: %d, VRef: %d",
|
debug_log(LOG_LEVEL_INFO, " Internal temp: %d, VAnalog: %d, VDigital: %d, VRef: %d",
|
||||||
modules[i].internalDieTemp, modules[i].analogSupplyVoltage,
|
modules[i].internalDieTemp, modules[i].analogSupplyVoltage,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user