NTC on PCB not used as battery temperature anymore
- MCU temperature was renamed to internal_temperature - NTC at board edge senses temperatures far above battery / ambient temperature at high loads and is now ignored - Battery temperature always assumed 25ÂC unless external sensor is detected
This commit is contained in:
+15
-67
@@ -53,10 +53,6 @@
|
||||
AnalogOut ref_i_dcdc(PIN_REF_I_DCDC);
|
||||
#endif
|
||||
|
||||
#ifdef PIN_TEMP_INT_PD
|
||||
DigitalInOut temp_pd(PIN_TEMP_INT_PD);
|
||||
#endif
|
||||
|
||||
float solar_current_offset;
|
||||
float load_current_offset;
|
||||
|
||||
@@ -66,7 +62,7 @@ volatile uint32_t adc_filtered[NUM_ADC_CH] = {0};
|
||||
//volatile int num_adc_conversions;
|
||||
|
||||
extern LogData log_data;
|
||||
extern float mcu_temp;
|
||||
extern float internal_temp;
|
||||
|
||||
void calibrate_current_sensors()
|
||||
{
|
||||
@@ -146,7 +142,6 @@ void update_measurements()
|
||||
#if defined PIN_ADC_TEMP_BAT || defined PIN_ADC_TEMP_FETS
|
||||
float v_temp, rts;
|
||||
#endif
|
||||
float bat_temp = 25.0;
|
||||
|
||||
#ifdef PIN_ADC_TEMP_BAT
|
||||
// battery temperature calculation
|
||||
@@ -155,10 +150,19 @@ void update_measurements()
|
||||
|
||||
// Temperature calculation using Beta equation for 10k thermistor
|
||||
// (25°C reference temperature for Beta equation assumed)
|
||||
bat_temp = 1.0/(1.0/(273.15+25) + 1.0/NTC_BETA_VALUE*log(rts/10000.0)) - 273.15; // °C
|
||||
#endif
|
||||
float bat_temp = 1.0/(1.0/(273.15+25) + 1.0/NTC_BETA_VALUE*log(rts/10000.0)) - 273.15; // °C
|
||||
|
||||
detect_battery_temperature(&charger, bat_temp);
|
||||
if (bat_temp > -50) {
|
||||
// external sensor connected: take measured value
|
||||
charger.bat_temperature = bat_temp;
|
||||
charger.ext_temp_sensor = true;
|
||||
}
|
||||
else {
|
||||
// no external sensor: assume typical room temperature
|
||||
charger.bat_temperature = 25;
|
||||
charger.ext_temp_sensor = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PIN_ADC_TEMP_FETS
|
||||
// MOSFET temperature calculation
|
||||
@@ -169,64 +173,8 @@ void update_measurements()
|
||||
|
||||
// internal MCU temperature
|
||||
uint16_t adcval = (adc_filtered[ADC_POS_TEMP_MCU] >> (4 + ADC_FILTER_CONST)) * vcc / VREFINT_VALUE;
|
||||
mcu_temp = (TSENSE_CAL2_VALUE - TSENSE_CAL1_VALUE) / (TSENSE_CAL2 - TSENSE_CAL1) * (adcval - TSENSE_CAL1) + TSENSE_CAL1_VALUE;
|
||||
//printf("TS_CAL1:%d TS_CAL2:%d ADC:%d, temp_int:%f\n", TS_CAL1, TS_CAL2, adcval, meas->temp_int);
|
||||
}
|
||||
|
||||
void detect_battery_temperature(Charger *charger, float bat_temp)
|
||||
{
|
||||
#ifdef PIN_TEMP_INT_PD
|
||||
|
||||
// state machine for external sensor detection
|
||||
enum temp_sense_state {
|
||||
TSENSE_STATE_CHECK,
|
||||
TSENSE_STATE_CHECK_WAIT,
|
||||
TSENSE_STATE_MEASURE,
|
||||
TSENSE_STATE_MEASURE_WAIT
|
||||
};
|
||||
static temp_sense_state ts_state = TSENSE_STATE_CHECK;
|
||||
|
||||
static int sensor_change_counter = 0;
|
||||
|
||||
switch (ts_state) {
|
||||
case TSENSE_STATE_CHECK:
|
||||
if (bat_temp < -50) {
|
||||
charger->ext_temp_sensor = false;
|
||||
temp_pd.output();
|
||||
temp_pd = 0;
|
||||
ts_state = TSENSE_STATE_CHECK_WAIT;
|
||||
}
|
||||
else {
|
||||
charger->ext_temp_sensor = true;
|
||||
ts_state = TSENSE_STATE_MEASURE;
|
||||
}
|
||||
break;
|
||||
case TSENSE_STATE_CHECK_WAIT:
|
||||
sensor_change_counter++;
|
||||
if (sensor_change_counter > 5) {
|
||||
sensor_change_counter = 0;
|
||||
ts_state = TSENSE_STATE_MEASURE;
|
||||
}
|
||||
break;
|
||||
case TSENSE_STATE_MEASURE:
|
||||
charger->bat_temperature = charger->bat_temperature * 0.8 + bat_temp * 0.2;
|
||||
//printf("Battery temperature: %.2f (%s sensor)\n", bat_temp, (charger->ext_temp_sensor ? "external" : "internal"));
|
||||
temp_pd.input();
|
||||
ts_state = TSENSE_STATE_MEASURE_WAIT;
|
||||
break;
|
||||
case TSENSE_STATE_MEASURE_WAIT:
|
||||
sensor_change_counter++;
|
||||
if (sensor_change_counter > 10) {
|
||||
sensor_change_counter = 0;
|
||||
ts_state = TSENSE_STATE_CHECK;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#else
|
||||
if (bat_temp > -50) {
|
||||
charger->bat_temperature = bat_temp;
|
||||
}
|
||||
#endif
|
||||
internal_temp = (TSENSE_CAL2_VALUE - TSENSE_CAL1_VALUE) /
|
||||
(TSENSE_CAL2 - TSENSE_CAL1) * (adcval - TSENSE_CAL1) + TSENSE_CAL1_VALUE;
|
||||
}
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
|
||||
@@ -34,10 +34,6 @@
|
||||
*/
|
||||
void calibrate_current_sensors();
|
||||
|
||||
/** Detects if external temperature sensor is attached, otherwise takes internal sensor
|
||||
*/
|
||||
void detect_battery_temperature(Charger *bat, float bat_temp);
|
||||
|
||||
/** Updates structures with data read from ADC
|
||||
*/
|
||||
void update_measurements();
|
||||
|
||||
@@ -36,7 +36,7 @@ const char* const firmware_commit = COMMIT_HASH;
|
||||
uint32_t device_id = DEVICE_ID; // from config.h
|
||||
|
||||
extern uint32_t timestamp;
|
||||
float mcu_temp;
|
||||
float internal_temp;
|
||||
|
||||
/** Data Objects
|
||||
*
|
||||
@@ -131,7 +131,7 @@ const data_object_t data_objects[] = {
|
||||
{0x73, TS_OUTPUT, TS_READ_ALL, TS_T_FLOAT32, 2, (void*) &(load_terminal.current), "Load_A"},
|
||||
{0x74, TS_OUTPUT, TS_READ_ALL, TS_T_FLOAT32, 1, (void*) &(charger.bat_temperature), "Bat_degC"},
|
||||
{0x75, TS_OUTPUT, TS_READ_ALL, TS_T_BOOL, 1, (void*) &(charger.ext_temp_sensor), "BatTempExt"},
|
||||
{0x76, TS_OUTPUT, TS_READ_ALL, TS_T_FLOAT32, 1, (void*) &(mcu_temp), "MCU_degC"},
|
||||
{0x76, TS_OUTPUT, TS_READ_ALL, TS_T_FLOAT32, 1, (void*) &(internal_temp), "Int_degC"},
|
||||
#if defined(PIN_ADC_TEMP_FETS) && FEATURE_DCDC_CONVERTER
|
||||
{0x77, TS_OUTPUT, TS_READ_ALL, TS_T_FLOAT32, 1, (void*) &(dcdc.temp_mosfets), "Mosfet_degC"},
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@
|
||||
volatile bool short_circuit = false;
|
||||
|
||||
extern LogData log_data;
|
||||
extern float mcu_temp;
|
||||
extern float internal_temp;
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
|
||||
@@ -347,7 +347,7 @@ void LoadOutput::control()
|
||||
|
||||
// junction temperature calculation model for overcurrent detection
|
||||
junction_temperature = junction_temperature + (
|
||||
mcu_temp - junction_temperature +
|
||||
internal_temp - junction_temperature +
|
||||
port->current * port->current /
|
||||
(LOAD_CURRENT_MAX * LOAD_CURRENT_MAX) * (MOSFET_MAX_JUNCTION_TEMP - 25)
|
||||
) / (MOSFET_THERMAL_TIME_CONSTANT * CONTROL_FREQUENCY);
|
||||
|
||||
+3
-3
@@ -23,7 +23,7 @@
|
||||
#include <math.h> // for fabs function
|
||||
#include <stdio.h>
|
||||
|
||||
extern float mcu_temp;
|
||||
extern float internal_temp;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// must be called exactly once per second, otherwise energy calculation gets wrong
|
||||
@@ -112,7 +112,7 @@ void log_update_min_max_values(LogData *log_data)
|
||||
log_data->bat_temp_max = charger.bat_temperature;
|
||||
}
|
||||
|
||||
if (mcu_temp > log_data->int_temp_max) {
|
||||
log_data->int_temp_max = mcu_temp;
|
||||
if (internal_temp > log_data->int_temp_max) {
|
||||
log_data->int_temp_max = internal_temp;
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,8 @@
|
||||
|
||||
#define PIN_REF_I_DCDC PA_4
|
||||
|
||||
// Internal NTC temperature currently ignored by firmware as it is similar to MCU temperature and
|
||||
// does not reflect external battery temperature. Feature will be removed in future HW revisions.
|
||||
#define PIN_TEMP_INT_PD PA_8
|
||||
|
||||
enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT };
|
||||
|
||||
@@ -62,6 +62,8 @@
|
||||
|
||||
#define PIN_REF_I_DCDC PA_4
|
||||
|
||||
// Internal NTC temperature currently ignored by firmware as it is similar to MCU temperature and
|
||||
// does not reflect external battery temperature. Feature will be removed in future HW revisions.
|
||||
#define PIN_TEMP_INT_PD PA_8
|
||||
|
||||
enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT };
|
||||
|
||||
@@ -24,7 +24,6 @@ typedef struct {
|
||||
float dcdc_current;
|
||||
float load_current;
|
||||
float bat_temperature;
|
||||
float mcu_temperature;
|
||||
float internal_temperature;
|
||||
} adc_values_t;
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@ void adc_tests()
|
||||
adcval.dcdc_current = 3;
|
||||
adcval.internal_temperature = 25;
|
||||
adcval.load_current = 1;
|
||||
adcval.mcu_temperature = 25;
|
||||
adcval.solar_voltage = 30;
|
||||
prepare_adc_readings(adcval);
|
||||
|
||||
|
||||
+3
-3
@@ -192,7 +192,7 @@ void control_off_overvoltage()
|
||||
TEST_ASSERT_EQUAL(1 << ERR_LOAD_OVERVOLTAGE, log_data.error_flags);
|
||||
}
|
||||
|
||||
extern float mcu_temp;
|
||||
extern float internal_temp;
|
||||
|
||||
void control_off_overcurrent()
|
||||
{
|
||||
@@ -204,7 +204,7 @@ void control_off_overcurrent()
|
||||
port.voltage = 14;
|
||||
load.state = LOAD_STATE_ON;
|
||||
load.voltage_prev = port.voltage;
|
||||
mcu_temp = 25;
|
||||
internal_temp = 25;
|
||||
load.junction_temperature = 25;
|
||||
log_data.error_flags = 0;
|
||||
|
||||
@@ -227,7 +227,7 @@ void control_off_voltage_dip()
|
||||
port.init_load(14.6);
|
||||
load.voltage_prev = port.voltage;
|
||||
load.state = LOAD_STATE_ON;
|
||||
mcu_temp = 25;
|
||||
internal_temp = 25;
|
||||
load.junction_temperature = 25;
|
||||
log_data.error_flags = 0;
|
||||
|
||||
|
||||
+2
-2
@@ -106,11 +106,11 @@ void log_new_bat_temp_max()
|
||||
TEST_ASSERT_EQUAL(45, log_data.bat_temp_max);
|
||||
}
|
||||
|
||||
extern float mcu_temp;
|
||||
extern float internal_temp;
|
||||
|
||||
void log_new_int_temp_max()
|
||||
{
|
||||
mcu_temp = 22;
|
||||
internal_temp = 22;
|
||||
log_update_min_max_values(&log_data);
|
||||
TEST_ASSERT_EQUAL(22, log_data.int_temp_max);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ void energy_calculation_init()
|
||||
adcval.dcdc_current = dcdc_current_sun;
|
||||
adcval.internal_temperature = 25;
|
||||
adcval.load_current = load_current;
|
||||
adcval.mcu_temperature = 25;
|
||||
adcval.internal_temperature = 25;
|
||||
adcval.solar_voltage = 30;
|
||||
|
||||
// insert values into ADC functions
|
||||
|
||||
Reference in New Issue
Block a user