From 5ac7bdfb339f18869852479e65b396c3659b881f Mon Sep 17 00:00:00 2001 From: Lene Marquardt Date: Wed, 26 Mar 2025 16:56:50 +0100 Subject: [PATCH] temp calc, need to fix swo output of temp --- AMS_Master_Code/.vscode/launch.json | 4 ++++ AMS_Master_Code/Core/Inc/config_ADBMS6830.h | 2 +- .../ADBMS6830B_Driver/Core/Inc/ADBMS_Driver.h | 1 + .../Core/Inc/NTCLE_Abstraction.h | 10 +++++++++ .../Core/Src/NTCLE413_Abstraction.c | 22 ------------------- .../Core/Src/NTCLE_Abstraction.c | 22 +++++++++++++++++++ AMS_Master_Code/Core/Src/main.c | 12 ++++------ 7 files changed, 42 insertions(+), 31 deletions(-) create mode 100644 AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/NTCLE_Abstraction.h delete mode 100644 AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/NTCLE413_Abstraction.c create mode 100644 AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/NTCLE_Abstraction.c diff --git a/AMS_Master_Code/.vscode/launch.json b/AMS_Master_Code/.vscode/launch.json index bd2708a..4c292f6 100644 --- a/AMS_Master_Code/.vscode/launch.json +++ b/AMS_Master_Code/.vscode/launch.json @@ -26,6 +26,10 @@ "encoding": "ascii" } ] + }, + "liveWatch": { + "enabled": true, + "samplesPerSecond": 4 } }, { diff --git a/AMS_Master_Code/Core/Inc/config_ADBMS6830.h b/AMS_Master_Code/Core/Inc/config_ADBMS6830.h index 440ddb0..4b60e4c 100644 --- a/AMS_Master_Code/Core/Inc/config_ADBMS6830.h +++ b/AMS_Master_Code/Core/Inc/config_ADBMS6830.h @@ -3,7 +3,7 @@ #define __CONFIG_ADBMS6830_H #include "main.h" -#define N_BMS 3 +#define N_BMS 1 #define ADBMS_SPI_TIMEOUT 100 // Timeout in ms [[maybe_unused]] static inline void mcuAdbmsCSLow() { diff --git a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_Driver.h b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_Driver.h index c7cff59..c5a76f3 100644 --- a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_Driver.h +++ b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_Driver.h @@ -79,6 +79,7 @@ struct ADBMS6830_Internal_Status { typedef struct { int16_t cellVoltages[MAXIMUM_CELL_VOLTAGES]; int16_t auxVoltages[MAXIMUM_AUX_VOLTAGES]; + int16_t cellTemps[MAXIMUM_AUX_VOLTAGES]; struct ADBMS6830_Internal_Status status; uint16_t internalDieTemp; diff --git a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/NTCLE_Abstraction.h b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/NTCLE_Abstraction.h new file mode 100644 index 0000000..16a7eee --- /dev/null +++ b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/NTCLE_Abstraction.h @@ -0,0 +1,10 @@ +#ifndef NTCLE_Abstraction_H +#define NTCLE_Abstraction_H + +#include +#include +#include + +float calcTemp(int16_t adcVoltage, int16_t vref2); + +#endif // NTCLE_Abstraction_H \ No newline at end of file diff --git a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/NTCLE413_Abstraction.c b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/NTCLE413_Abstraction.c deleted file mode 100644 index dedcf87..0000000 --- a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/NTCLE413_Abstraction.c +++ /dev/null @@ -1,22 +0,0 @@ -// calculate Temperature for NTCLE413 Temperature Sensors - -#include -#include -#include - -#define R0 10000 //Ohm -#define BETA 3435 //Kelvin -#define T0 298.15 //Kelvin - -float calcTemp(int16_t vref2, int16_t adcVoltage){ - float r_ntc = R0/((vref2/adcVoltage)-1); - - float temp = r_ntc / R0; // (R/Ro) - temp = logf(temp); // ln(R/Ro) - temp /= BETA; // 1/B * ln(R/Ro) - temp += 1.0 / (T0 + 273.15); // + (1/To) - temp = 1.0 / temp; // Invert - temp -= 273.15; // convert to °C - - return temp; -} \ No newline at end of file diff --git a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/NTCLE_Abstraction.c b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/NTCLE_Abstraction.c new file mode 100644 index 0000000..6ad4cde --- /dev/null +++ b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/NTCLE_Abstraction.c @@ -0,0 +1,22 @@ +// calculate Temperature for NTCLE413 Temperature Sensors +//https://arduinodiy.wordpress.com/2015/11/10/measuring-temperature-with-ntc-the-steinhart-hart-formula/ + +#include "NTCLE_Abstraction.h" + +#define R0 10000.0 //Ohm +#define BETA 3435.0 //Kelvin +#define T0 298.15 //Kelvin + +float calcTemp(int16_t adcVoltage, int16_t vref2){ + float tmp = ((float)vref2)/adcVoltage; + float r_ntc = R0/(tmp-1.0); + + float temp = r_ntc / R0; // (R/Ro) + temp = logf(temp); // ln(R/Ro) + temp /= BETA; // 1/B * ln(R/Ro) + temp += 1.0 / T0; // + (1/To) + temp = 1.0 / temp; // Invert + temp -= 273.15; // convert to °C + + return (int16_t)(temp+0.5); +} \ No newline at end of file diff --git a/AMS_Master_Code/Core/Src/main.c b/AMS_Master_Code/Core/Src/main.c index 948083e..acd46a2 100644 --- a/AMS_Master_Code/Core/Src/main.c +++ b/AMS_Master_Code/Core/Src/main.c @@ -25,6 +25,7 @@ #include "config_ADBMS6830.h" #include "swo_log.h" #include +#include "NTCLE_Abstraction.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -167,15 +168,10 @@ int main(void) modules[i].auxVoltages[5], modules[i].auxVoltages[6], modules[i].auxVoltages[7], modules[i].auxVoltages[8], modules[i].auxVoltages[9]); + debug_log(LOG_LEVEL_INFO, " Calculated temps:"); - debug_log(LOG_LEVEL_INFO, " T0: %4d T1: %4d T2: %4d T3: %4d T4: %4d", - calcTemp(modules[i].auxVoltages[0]), calcTemp(modules[i].auxVoltages[1]), - modules[i].auxVoltages[2], modules[i].auxVoltages[3], - modules[i].auxVoltages[4]); - debug_log(LOG_LEVEL_INFO, " G5: %4d G6: %4d G7: %4d G8: %4d G9: %4d", - modules[i].auxVoltages[5], modules[i].auxVoltages[6], - modules[i].auxVoltages[7], modules[i].auxVoltages[8], - modules[i].auxVoltages[9]); + debug_log(LOG_LEVEL_INFO, " T0: %4f ", + calcTemp(modules[i].auxVoltages[0], modules[i].refVoltage)); debug_log(LOG_LEVEL_INFO, " Internal temp: %d, VAnalog: %d, VDigital: %d, VRef: %d", modules[i].internalDieTemp, modules[i].analogSupplyVoltage,