temp calc, need to fix swo output of temp
This commit is contained in:
parent
283de0e4e8
commit
5ac7bdfb33
4
AMS_Master_Code/.vscode/launch.json
vendored
4
AMS_Master_Code/.vscode/launch.json
vendored
@ -26,6 +26,10 @@
|
||||
"encoding": "ascii"
|
||||
}
|
||||
]
|
||||
},
|
||||
"liveWatch": {
|
||||
"enabled": true,
|
||||
"samplesPerSecond": 4
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
@ -0,0 +1,10 @@
|
||||
#ifndef NTCLE_Abstraction_H
|
||||
#define NTCLE_Abstraction_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
float calcTemp(int16_t adcVoltage, int16_t vref2);
|
||||
|
||||
#endif // NTCLE_Abstraction_H
|
@ -1,22 +0,0 @@
|
||||
// calculate Temperature for NTCLE413 Temperature Sensors
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#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;
|
||||
}
|
@ -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);
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
#include "config_ADBMS6830.h"
|
||||
#include "swo_log.h"
|
||||
#include <string.h>
|
||||
#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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user