Pull out PID irrelevant filters
This commit is contained in:
@@ -21,7 +21,8 @@ uint32_t currentTempTargetDegC = 0; // Current temperature target in
|
||||
int32_t powerSupplyWattageLimit = 0;
|
||||
bool heaterThermalRunaway = false;
|
||||
|
||||
static void detectThermalRunaway(int16_t currentTipTempInC, int tError);
|
||||
static void detectThermalRunaway(const int16_t currentTipTempInC, const int tError);
|
||||
static void setOutputx10WattsViaFilters(int32_t x10Watts);
|
||||
|
||||
/* StartPIDTask function */
|
||||
void startPIDTask(void const *argument __unused) {
|
||||
@@ -29,17 +30,13 @@ void startPIDTask(void const *argument __unused) {
|
||||
* We take the current tip temperature & evaluate the next step for the tip
|
||||
* control PWM.
|
||||
*/
|
||||
setTipX10Watts(0); // disable the output driver if the output is set to be off
|
||||
TickType_t lastPowerPulseStart = 0;
|
||||
TickType_t lastPowerPulseEnd = 0;
|
||||
setTipX10Watts(0); // disable the output at startup
|
||||
|
||||
history<int32_t, PID_TIM_HZ> tempError = {{0}, 0, 0};
|
||||
currentTempTargetDegC = 0; // Force start with no output (off). If in sleep / soldering this will
|
||||
// be over-ridden rapidly
|
||||
pidTaskNotification = xTaskGetCurrentTaskHandle();
|
||||
uint32_t PIDTempTarget = 0;
|
||||
uint16_t tipTempCRunawayTemp = 0;
|
||||
TickType_t runawaylastChangeTime = 0;
|
||||
// Pre-seed the adc filters
|
||||
for (int i = 0; i < 64; i++) {
|
||||
vTaskDelay(2);
|
||||
@@ -107,6 +104,45 @@ void startPIDTask(void const *argument __unused) {
|
||||
} else {
|
||||
detectThermalRunaway(currentTipTempInC, 0);
|
||||
}
|
||||
setOutputx10WattsViaFilters(x10WattsOut);
|
||||
} else {
|
||||
// ADC interrupt timeout
|
||||
setTipPWM(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void detectThermalRunaway(const int16_t currentTipTempInC, const 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();
|
||||
}
|
||||
}
|
||||
|
||||
void setOutputx10WattsViaFilters(int32_t x10WattsOut) {
|
||||
static TickType_t lastPowerPulseStart = 0;
|
||||
static TickType_t lastPowerPulseEnd = 0;
|
||||
|
||||
// If the user turns on the option of using an occasional pulse to keep the power bank on
|
||||
if (getSettingValue(SettingsOptions::KeepAwakePulse)) {
|
||||
@@ -150,37 +186,4 @@ void startPIDTask(void const *argument __unused) {
|
||||
log_system_state(x10WattsOut);
|
||||
#endif
|
||||
resetWatchdog();
|
||||
} else {
|
||||
// ADC interrupt timeout
|
||||
setTipPWM(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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