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