aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBen V. Brown <[email protected]>2020-01-18 19:12:53 +1100
committerBen V. Brown <[email protected]>2020-01-18 19:12:53 +1100
commita841608547e5a15ce4e47768f88d177f519757ba (patch)
treea95848da8c1a107a11da5dc9498f3e15594a239c
parent0384ef70b02c24e9023fefea15722f3d2fb6fca8 (diff)
downloadIronOS-a841608547e5a15ce4e47768f88d177f519757ba.tar.gz
IronOS-a841608547e5a15ce4e47768f88d177f519757ba.zip
Fix race condition around PID temp setpoint
-rw-r--r--workspace/TS100/Core/Src/main.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/workspace/TS100/Core/Src/main.cpp b/workspace/TS100/Core/Src/main.cpp
index 7950730b..d11b1198 100644
--- a/workspace/TS100/Core/Src/main.cpp
+++ b/workspace/TS100/Core/Src/main.cpp
@@ -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);
}
}