summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBen V. Brown <[email protected]>2023-09-22 10:19:50 +1000
committerGitHub <[email protected]>2023-09-22 10:19:50 +1000
commitc0a5e244b93eba570c08bc73ecd2fe7cfc067636 (patch)
tree426da92404b30a3949b2e3ca844a633fbf908ebf
parentf99aed5785526a1508cbfd303cbb27e8f56d4535 (diff)
downloadIronOS-c0a5e244b93eba570c08bc73ecd2fe7cfc067636.tar.gz
IronOS-c0a5e244b93eba570c08bc73ecd2fe7cfc067636.zip
Temperature code updates (#1814)v2.22-rc2
* Create a typedef for temperatures * Quick parse replace temp types * Fixup for fast/slow PWM on PinecilV2 * Update PIDThread.cpp * Pinecil small tips need less smoothing * Remove incorrect comment * Remove unused function * Update PinecilV2 Tune as well
-rw-r--r--source/Core/BSP/BSP.h2
-rw-r--r--source/Core/BSP/MHP30/ThermoModel.cpp6
-rw-r--r--source/Core/BSP/Miniware/ThermoModel.cpp2
-rw-r--r--source/Core/BSP/Pinecil/ThermoModel.cpp2
-rw-r--r--source/Core/BSP/Pinecilv2/BSP.cpp8
-rw-r--r--source/Core/BSP/Pinecilv2/IRQ.cpp41
-rw-r--r--source/Core/BSP/Pinecilv2/IRQ.h1
-rw-r--r--source/Core/BSP/Pinecilv2/Setup.h6
-rw-r--r--source/Core/BSP/Pinecilv2/ThermoModel.cpp2
-rw-r--r--source/Core/BSP/Pinecilv2/configuration.h1
-rw-r--r--source/Core/BSP/Sequre_S60/ThermoModel.cpp2
-rw-r--r--source/Core/Drivers/TipThermoModel.cpp29
-rw-r--r--source/Core/Drivers/TipThermoModel.h21
-rw-r--r--source/Core/Inc/Types.h10
-rw-r--r--source/Core/Inc/main.hpp7
-rw-r--r--source/Core/Inc/power.hpp1
-rw-r--r--source/Core/Src/power.cpp8
-rw-r--r--source/Core/Threads/OperatingModes/utils/checkUndervoltage.cpp2
-rw-r--r--source/Core/Threads/PIDThread.cpp73
19 files changed, 116 insertions, 108 deletions
diff --git a/source/Core/BSP/BSP.h b/source/Core/BSP/BSP.h
index 626989fe..37508597 100644
--- a/source/Core/BSP/BSP.h
+++ b/source/Core/BSP/BSP.h
@@ -3,9 +3,11 @@
#include "BSP_Power.h"
#include "BSP_QC.h"
#include "Defines.h"
+#include "Types.h"
#include "configuration.h"
#include <stdbool.h>
#include <stdint.h>
+
/*
* BSP.h -- Board Support
*
diff --git a/source/Core/BSP/MHP30/ThermoModel.cpp b/source/Core/BSP/MHP30/ThermoModel.cpp
index f43499a0..9275d835 100644
--- a/source/Core/BSP/MHP30/ThermoModel.cpp
+++ b/source/Core/BSP/MHP30/ThermoModel.cpp
@@ -6,10 +6,12 @@
*/
#include "Setup.h"
#include "TipThermoModel.h"
+#include "Types.h"
#include "Utils.h"
#include "configuration.h"
-extern uint16_t tipSenseResistancex10Ohms;
-uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
+
+extern uint16_t tipSenseResistancex10Ohms;
+TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
// For the MHP30, we are mimicing the original code and using the resistor fitted to the base of the heater head,
// this is measured at boot in pid task and in the disconnected tip check if tip is removed
if (tipSenseResistancex10Ohms > 900 && tipSenseResistancex10Ohms <= 1100) {
diff --git a/source/Core/BSP/Miniware/ThermoModel.cpp b/source/Core/BSP/Miniware/ThermoModel.cpp
index 25376d4e..da9dac4c 100644
--- a/source/Core/BSP/Miniware/ThermoModel.cpp
+++ b/source/Core/BSP/Miniware/ThermoModel.cpp
@@ -127,4 +127,4 @@ const int32_t uVtoDegC[] = {
#endif
const int uVtoDegCItems = sizeof(uVtoDegC) / (2 * sizeof(uVtoDegC[0]));
-uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }
+TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }
diff --git a/source/Core/BSP/Pinecil/ThermoModel.cpp b/source/Core/BSP/Pinecil/ThermoModel.cpp
index fa2cd65d..a20fe0aa 100644
--- a/source/Core/BSP/Pinecil/ThermoModel.cpp
+++ b/source/Core/BSP/Pinecil/ThermoModel.cpp
@@ -69,4 +69,4 @@ const int32_t uVtoDegC[] = {
const int uVtoDegCItems = sizeof(uVtoDegC) / (2 * sizeof(uVtoDegC[0]));
-uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }
+TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }
diff --git a/source/Core/BSP/Pinecilv2/BSP.cpp b/source/Core/BSP/Pinecilv2/BSP.cpp
index 35809866..7c711a61 100644
--- a/source/Core/BSP/Pinecilv2/BSP.cpp
+++ b/source/Core/BSP/Pinecilv2/BSP.cpp
@@ -17,8 +17,8 @@
// These control the period's of time used for the PWM
const uint16_t powerPWM = 255;
-const uint8_t holdoffTicks = 25; // This is the tick delay before temp measure starts (i.e. time for op-amp recovery)
-const uint8_t tempMeasureTicks = 25;
+uint8_t holdoffTicks = 25; // This is the tick delay before temp measure starts (i.e. time for op-amp recovery)
+uint8_t tempMeasureTicks = 25;
uint16_t totalPWM = 255; // Total length of the cycle's ticks
@@ -162,13 +162,13 @@ uint8_t getTipResistanceX10() {
uint8_t getTipThermalMass() {
if (lastTipResistance >= 80) {
- return TIP_THERMAL_MASS;
+ return 65;
}
return 45;
}
uint8_t getTipInertia() {
if (lastTipResistance >= 80) {
- return TIP_THERMAL_MASS;
+ return 90;
}
return 10;
}
diff --git a/source/Core/BSP/Pinecilv2/IRQ.cpp b/source/Core/BSP/Pinecilv2/IRQ.cpp
index 3257ae40..bd64a96e 100644
--- a/source/Core/BSP/Pinecilv2/IRQ.cpp
+++ b/source/Core/BSP/Pinecilv2/IRQ.cpp
@@ -19,7 +19,7 @@ extern "C" {
}
void start_PWM_output(void);
-#define ADC_Filter_Smooth 4
+#define ADC_Filter_Smooth 1
history<uint16_t, ADC_Filter_Smooth> ADC_Vin;
history<uint16_t, ADC_Filter_Smooth> ADC_Temp;
history<uint16_t, ADC_Filter_Smooth> ADC_Tip;
@@ -67,19 +67,21 @@ void adc_fifo_irq(void) {
ADC_IntClr(ADC_INT_ALL);
}
-static bool fastPWM = false;
+volatile bool inFastPWMMode = false;
+
static void switchToFastPWM(void);
+static void switchToSlowPWM(void);
-volatile uint16_t PWMSafetyTimer = 0;
-volatile uint8_t pendingPWM = 0;
-volatile bool lastPeriodWasFast = false;
+volatile uint16_t PWMSafetyTimer = 0;
+volatile uint8_t pendingPWM = 0;
+volatile bool pendingNextPeriodIsFast = false;
void start_PWM_output(void) {
if (PWMSafetyTimer) {
PWMSafetyTimer--;
- if (lastPeriodWasFast != fastPWM) {
- if (fastPWM) {
+ if (pendingNextPeriodIsFast != inFastPWMMode) {
+ if (pendingNextPeriodIsFast) {
switchToFastPWM();
} else {
switchToSlowPWM();
@@ -96,6 +98,7 @@ void start_PWM_output(void) {
}
} else {
PWM_Channel_Disable(PWM_Channel);
+ switchToFastPWM();
}
TIMER_Enable(TIMER_CH0);
}
@@ -108,43 +111,47 @@ void timer0_comp0_callback(void) {
void timer0_comp1_callback(void) { PWM_Channel_Disable(PWM_Channel); } // Trigged at end of output cycle; turn off the tip PWM
void switchToFastPWM(void) {
- fastPWM = true;
- totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
+ inFastPWMMode = true;
+ holdoffTicks = 10;
+ tempMeasureTicks = 10;
+ totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_2, totalPWM);
// ~10Hz
TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_0, powerPWM + holdoffTicks);
- // Set divider to 11
+ // Set divider to 10 ~= 10.5Hz
uint32_t tmpVal = BL_RD_REG(TIMER_BASE, TIMER_TCDR);
- tmpVal = BL_SET_REG_BITS_VAL(tmpVal, TIMER_TCDR2, 11);
+ tmpVal = BL_SET_REG_BITS_VAL(tmpVal, TIMER_TCDR2, 10);
BL_WR_REG(TIMER_BASE, TIMER_TCDR, tmpVal);
}
void switchToSlowPWM(void) {
// 5Hz
- fastPWM = false;
- totalPWM = powerPWM + tempMeasureTicks / 2 + holdoffTicks / 2;
+ inFastPWMMode = false;
+ holdoffTicks = 5;
+ tempMeasureTicks = 5;
+ totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_2, totalPWM);
// Adjust ADC
- TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_0, powerPWM + (holdoffTicks / 2));
+ TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_0, powerPWM + holdoffTicks);
// Set divider to 22
uint32_t tmpVal = BL_RD_REG(TIMER_BASE, TIMER_TCDR);
- tmpVal = BL_SET_REG_BITS_VAL(tmpVal, TIMER_TCDR2, 22);
+ tmpVal = BL_SET_REG_BITS_VAL(tmpVal, TIMER_TCDR2, 20);
BL_WR_REG(TIMER_BASE, TIMER_TCDR, tmpVal);
}
void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
PWMSafetyTimer = 10; // This is decremented in the handler for PWM so that the tip pwm is
// disabled if the PID task is not scheduled often enough.
- pendingPWM = pulse;
- fastPWM = shouldUseFastModePWM;
+ pendingPWM = pulse;
+ pendingNextPeriodIsFast = shouldUseFastModePWM;
}
extern osThreadId POWTaskHandle;
diff --git a/source/Core/BSP/Pinecilv2/IRQ.h b/source/Core/BSP/Pinecilv2/IRQ.h
index 1e66b904..4f6d6814 100644
--- a/source/Core/BSP/Pinecilv2/IRQ.h
+++ b/source/Core/BSP/Pinecilv2/IRQ.h
@@ -21,7 +21,6 @@ void timer0_comp1_callback(void);
void timer0_comp2_callback(void);
void adc_fifo_irq(void);
void GPIO_IRQHandler(void);
-void switchToSlowPWM(void);
#ifdef __cplusplus
}
#endif
diff --git a/source/Core/BSP/Pinecilv2/Setup.h b/source/Core/BSP/Pinecilv2/Setup.h
index 18591d7c..d2ab67cb 100644
--- a/source/Core/BSP/Pinecilv2/Setup.h
+++ b/source/Core/BSP/Pinecilv2/Setup.h
@@ -29,7 +29,7 @@ uint16_t getADCVin(uint8_t sample);
#ifdef __cplusplus
}
#endif
-void setupFUSBIRQ();
-extern const uint8_t holdoffTicks;
-extern const uint8_t tempMeasureTicks;
+void setupFUSBIRQ();
+extern uint8_t holdoffTicks;
+extern uint8_t tempMeasureTicks;
#endif /* PINE_SETUP_H_ */
diff --git a/source/Core/BSP/Pinecilv2/ThermoModel.cpp b/source/Core/BSP/Pinecilv2/ThermoModel.cpp
index 4515c42f..028a477b 100644
--- a/source/Core/BSP/Pinecilv2/ThermoModel.cpp
+++ b/source/Core/BSP/Pinecilv2/ThermoModel.cpp
@@ -69,4 +69,4 @@ const int32_t uVtoDegC[] = {
const int uVtoDegCItems = sizeof(uVtoDegC) / (2 * sizeof(int32_t));
-uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }
+TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }
diff --git a/source/Core/BSP/Pinecilv2/configuration.h b/source/Core/BSP/Pinecilv2/configuration.h
index 9cc198b2..3683b085 100644
--- a/source/Core/BSP/Pinecilv2/configuration.h
+++ b/source/Core/BSP/Pinecilv2/configuration.h
@@ -161,7 +161,6 @@
#define DEBUG_UART_OUTPUT
#define HAS_POWER_DEBUG_MENU
#define HARDWARE_MAX_WATTAGE_X10 750
-#define TIP_THERMAL_MASS 65 // X10 watts to raise 1 deg C in 1 second
#define BLE_ENABLED
#define NEEDS_VBUS_PROBE 0
#define CANT_DIRECT_READ_SETTINGS
diff --git a/source/Core/BSP/Sequre_S60/ThermoModel.cpp b/source/Core/BSP/Sequre_S60/ThermoModel.cpp
index 550726e8..90c12ab1 100644
--- a/source/Core/BSP/Sequre_S60/ThermoModel.cpp
+++ b/source/Core/BSP/Sequre_S60/ThermoModel.cpp
@@ -8,4 +8,4 @@
#include "Utils.h"
#include "configuration.h"
-uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return (tipuVDelta * 50) / 485; }
+TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return (tipuVDelta * 50) / 485; }
diff --git a/source/Core/Drivers/TipThermoModel.cpp b/source/Core/Drivers/TipThermoModel.cpp
index ea6a0c74..29edc08d 100644
--- a/source/Core/Drivers/TipThermoModel.cpp
+++ b/source/Core/Drivers/TipThermoModel.cpp
@@ -8,6 +8,7 @@
#include "TipThermoModel.h"
#include "BSP.h"
#include "Settings.h"
+#include "Types.h"
#include "Utils.h"
#include "configuration.h"
#include "main.hpp"
@@ -54,45 +55,41 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC, bool ski
return valueuV;
}
-uint32_t TipThermoModel::convertTipRawADCToDegC(uint16_t rawADC) { return convertuVToDegC(convertTipRawADCTouV(rawADC)); }
-uint32_t TipThermoModel::convertTipRawADCToDegF(uint16_t rawADC) { return convertuVToDegF(convertTipRawADCTouV(rawADC)); }
+TemperatureType_t TipThermoModel::convertTipRawADCToDegC(uint16_t rawADC) { return convertuVToDegC(convertTipRawADCTouV(rawADC)); }
+TemperatureType_t TipThermoModel::convertTipRawADCToDegF(uint16_t rawADC) { return convertuVToDegF(convertTipRawADCTouV(rawADC)); }
-uint32_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) { return convertCtoF(convertuVToDegC(tipuVDelta)); }
+TemperatureType_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) { return convertCtoF(convertuVToDegC(tipuVDelta)); }
-uint32_t TipThermoModel::convertCtoF(uint32_t degC) {
+TemperatureType_t TipThermoModel::convertCtoF(TemperatureType_t degC) {
//(Y °C × 9/5) + 32 =Y°F
return (32 + ((degC * 9) / 5));
}
-uint32_t TipThermoModel::convertFtoC(uint32_t degF) {
+TemperatureType_t TipThermoModel::convertFtoC(TemperatureType_t degF) {
//(Y°F − 32) × 5/9 = Y°C
if (degF < 32) {
return 0;
}
return ((degF - 32) * 5) / 9;
}
-uint32_t TipThermoModel::getTipInC(bool sampleNow) {
- int32_t currentTipTempInC = TipThermoModel::convertTipRawADCToDegC(getTipRawTemp(sampleNow));
+TemperatureType_t TipThermoModel::getTipInC(bool sampleNow) {
+ TemperatureType_t currentTipTempInC = TipThermoModel::convertTipRawADCToDegC(getTipRawTemp(sampleNow));
currentTipTempInC += getHandleTemperature(sampleNow) / 10; // Add handle offset
- // Power usage indicates that our tip temp is lower than our thermocouple temp.
- // I found a number that doesn't unbalance the existing PID, causing overshoot.
- // This could be tuned in concert with PID parameters...
-
if (currentTipTempInC < 0) {
return 0;
}
return currentTipTempInC;
}
-uint32_t TipThermoModel::getTipInF(bool sampleNow) {
- uint32_t currentTipTempInF = getTipInC(sampleNow);
- currentTipTempInF = convertCtoF(currentTipTempInF);
+TemperatureType_t TipThermoModel::getTipInF(bool sampleNow) {
+ TemperatureType_t currentTipTempInF = getTipInC(sampleNow);
+ currentTipTempInF = convertCtoF(currentTipTempInF);
return currentTipTempInF;
}
-uint32_t TipThermoModel::getTipMaxInC() {
- uint32_t maximumTipTemp = TipThermoModel::convertTipRawADCToDegC(ADC_MAX_READING - 1);
+TemperatureType_t TipThermoModel::getTipMaxInC() {
+ TemperatureType_t maximumTipTemp = TipThermoModel::convertTipRawADCToDegC(ADC_MAX_READING - 1);
maximumTipTemp += getHandleTemperature(0) / 10; // Add handle offset
return maximumTipTemp - 1;
}
diff --git a/source/Core/Drivers/TipThermoModel.h b/source/Core/Drivers/TipThermoModel.h
index b595c736..03a10ff0 100644
--- a/source/Core/Drivers/TipThermoModel.h
+++ b/source/Core/Drivers/TipThermoModel.h
@@ -8,26 +8,27 @@
#ifndef SRC_TIPTHERMOMODEL_H_
#define SRC_TIPTHERMOMODEL_H_
#include "BSP.h"
+#include "Types.h"
#include "stdint.h"
class TipThermoModel {
public:
// These are the main two functions
- static uint32_t getTipInC(bool sampleNow = false);
- static uint32_t getTipInF(bool sampleNow = false);
+ static TemperatureType_t getTipInC(bool sampleNow = false);
+ static TemperatureType_t getTipInF(bool sampleNow = false);
// Calculates the maximum temperature can can be read by the ADC range
- static uint32_t getTipMaxInC();
+ static TemperatureType_t getTipMaxInC();
- static uint32_t convertTipRawADCToDegC(uint16_t rawADC);
- static uint32_t convertTipRawADCToDegF(uint16_t rawADC);
+ static TemperatureType_t convertTipRawADCToDegC(uint16_t rawADC);
+ static TemperatureType_t convertTipRawADCToDegF(uint16_t rawADC);
// Returns the uV of the tip reading before the op-amp compensating for pullups
- static uint32_t convertTipRawADCTouV(uint16_t rawADC, bool skipCalOffset = false);
- static uint32_t convertCtoF(uint32_t degC);
- static uint32_t convertFtoC(uint32_t degF);
+ static uint32_t convertTipRawADCTouV(uint16_t rawADC, bool skipCalOffset = false);
+ static TemperatureType_t convertCtoF(TemperatureType_t degC);
+ static TemperatureType_t convertFtoC(TemperatureType_t degF);
private:
- static uint32_t convertuVToDegC(uint32_t tipuVDelta);
- static uint32_t convertuVToDegF(uint32_t tipuVDelta);
+ static TemperatureType_t convertuVToDegC(uint32_t tipuVDelta);
+ static TemperatureType_t convertuVToDegF(uint32_t tipuVDelta);
};
#endif /* SRC_TIPTHERMOMODEL_H_ */
diff --git a/source/Core/Inc/Types.h b/source/Core/Inc/Types.h
new file mode 100644
index 00000000..145cd6be
--- /dev/null
+++ b/source/Core/Inc/Types.h
@@ -0,0 +1,10 @@
+#ifndef TYPES_H_
+#define TYPES_H_
+#include <stddef.h>
+
+// Used for temperature represented in C or x10C.
+//
+
+typedef int32_t TemperatureType_t;
+
+#endif \ No newline at end of file
diff --git a/source/Core/Inc/main.hpp b/source/Core/Inc/main.hpp
index bd2eef41..0ffac19d 100644
--- a/source/Core/Inc/main.hpp
+++ b/source/Core/Inc/main.hpp
@@ -2,10 +2,11 @@
#define __MAIN_H
#include "OLED.hpp"
#include "Setup.h"
+#include "Types.h"
#include <stdint.h>
-extern volatile uint32_t currentTempTargetDegC;
-extern bool settingsWereReset;
-extern bool usb_pd_available;
+extern volatile TemperatureType_t currentTempTargetDegC;
+extern bool settingsWereReset;
+extern bool usb_pd_available;
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/source/Core/Inc/power.hpp b/source/Core/Inc/power.hpp
index f8d35f67..432ad166 100644
--- a/source/Core/Inc/power.hpp
+++ b/source/Core/Inc/power.hpp
@@ -23,7 +23,6 @@ const uint8_t wattHistoryFilter = 24; //
extern expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory;
uint32_t availableW10(uint8_t sample);
-int32_t tempToX10Watts(int32_t rawTemp);
void setTipX10Watts(int32_t mw);
uint8_t X10WattsToPWM(int32_t milliWatts, uint8_t sample = 0);
#endif /* POWER_HPP_ */
diff --git a/source/Core/Src/power.cpp b/source/Core/Src/power.cpp
index 88d0509b..708014ed 100644
--- a/source/Core/Src/power.cpp
+++ b/source/Core/Src/power.cpp
@@ -27,14 +27,6 @@ bool shouldBeUsingFastPWMMode(const uint8_t pwmTicks) {
return lastPWMWasFast;
}
-int32_t tempToX10Watts(int32_t rawTemp) {
- // mass is in x10J/*C, rawC is raw per degree C
- // returns x10Watts needed to raise/lower a mass by rawTemp
- // degrees in one cycle.
- int32_t x10Watts = TIP_THERMAL_MASS * rawTemp;
- return x10Watts;
-}
-
void setTipX10Watts(int32_t mw) {
int32_t outputPWMLevel = X10WattsToPWM(mw, 1);
const bool shouldUseFastPWM = shouldBeUsingFastPWMMode(outputPWMLevel);
diff --git a/source/Core/Threads/OperatingModes/utils/checkUndervoltage.cpp b/source/Core/Threads/OperatingModes/utils/checkUndervoltage.cpp
index 15d8f613..158e8842 100644
--- a/source/Core/Threads/OperatingModes/utils/checkUndervoltage.cpp
+++ b/source/Core/Threads/OperatingModes/utils/checkUndervoltage.cpp
@@ -2,7 +2,7 @@
#include "OperatingModeUtilities.h"
#include "configuration.h"
#ifdef POW_DC
-extern volatile uint32_t currentTempTargetDegC;
+extern volatile TemperatureType_t currentTempTargetDegC;
// returns true if undervoltage has occured
bool checkForUnderVoltage(void) {
if (!getIsPoweredByDCIN()) {
diff --git a/source/Core/Threads/PIDThread.cpp b/source/Core/Threads/PIDThread.cpp
index 026a414c..7118273b 100644
--- a/source/Core/Threads/PIDThread.cpp
+++ b/source/Core/Threads/PIDThread.cpp
@@ -15,15 +15,15 @@
#include "power.hpp"
#include "task.h"
-static TickType_t powerPulseWaitUnit = 25 * TICKS_100MS; // 2.5 s
-static TickType_t powerPulseDurationUnit = (5 * TICKS_100MS) / 2; // 250 ms
-TaskHandle_t pidTaskNotification = NULL;
-volatile uint32_t currentTempTargetDegC = 0; // Current temperature target in C
-int32_t powerSupplyWattageLimit = 0;
-bool heaterThermalRunaway = false;
-
-static int32_t getPIDResultX10Watts(int32_t tError);
-static void detectThermalRunaway(const int16_t currentTipTempInC, const int tError);
+static TickType_t powerPulseWaitUnit = 25 * TICKS_100MS; // 2.5 s
+static TickType_t powerPulseDurationUnit = (5 * TICKS_100MS) / 2; // 250 ms
+TaskHandle_t pidTaskNotification = NULL;
+volatile TemperatureType_t currentTempTargetDegC = 0; // Current temperature target in C
+int32_t powerSupplyWattageLimit = 0;
+bool heaterThermalRunaway = false;
+
+static int32_t getPIDResultX10Watts(TemperatureType_t tError);
+static void detectThermalRunaway(const TemperatureType_t currentTipTempInC, const TemperatureType_t tError);
static void setOutputx10WattsViaFilters(int32_t x10Watts);
static int32_t getX10WattageLimits();
@@ -37,8 +37,8 @@ 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;
+ pidTaskNotification = xTaskGetCurrentTaskHandle();
+ TemperatureType_t PIDTempTarget = 0;
// Pre-seed the adc filters
for (int i = 0; i < 32; i++) {
ulTaskNotifyTake(pdTRUE, 5);
@@ -58,19 +58,20 @@ void startPIDTask(void const *argument __unused) {
// This is a call to block this thread until the ADC does its samples
if (ulTaskNotifyTake(pdTRUE, TICKS_SECOND * 2)) {
// Do the reading here to keep the temp calculations churning along
- uint32_t currentTipTempInC = TipThermoModel::getTipInC(true);
- PIDTempTarget = currentTempTargetDegC;
+ TemperatureType_t currentTipTempInC = TipThermoModel::getTipInC(true);
+
+ PIDTempTarget = currentTempTargetDegC;
if (PIDTempTarget > 0) {
// Cap the max set point to 450C
- if (PIDTempTarget > (450)) {
+ if (PIDTempTarget > 450) {
// Maximum allowed output
- PIDTempTarget = (450);
+ PIDTempTarget = 450;
}
// Safety check that not aiming higher than current tip can measure
if (PIDTempTarget > TipThermoModel::getTipMaxInC()) {
PIDTempTarget = TipThermoModel::getTipMaxInC();
}
- int32_t tError = PIDTempTarget - currentTipTempInC;
+ TemperatureType_t tError = PIDTempTarget - currentTipTempInC;
detectThermalRunaway(currentTipTempInC, tError);
x10WattsOut = getPIDResultX10Watts(tError);
@@ -88,7 +89,7 @@ void startPIDTask(void const *argument __unused) {
}
}
-template <class T = int32_t> struct Integrator {
+template <class T = TemperatureType_t> struct Integrator {
T sum;
T update(const T val, const int32_t inertia, const int32_t gain, const int32_t rate, const int32_t limit) {
@@ -99,11 +100,12 @@ template <class T = int32_t> struct Integrator {
// Add the new value x integration interval ( 1 / rate)
sum += (gain * val) / rate;
- // limit the output
- if (sum > limit)
+ // constrain the output between +- our max power output, this limits windup when doing the inital heatup or when solding something large
+ if (sum > limit) {
sum = limit;
- else if (sum < -limit)
+ } else if (sum < -limit) {
sum = -limit;
+ }
return sum;
}
@@ -112,15 +114,15 @@ template <class T = int32_t> struct Integrator {
T get(bool positiveOnly = true) const { return (positiveOnly) ? ((sum > 0) ? sum : 0) : sum; }
};
-int32_t getPIDResultX10Watts(int32_t setpointDelta) {
- static TickType_t lastCall = 0;
- static Integrator<int32_t> powerStore = {0};
+int32_t getPIDResultX10Watts(TemperatureType_t setpointDelta) {
+ static TickType_t lastCall = 0;
+ static Integrator<TemperatureType_t> powerStore = {0};
const TickType_t rate = TICKS_SECOND / (xTaskGetTickCount() - lastCall);
lastCall = xTaskGetTickCount();
// Sandman note:
// PID Challenge - we have a small thermal mass that we to want heat up as fast as possible but we don't
- // want to overshot excessively (if at all) the setpoint temperature. In the same time we have 'imprecise'
+ // want to overshot excessively (if at all) the set point temperature. In the same time we have 'imprecise'
// instant temperature measurements. The nature of temperature reading imprecision is not necessarily
// related to the sensor (thermocouple) or DAQ system, that otherwise are fairly decent. The real issue is
// the thermal inertia. We basically read the temperature in the window between two heating sessions when
@@ -130,7 +132,7 @@ int32_t getPIDResultX10Watts(int32_t setpointDelta) {
// negative side effects. As a result, we can only rely on the I term but with a twist. Instead of a simple
// integrator we are going to use a self decaying integrator that acts more like a dual I term / P term
// rather than a plain I term. Depending on the circumstances, like when the delta temperature is large,
- // it acts more like a P term whereas on closing to setpoint it acts increasingly closer to a plain I term.
+ // it acts more like a P term whereas on closing to set point it acts increasingly closer to a plain I term.
// So in a sense, we have a bit of both.
// So there we go...
@@ -138,20 +140,17 @@ int32_t getPIDResultX10Watts(int32_t setpointDelta) {
// delta temperature is in °C. The result is the power in X10 W needed to raise (or decrease!) the
// tip temperature with (Delta Temperature ) °C in 1 second.
// Note on powerStore. On update, if the value is provided in X10 (W) units then inertia shall be provided
- // in X10 (J / °C) units as well. Also, powerStore is updated with a gain of 2. Where this comes from: The actual
- // power CMOS is controlled by TIM3->CTR1 (that is software modulated - on/off - by TIM2-CTR4 interrupts). However,
- // TIM3->CTR1 is configured with a duty cycle of 50% so, in real, we get only 50% of the presumed power output
- // so we basically double the need (gain = 2) to get what we want.
- return powerStore.update(getTipThermalMass() * setpointDelta, // the required power
- getTipInertia(), // Inertia, smaller numbers increase dominance of the previous value
- 2, // gain
- rate, // PID cycle frequency
+ // in X10 (J / °C) units as well.
+ return powerStore.update(((TemperatureType_t)getTipThermalMass()) * setpointDelta, // the required power
+ getTipInertia(), // Inertia, smaller numbers increase dominance of the previous value
+ 2, // gain
+ rate, // PID cycle frequency
getX10WattageLimits());
}
-void detectThermalRunaway(const int16_t currentTipTempInC, const int tError) {
- static uint16_t tipTempCRunawayTemp = 0;
- static TickType_t runawaylastChangeTime = 0;
+void detectThermalRunaway(const TemperatureType_t currentTipTempInC, const TemperatureType_t tError) {
+ static TemperatureType_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
@@ -160,7 +159,7 @@ void detectThermalRunaway(const int16_t currentTipTempInC, const int tError) {
if ((tError > THERMAL_RUNAWAY_TEMP_C)) {
// If we have heated up by more than 20C since last sample point, snapshot time and tip temp
- int16_t delta = (int16_t)currentTipTempInC - (int16_t)tipTempCRunawayTemp;
+ TemperatureType_t delta = currentTipTempInC - tipTempCRunawayTemp;
if (delta > THERMAL_RUNAWAY_TEMP_C) {
// We have heated up more than the threshold, reset the timer
tipTempCRunawayTemp = currentTipTempInC;