From e7bcf920badd672e77d4972bd378f33e3df29f30 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 4 Jun 2023 12:13:26 +1000 Subject: [PATCH] Refactor PinecilV2 Tuning Closes #1688 --- source/Core/BSP/BSP_Power.h | 2 ++ source/Core/BSP/MHP30/BSP.cpp | 3 ++- source/Core/BSP/Miniware/BSP.cpp | 4 +++- source/Core/BSP/Pinecil/BSP.cpp | 3 ++- source/Core/BSP/Pinecilv2/BSP.cpp | 14 +++++++++----- source/Core/BSP/Sequre_S60/BSP.cpp | 3 ++- source/Core/Threads/PIDThread.cpp | 8 ++++---- 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/source/Core/BSP/BSP_Power.h b/source/Core/BSP/BSP_Power.h index ef1f4aee..46c4ae2e 100644 --- a/source/Core/BSP/BSP_Power.h +++ b/source/Core/BSP/BSP_Power.h @@ -20,6 +20,8 @@ void power_check(); uint8_t getTipResistanceX10(); uint8_t getTipThermalMass(); +uint8_t getTipInertia(); + #ifdef __cplusplus } diff --git a/source/Core/BSP/MHP30/BSP.cpp b/source/Core/BSP/MHP30/BSP.cpp index 2c4b3381..ad3328f9 100644 --- a/source/Core/BSP/MHP30/BSP.cpp +++ b/source/Core/BSP/MHP30/BSP.cpp @@ -471,4 +471,5 @@ uint64_t getDeviceID() { uint8_t preStartChecksDone() { return 1; } -uint8_t getTipThermalMass() { return TIP_THERMAL_MASS; } \ No newline at end of file +uint8_t getTipThermalMass() { return TIP_THERMAL_MASS; } +uint8_t getTipInertia() { return TIP_THERMAL_MASS; } \ No newline at end of file diff --git a/source/Core/BSP/Miniware/BSP.cpp b/source/Core/BSP/Miniware/BSP.cpp index beb83c34..96e44dad 100644 --- a/source/Core/BSP/Miniware/BSP.cpp +++ b/source/Core/BSP/Miniware/BSP.cpp @@ -257,4 +257,6 @@ uint8_t getTipResistanceX10() { return TIP_RESISTANCE; } uint8_t preStartChecksDone() { return 1; } -uint8_t getTipThermalMass() { return TIP_THERMAL_MASS; } \ No newline at end of file +uint8_t getTipThermalMass() { return TIP_THERMAL_MASS; } + +uint8_t getTipInertia() { return TIP_THERMAL_MASS; } \ No newline at end of file diff --git a/source/Core/BSP/Pinecil/BSP.cpp b/source/Core/BSP/Pinecil/BSP.cpp index 9c918b62..bbbfbb19 100644 --- a/source/Core/BSP/Pinecil/BSP.cpp +++ b/source/Core/BSP/Pinecil/BSP.cpp @@ -96,4 +96,5 @@ uint8_t getTipResistanceX10() { return TIP_RESISTANCE; } uint8_t preStartChecksDone() { return 1; } -uint8_t getTipThermalMass() { return TIP_THERMAL_MASS; } \ No newline at end of file +uint8_t getTipThermalMass() { return TIP_THERMAL_MASS; } +uint8_t getTipInertia() { return TIP_THERMAL_MASS; } \ No newline at end of file diff --git a/source/Core/BSP/Pinecilv2/BSP.cpp b/source/Core/BSP/Pinecilv2/BSP.cpp index 0ca2d10c..28646a18 100644 --- a/source/Core/BSP/Pinecilv2/BSP.cpp +++ b/source/Core/BSP/Pinecilv2/BSP.cpp @@ -21,7 +21,7 @@ const uint8_t tempMeasureTicks = 25; uint16_t totalPWM = 255; // Total length of the cycle's ticks void resetWatchdog() { - //#TODO + // #TODO } #ifdef TEMP_NTC @@ -125,9 +125,7 @@ uint8_t getButtonB() { return val; } -void reboot() { - hal_system_reset(); -} +void reboot() { hal_system_reset(); } void delay_ms(uint16_t count) { // delay_1ms(count); @@ -164,7 +162,13 @@ uint8_t getTipThermalMass() { if (lastTipResistance >= 80) { return TIP_THERMAL_MASS; } - return (TIP_THERMAL_MASS * 25) / 10; + return 45; +} +uint8_t getTipInertia() { + if (lastTipResistance >= 80) { + return TIP_THERMAL_MASS; + } + return 10; } // We want to calculate lastTipResistance // If tip is connected, and the tip is cold and the tip is not being heated diff --git a/source/Core/BSP/Sequre_S60/BSP.cpp b/source/Core/BSP/Sequre_S60/BSP.cpp index 94f10c27..8a41d18b 100644 --- a/source/Core/BSP/Sequre_S60/BSP.cpp +++ b/source/Core/BSP/Sequre_S60/BSP.cpp @@ -233,6 +233,7 @@ uint8_t getTipResistanceX10() { return TIP_RESISTANCE; } uint8_t preStartChecksDone() { return 1; } -uint8_t getTipThermalMass() { return TIP_THERMAL_INERTIA; } +uint8_t getTipThermalMass() { return TIP_THERMAL_MASS; } +uint8_t getTipInertia() { return TIP_THERMAL_INERTIA; } void setBuzzer(bool on) {} \ No newline at end of file diff --git a/source/Core/Threads/PIDThread.cpp b/source/Core/Threads/PIDThread.cpp index 7ef8816c..026a414c 100644 --- a/source/Core/Threads/PIDThread.cpp +++ b/source/Core/Threads/PIDThread.cpp @@ -142,10 +142,10 @@ int32_t getPIDResultX10Watts(int32_t setpointDelta) { // 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(TIP_THERMAL_MASS * setpointDelta, // the required power - getTipThermalMass(), // Inertia, smaller numbers increase dominance of the previous value - 2, // gain - rate, // PID cycle frequency + return powerStore.update(getTipThermalMass() * setpointDelta, // the required power + getTipInertia(), // Inertia, smaller numbers increase dominance of the previous value + 2, // gain + rate, // PID cycle frequency getX10WattageLimits()); }