From 293c09cffaf7fb988f6341cc6bb39a37fdd4b32d Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Thu, 6 May 2021 21:35:43 +1000 Subject: [PATCH] Add slew rate to the PID output for MHP --- source/Core/Inc/configuration.h | 2 +- source/Core/Threads/PIDThread.cpp | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/source/Core/Inc/configuration.h b/source/Core/Inc/configuration.h index f70f83b4..66f3f828 100644 --- a/source/Core/Inc/configuration.h +++ b/source/Core/Inc/configuration.h @@ -220,7 +220,7 @@ #define MIN_BOOST_TEMP_C 150 // The min settable temp for boost mode °C #define MIN_BOOST_TEMP_F 300 // The min settable temp for boost mode °F #define NO_DISPLAY_ROTATE // Disable OLED rotation by accel - +#define SLEW_LIMIT 50 // Limit to 3.0 Watts per 64ms pid loop update rate slew rate #endif #ifdef MODEL_TS100 diff --git a/source/Core/Threads/PIDThread.cpp b/source/Core/Threads/PIDThread.cpp index 278de3a3..e8a69073 100644 --- a/source/Core/Threads/PIDThread.cpp +++ b/source/Core/Threads/PIDThread.cpp @@ -34,6 +34,9 @@ void startPIDTask(void const *argument __unused) { // be over-ridden rapidly pidTaskNotification = xTaskGetCurrentTaskHandle(); uint32_t PIDTempTarget = 0; +#ifdef SLEW_LIMIT + int32_t x10WattsOutLast = 0; +#endif for (;;) { if (ulTaskNotifyTake(pdTRUE, 2000)) { @@ -109,12 +112,21 @@ void startPIDTask(void const *argument __unused) { x10WattsOut = 0; } if (systemSettings.powerLimit && x10WattsOut > (systemSettings.powerLimit * 10)) { - setTipX10Watts(systemSettings.powerLimit * 10); - } else if (powerSupplyWattageLimit && x10WattsOut > powerSupplyWattageLimit * 10) { - setTipX10Watts(powerSupplyWattageLimit * 10); - } else { - setTipX10Watts(x10WattsOut); + x10WattsOut = systemSettings.powerLimit * 10; } + if (powerSupplyWattageLimit && x10WattsOut > powerSupplyWattageLimit * 10) { + x10WattsOut = powerSupplyWattageLimit * 10; + } +#ifdef SLEW_LIMIT + if (x10WattsOut - x10WattsOutLast > SLEW_LIMIT) { + x10WattsOut = x10WattsOutLast + SLEW_LIMIT; + } + if (x10WattsOut < 0) { + x10WattsOut = 0; + } + x10WattsOutLast = x10WattsOut; +#endif + setTipX10Watts(x10WattsOut); #ifdef DEBUG_UART_OUTPUT log_system_state(x10WattsOut); #endif