1
0
forked from me/IronOS

Fix race condition around PID temp setpoint

This commit is contained in:
Ben V. Brown
2020-01-18 19:12:53 +11:00
parent 0384ef70b0
commit a841608547

View File

@@ -124,6 +124,7 @@ void startPIDTask(void const *argument __unused) {
currentTempTargetDegC = 0; // Force start with no output (off). If in sleep / soldering this will
// be over-ridden rapidly
pidTaskNotification = xTaskGetCurrentTaskHandle();
uint32_t PIDTempTarget = 0;
for (;;) {
if (ulTaskNotifyTake(pdTRUE, 2000)) {
@@ -131,15 +132,16 @@ void startPIDTask(void const *argument __unused) {
int32_t x10WattsOut = 0;
// Do the reading here to keep the temp calculations churning along
uint32_t currentTipTempInC = TipThermoModel::getTipInC(true);
if (currentTempTargetDegC) {
PIDTempTarget = currentTempTargetDegC;
if (PIDTempTarget) {
// Cap the max set point to 450C
if (currentTempTargetDegC > (450)) {
if (PIDTempTarget > (450)) {
//Maximum allowed output
currentTempTargetDegC = (450);
PIDTempTarget = (450);
}
if (currentTempTargetDegC > TipThermoModel::getTipMaxInC()) {
currentTempTargetDegC = TipThermoModel::getTipMaxInC();
//Safety check that not aiming higher than current tip can measure
if (PIDTempTarget > TipThermoModel::getTipMaxInC()) {
PIDTempTarget = TipThermoModel::getTipMaxInC();
}
// Convert the current tip to degree's C
@@ -147,7 +149,7 @@ void startPIDTask(void const *argument __unused) {
// to be unstable. Use a rolling average to dampen it.
// We overshoot by roughly 1 degree C.
// This helps stabilize the display.
int32_t tError = currentTempTargetDegC - currentTipTempInC + 1;
int32_t tError = PIDTempTarget - currentTipTempInC + 1;
tError = tError > INT16_MAX ? INT16_MAX : tError;
tError = tError < INT16_MIN ? INT16_MIN : tError;
tempError.update(tError);
@@ -192,18 +194,20 @@ void startPIDTask(void const *argument __unused) {
lastPowerPulse = xTaskGetTickCount();
}
#endif
//Secondary safety check to forcefully disable header when within ADC noise of top of ADC
if (getTipRawTemp(0) > (0x7FFF - 150)) {
x10WattsOut = 0;
}
if (systemSettings.powerLimitEnable
&& x10WattsOut > (systemSettings.powerLimit * 10))
&& x10WattsOut > (systemSettings.powerLimit * 10)) {
setTipX10Watts(systemSettings.powerLimit * 10);
else
} else {
setTipX10Watts(x10WattsOut);
}
HAL_IWDG_Refresh(&hiwdg);
} else {
asm("bkpt");
//ADC interrupt timeout
//ADC interrupt timeout
setTipPWM(0);
}
}