Update PIDThread.cpp
This commit is contained in:
@@ -20,6 +20,9 @@ TaskHandle_t pidTaskNotification = NULL;
|
|||||||
uint32_t currentTempTargetDegC = 0; // Current temperature target in C
|
uint32_t currentTempTargetDegC = 0; // Current temperature target in C
|
||||||
int32_t powerSupplyWattageLimit = 0;
|
int32_t powerSupplyWattageLimit = 0;
|
||||||
bool heaterThermalRunaway = false;
|
bool heaterThermalRunaway = false;
|
||||||
|
|
||||||
|
static void detectThermalRunaway(int16_t currentTipTempInC, int tError);
|
||||||
|
|
||||||
/* StartPIDTask function */
|
/* StartPIDTask function */
|
||||||
void startPIDTask(void const *argument __unused) {
|
void startPIDTask(void const *argument __unused) {
|
||||||
/*
|
/*
|
||||||
@@ -100,32 +103,9 @@ void startPIDTask(void const *argument __unused) {
|
|||||||
// basically: temp - lastTemp
|
// basically: temp - lastTemp
|
||||||
// Unfortunately, our temp signal is too noisy to really help.
|
// Unfortunately, our temp signal is too noisy to really help.
|
||||||
|
|
||||||
// Check for thermal runaway, where it has been x seconds with negligible (y) temp rise
|
detectThermalRunaway(currentTipTempInC, tError);
|
||||||
// While trying to actively heat
|
|
||||||
if ((tError > THERMAL_RUNAWAY_TEMP_C)) {
|
|
||||||
// Temp error is high
|
|
||||||
int16_t delta = (int16_t)currentTipTempInC - (int16_t)tipTempCRunawayTemp;
|
|
||||||
if (delta < 0) {
|
|
||||||
delta = -delta;
|
|
||||||
}
|
|
||||||
if (delta > THERMAL_RUNAWAY_TEMP_C) {
|
|
||||||
// We have heated up more than the threshold, reset the timer
|
|
||||||
tipTempCRunawayTemp = currentTipTempInC;
|
|
||||||
runawaylastChangeTime = xTaskGetTickCount();
|
|
||||||
} else {
|
|
||||||
if ((xTaskGetTickCount() - runawaylastChangeTime) > (THERMAL_RUNAWAY_TIME_SEC * TICKS_SECOND)) {
|
|
||||||
// It has taken too long to rise
|
|
||||||
heaterThermalRunaway = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tipTempCRunawayTemp = currentTipTempInC;
|
|
||||||
runawaylastChangeTime = xTaskGetTickCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
tipTempCRunawayTemp = currentTipTempInC;
|
detectThermalRunaway(currentTipTempInC, 0);
|
||||||
runawaylastChangeTime = xTaskGetTickCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user turns on the option of using an occasional pulse to keep the power bank on
|
// If the user turns on the option of using an occasional pulse to keep the power bank on
|
||||||
@@ -176,3 +156,31 @@ void startPIDTask(void const *argument __unused) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void detectThermalRunaway(int16_t currentTipTempInC, int tError) {
|
||||||
|
static uint16_t tipTempCRunawayTemp = 0;
|
||||||
|
static TickType_t runawaylastChangeTime = 0;
|
||||||
|
|
||||||
|
// Check for thermal runaway, where it has been x seconds with negligible (y) temp rise
|
||||||
|
// While trying to actively heat
|
||||||
|
if ((tError > THERMAL_RUNAWAY_TEMP_C)) {
|
||||||
|
// Temp error is high
|
||||||
|
int16_t delta = (int16_t)currentTipTempInC - (int16_t)tipTempCRunawayTemp;
|
||||||
|
if (delta < 0) {
|
||||||
|
delta = -delta;
|
||||||
|
}
|
||||||
|
if (delta > THERMAL_RUNAWAY_TEMP_C) {
|
||||||
|
// We have heated up more than the threshold, reset the timer
|
||||||
|
tipTempCRunawayTemp = currentTipTempInC;
|
||||||
|
runawaylastChangeTime = xTaskGetTickCount();
|
||||||
|
} else {
|
||||||
|
if ((xTaskGetTickCount() - runawaylastChangeTime) > (THERMAL_RUNAWAY_TIME_SEC * TICKS_SECOND)) {
|
||||||
|
// It has taken too long to rise
|
||||||
|
heaterThermalRunaway = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tipTempCRunawayTemp = currentTipTempInC;
|
||||||
|
runawaylastChangeTime = xTaskGetTickCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user