From ad857a08ab7fc2212c1da5a56bc980f6f4490797 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 14 Sep 2021 22:01:10 +1000 Subject: [PATCH] QC code does not get control of vin filter --- source/Core/BSP/Miniware/Setup.cpp | 2 +- source/Core/Src/QC3.cpp | 8 ++++---- source/Core/Threads/PIDThread.cpp | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/Core/BSP/Miniware/Setup.cpp b/source/Core/BSP/Miniware/Setup.cpp index 93b7a6e6..b86c86ff 100644 --- a/source/Core/BSP/Miniware/Setup.cpp +++ b/source/Core/BSP/Miniware/Setup.cpp @@ -20,7 +20,7 @@ DMA_HandleTypeDef hdma_i2c1_tx; IWDG_HandleTypeDef hiwdg; TIM_HandleTypeDef htim2; TIM_HandleTypeDef htim3; -#define ADC_FILTER_LEN 32 +#define ADC_FILTER_LEN 4 #define ADC_SAMPLES 16 uint16_t ADCReadings[ADC_SAMPLES]; // Used to store the adc readings for the handle cold junction temp diff --git a/source/Core/Src/QC3.cpp b/source/Core/Src/QC3.cpp index 6a11c5de..4fa0bf4f 100644 --- a/source/Core/Src/QC3.cpp +++ b/source/Core/Src/QC3.cpp @@ -70,7 +70,7 @@ void seekQC(int16_t Vx10, uint16_t divisor) { // try and step towards the wanted value // 1. Measure current voltage - int16_t vStart = getInputVoltageX10(divisor, 1); + int16_t vStart = getInputVoltageX10(divisor, 0); int difference = Vx10 - vStart; // 2. calculate ideal steps (0.2V changes) @@ -94,7 +94,7 @@ void seekQC(int16_t Vx10, uint16_t divisor) { #ifdef ENABLE_QC2 // Re-measure /* Disabled due to nothing to test and code space of around 1k*/ - steps = vStart - getInputVoltageX10(divisor, 1); + steps = vStart - getInputVoltageX10(divisor, 0); if (steps < 0) steps = -steps; if (steps > 4) { @@ -118,7 +118,7 @@ void seekQC(int16_t Vx10, uint16_t divisor) { void startQC(uint16_t divisor) { // Pre check that the input could be >5V already, and if so, dont both // negotiating as someone is feeding in hv - if (getInputVoltageX10(divisor, 1) > 80) { + if (getInputVoltageX10(divisor, 0) > 80) { QCTries = 11; QCMode = QCState::NO_QC; return; @@ -160,7 +160,7 @@ void startQC(uint16_t divisor) { // Wait for frontend ADC to stabilise QCMode = QCState::QC_2; for (uint8_t i = 0; i < 10; i++) { - if (getInputVoltageX10(divisor, 1) > 80) { + if (getInputVoltageX10(divisor, 0) > 80) { // yay we have at least QC2.0 or QC3.0 QCMode = QCState::QC_3; // We have at least QC2, pray for 3 return; diff --git a/source/Core/Threads/PIDThread.cpp b/source/Core/Threads/PIDThread.cpp index 718fd9ee..fbd03d56 100644 --- a/source/Core/Threads/PIDThread.cpp +++ b/source/Core/Threads/PIDThread.cpp @@ -64,8 +64,8 @@ void startPIDTask(void const *argument __unused) { PIDTempTarget = TipThermoModel::getTipMaxInC(); } int32_t tError = PIDTempTarget - currentTipTempInC; - tError = tError > INT16_MAX ? INT16_MAX : tError; - tError = tError < INT16_MIN ? INT16_MIN : tError; + // tError = tError > INT16_MAX ? INT16_MAX : tError; + // tError = tError < INT16_MIN ? INT16_MIN : tError; detectThermalRunaway(currentTipTempInC, tError); x10WattsOut = getPIDResultX10Watts(tError); @@ -138,7 +138,7 @@ int32_t getPIDResultX10Watts(int32_t setpointDelta) { // so we basically double the need (gain = 2) to get what we want. return powerStore.update(TIP_THERMAL_MASS * setpointDelta, // the required power TIP_THERMAL_MASS, // inertia factor - 2, // gain + 1, // gain rate, // PID cycle frequency getX10WattageLimits()); }