From c74bc36178441d1d77127aadd5510eebf7ee8eba Mon Sep 17 00:00:00 2001 From: discip <53649486+discip@users.noreply.github.com> Date: Fri, 4 Feb 2022 23:42:20 +0100 Subject: [PATCH 1/7] removing HALL from unsupported devices --- Translations/make_translation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Translations/make_translation.py b/Translations/make_translation.py index 217f1da2..0c3d5c71 100755 --- a/Translations/make_translation.py +++ b/Translations/make_translation.py @@ -127,7 +127,9 @@ def get_debug_menu() -> List[str]: "ACC ", "PWR ", "Max ", + #ifdef HALL_SENSOR "Hall ", + #endif ] From eba52bfd5b93498558c9af921607f74e805106a0 Mon Sep 17 00:00:00 2001 From: discip <53649486+discip@users.noreply.github.com> Date: Fri, 4 Feb 2022 23:43:13 +0100 Subject: [PATCH 2/7] removing HALL from unsupported devices _2 --- source/Core/Threads/GUIThread.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index b07e93bd..84b4c7bd 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -782,19 +782,17 @@ void showDebugMenu(void) { // Max deg C limit OLED::printNumber(TipThermoModel::getTipMaxInC(), 3, FontStyle::SMALL); break; +#ifdef HALL_SENSOR case 13: // Print raw hall effect value if availabe, none if hall effect disabled. -#ifdef HALL_SENSOR - { - int16_t hallEffectStrength = getRawHallEffect(); - if (hallEffectStrength < 0) - hallEffectStrength = -hallEffectStrength; - OLED::printNumber(hallEffectStrength, 6, FontStyle::SMALL); - } -#else - OLED::print(translatedString(Tr->OffString), FontStyle::SMALL); + { + int16_t hallEffectStrength = getRawHallEffect(); + if (hallEffectStrength < 0) + hallEffectStrength = -hallEffectStrength; + OLED::printNumber(hallEffectStrength, 6, FontStyle::SMALL); + } + break; #endif - break; default: break; } @@ -805,7 +803,11 @@ void showDebugMenu(void) { return; else if (b == BUTTON_F_SHORT) { screen++; +#ifdef HALL_SENSOR screen = screen % 14; +#else + screen = screen % 13; +#endif } GUIDelay(); } From c38dfb6007b2deb72bed04bb91efefadd70611f5 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sat, 5 Feb 2022 09:59:45 +1100 Subject: [PATCH 3/7] Dont wrap negative deltas --- source/Core/BSP/Miniware/configuration.h | 2 +- source/Core/Threads/PIDThread.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/Core/BSP/Miniware/configuration.h b/source/Core/BSP/Miniware/configuration.h index 69ff81af..72f6f816 100644 --- a/source/Core/BSP/Miniware/configuration.h +++ b/source/Core/BSP/Miniware/configuration.h @@ -95,7 +95,7 @@ #define DETAILED_IDLE 0 // 0: Disable 1: Enable - Default 0 #define THERMAL_RUNAWAY_TIME_SEC 20 -#define THERMAL_RUNAWAY_TEMP_C 20 +#define THERMAL_RUNAWAY_TEMP_C 10 #define CUT_OUT_SETTING 0 // default to no cut-off voltage #define RECOM_VOL_CELL 33 // Minimum voltage per cell (Recommended 3.3V (33)) diff --git a/source/Core/Threads/PIDThread.cpp b/source/Core/Threads/PIDThread.cpp index b87a488e..5173af3e 100644 --- a/source/Core/Threads/PIDThread.cpp +++ b/source/Core/Threads/PIDThread.cpp @@ -148,12 +148,12 @@ void detectThermalRunaway(const int16_t currentTipTempInC, const int tError) { // Check for thermal runaway, where it has been x seconds with negligible (y) temp rise // While trying to actively heat + + // If we are more than 20C below the setpoint if ((tError > THERMAL_RUNAWAY_TEMP_C)) { - // Temp error is high + + // 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; - if (delta < 0) { - delta = -delta; - } if (delta > THERMAL_RUNAWAY_TEMP_C) { // We have heated up more than the threshold, reset the timer tipTempCRunawayTemp = currentTipTempInC; From a461577ee26cbe157c90d6511b87d474e96f40a7 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sat, 5 Feb 2022 10:23:42 +1100 Subject: [PATCH 4/7] Update PIDThread.cpp Should use osDelay to be scheduler safe --- source/Core/Threads/PIDThread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/Threads/PIDThread.cpp b/source/Core/Threads/PIDThread.cpp index 5173af3e..4c56372c 100644 --- a/source/Core/Threads/PIDThread.cpp +++ b/source/Core/Threads/PIDThread.cpp @@ -40,7 +40,7 @@ void startPIDTask(void const *argument __unused) { uint32_t PIDTempTarget = 0; // Pre-seed the adc filters for (int i = 0; i < 128; i++) { - vTaskDelay(5); + osDelay(5); TipThermoModel::getTipInC(true); getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 1); } From 4f38236a00871201fa375579c5a6d70aa641d52b Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sat, 5 Feb 2022 10:23:56 +1100 Subject: [PATCH 5/7] Bugfix: Only change speed of pwm at end of cycle interrupt --- source/Core/BSP/Miniware/BSP.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/source/Core/BSP/Miniware/BSP.cpp b/source/Core/BSP/Miniware/BSP.cpp index 327cf05f..1d77a8c7 100644 --- a/source/Core/BSP/Miniware/BSP.cpp +++ b/source/Core/BSP/Miniware/BSP.cpp @@ -20,6 +20,7 @@ static const uint8_t tempMeasureTicks = 14; uint16_t totalPWM; // htim2.Init.Period, the full PWM cycle static bool fastPWM; +static bool infastPWM; void resetWatchdog() { HAL_IWDG_Refresh(&hiwdg); } #ifdef TEMP_NTC @@ -135,7 +136,7 @@ uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) { static void switchToFastPWM(void) { // 10Hz - fastPWM = true; + infastPWM = true; totalPWM = powerPWM + tempMeasureTicks + holdoffTicks; htim2.Instance->ARR = totalPWM; htim2.Instance->CCR1 = powerPWM + holdoffTicks; @@ -144,7 +145,7 @@ static void switchToFastPWM(void) { static void switchToSlowPWM(void) { // 5Hz - fastPWM = false; + infastPWM = false; totalPWM = powerPWM + tempMeasureTicks / 2 + holdoffTicks / 2; htim2.Instance->ARR = totalPWM; htim2.Instance->CCR1 = powerPWM + holdoffTicks / 2; @@ -152,16 +153,10 @@ static void switchToSlowPWM(void) { } 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 + PWMSafetyTimer = 20; // This is decremented in the handler for PWM so that the tip pwm is // disabled if the PID task is not scheduled often enough. + fastPWM = shouldUseFastModePWM; pendingPWM = pulse; - if (fastPWM != shouldUseFastModePWM) { - if (shouldUseFastModePWM) { - switchToFastPWM(); - } else { - switchToSlowPWM(); - } - } } // These are called by the HAL after the corresponding events from the system // timers. @@ -182,6 +177,14 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { } else { HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1); } + if (fastPWM != infastPWM) { + if (fastPWM) { + switchToFastPWM(); + } else { + switchToSlowPWM(); + } + } + } else if (htim->Instance == TIM1) { // STM uses this for internal functions as a counter for timeouts HAL_IncTick(); From 31c424bd727887c7bf8fce40bd41bd7dfd95ba91 Mon Sep 17 00:00:00 2001 From: discip <53649486+discip@users.noreply.github.com> Date: Sat, 5 Feb 2022 01:55:54 +0100 Subject: [PATCH 6/7] Update make_translation.py --- Translations/make_translation.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Translations/make_translation.py b/Translations/make_translation.py index 0c3d5c71..217f1da2 100755 --- a/Translations/make_translation.py +++ b/Translations/make_translation.py @@ -127,9 +127,7 @@ def get_debug_menu() -> List[str]: "ACC ", "PWR ", "Max ", - #ifdef HALL_SENSOR "Hall ", - #endif ] From 513a2d66bb0196ab416ff3ccc614ecce51a9cd62 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sat, 5 Feb 2022 12:34:08 +1100 Subject: [PATCH 7/7] Always set cursor back to (0,0) --- source/Core/Threads/GUIThread.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index 84b4c7bd..debeffff 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -616,6 +616,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) { printVoltage(); OLED::print(SymbolVolts, FontStyle::SMALL); } else { + OLED::setCursor(0, 0); // We switch the layout direction depending on the orientation of the oled if (OLED::getRotation()) { // battery