From 7a5c0ad20f95ae1115f9fe4987438fcbab2bf181 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 2 May 2021 15:45:45 +1000 Subject: [PATCH] Updated cold junction temp curve * Disabled the hack off on temp as we dont need it for MHP30 * faster ADC on MHP30 --- source/Core/BSP/Defines.h | 2 - source/Core/BSP/MHP30/BSP.cpp | 176 +++++++++++++++++++++++-- source/Core/BSP/MHP30/IRQ.cpp | 13 +- source/Core/BSP/Miniware/BSP.cpp | 1 + source/Core/BSP/Pine64/BSP.cpp | 3 +- source/Core/BSP/Pine64/ThermoModel.cpp | 2 +- source/Core/Drivers/TipThermoModel.cpp | 2 + source/Core/Inc/configuration.h | 22 ++-- source/Core/Threads/PIDThread.cpp | 3 +- 9 files changed, 191 insertions(+), 33 deletions(-) diff --git a/source/Core/BSP/Defines.h b/source/Core/BSP/Defines.h index f5a8d841..90359e4c 100644 --- a/source/Core/BSP/Defines.h +++ b/source/Core/BSP/Defines.h @@ -10,8 +10,6 @@ #include "FreeRTOSConfig.h" enum Orientation { ORIENTATION_LEFT_HAND = 0, ORIENTATION_RIGHT_HAND = 1, ORIENTATION_FLAT = 3 }; -// It is assumed that all hardware implements an 8Hz update period at this time -#define PID_TIM_HZ (8) #define TICKS_SECOND configTICK_RATE_HZ #define TICKS_MIN (60 * TICKS_SECOND) #define TICKS_100MS (TICKS_SECOND / 10) diff --git a/source/Core/BSP/MHP30/BSP.cpp b/source/Core/BSP/MHP30/BSP.cpp index 4da9d228..e7a9a362 100644 --- a/source/Core/BSP/MHP30/BSP.cpp +++ b/source/Core/BSP/MHP30/BSP.cpp @@ -7,6 +7,7 @@ #include "Setup.h" #include "TipThermoModel.h" #include "Utils.h" +#include "configuration.h" #include "history.hpp" #include "main.hpp" #include @@ -22,20 +23,167 @@ void resetWatchdog() { HAL_IWDG_Refresh(&hiwdg); } // Lookup table for the NTC // Stored as ADCReading,Temp in degC static const uint16_t NTCHandleLookup[] = { - // ADC Reading , Temp in C - 11292, 600, // - 12782, 550, // - 14380, 500, // - 16061, 450, // - 17793, 400, // - 19541, 350, // - 21261, 300, // - 22915, 250, // - 24465, 200, // - 25882, 150, // - 27146, 100, // - 28249, 50, // - 29189, 0, // + // ADC Reading , Temp in Cx10 + 808, 1600, // + 832, 1590, // + 848, 1580, // + 872, 1570, // + 888, 1560, // + 912, 1550, // + 936, 1540, // + 960, 1530, // + 984, 1520, // + 1008, 1510, // + 1032, 1500, // + 1056, 1490, // + 1080, 1480, // + 1112, 1470, // + 1136, 1460, // + 1168, 1450, // + 1200, 1440, // + 1224, 1430, // + 1256, 1420, // + 1288, 1410, // + 1328, 1400, // + 1360, 1390, // + 1392, 1380, // + 1432, 1370, // + 1464, 1360, // + 1504, 1350, // + 1544, 1340, // + 1584, 1330, // + 1632, 1320, // + 1672, 1310, // + 1720, 1300, // + 1760, 1290, // + 1808, 1280, // + 1856, 1270, // + 1912, 1260, // + 1960, 1250, // + 2016, 1240, // + 2072, 1230, // + 2128, 1220, // + 2184, 1210, // + 2248, 1200, // + 2304, 1190, // + 2368, 1180, // + 2440, 1170, // + 2504, 1160, // + 2576, 1150, // + 2648, 1140, // + 2720, 1130, // + 2792, 1120, // + 2872, 1110, // + 2952, 1100, // + 3040, 1090, // + 3128, 1080, // + 3216, 1070, // + 3304, 1060, // + 3400, 1050, // + 3496, 1040, // + 3592, 1030, // + 3696, 1020, // + 3800, 1010, // + 3912, 1000, // + 4024, 990, // + 4136, 980, // + 4256, 970, // + 4376, 960, // + 4504, 950, // + 4632, 940, // + 4768, 930, // + 4904, 920, // + 5048, 910, // + 5192, 900, // + 5336, 890, // + 5488, 880, // + 5648, 870, // + 5808, 860, // + 5976, 850, // + 6144, 840, // + 6320, 830, // + 6504, 820, // + 6688, 810, // + 6872, 800, // + 7072, 790, // + 7264, 780, // + 7472, 770, // + 7680, 760, // + 7896, 750, // + 8112, 740, // + 8336, 730, // + 8568, 720, // + 8800, 710, // + 9040, 700, // + 9288, 690, // + 9536, 680, // + 9792, 670, // + 10056, 660, // + 10320, 650, // + 10592, 640, // + 10872, 630, // + 11152, 620, // + 11440, 610, // + 11728, 600, // + 12024, 590, // + 12320, 580, // + 12632, 570, // + 12936, 560, // + 13248, 550, // + 13568, 540, // + 13888, 530, // + 14216, 520, // + 14544, 510, // + 14880, 500, // + 15216, 490, // + 15552, 480, // + 15888, 470, // + 16232, 460, // + 16576, 450, // + 16920, 440, // + 17272, 430, // + 17616, 420, // + 17968, 410, // + 18320, 400, // + 18664, 390, // + 19016, 380, // + 19368, 370, // + 19712, 360, // + 20064, 350, // + 20408, 340, // + 20752, 330, // + 21088, 320, // + 21432, 310, // + 21768, 300, // + 22096, 290, // + 22424, 280, // + 22752, 270, // + 23072, 260, // + 23392, 250, // + 23704, 240, // + 24008, 230, // + 24312, 220, // + 24608, 210, // + 24904, 200, // + 25192, 190, // + 25472, 180, // + 25744, 170, // + 26016, 160, // + 26280, 150, // + 26536, 140, // + 26784, 130, // + 27024, 120, // + 27264, 110, // + 27496, 100, // + 27720, 90, // + 27936, 80, // + 28144, 70, // + 28352, 60, // + 28544, 50, // + 28736, 40, // + 28920, 30, // + 29104, 20, // + 29272, 10, // }; const int NTCHandleLookupItems = sizeof(NTCHandleLookup) / (2 * sizeof(uint16_t)); #endif diff --git a/source/Core/BSP/MHP30/IRQ.cpp b/source/Core/BSP/MHP30/IRQ.cpp index 142a7f5b..1d51922d 100644 --- a/source/Core/BSP/MHP30/IRQ.cpp +++ b/source/Core/BSP/MHP30/IRQ.cpp @@ -15,12 +15,15 @@ * runs again */ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc) { - - BaseType_t xHigherPriorityTaskWoken = pdFALSE; + static uint8_t counter = 0; + BaseType_t xHigherPriorityTaskWoken = pdFALSE; if (hadc == &hadc1) { - if (pidTaskNotification) { - vTaskNotifyGiveFromISR(pidTaskNotification, &xHigherPriorityTaskWoken); - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + counter++; + if (counter % 4 == 0) { + if (pidTaskNotification) { + vTaskNotifyGiveFromISR(pidTaskNotification, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } } } } diff --git a/source/Core/BSP/Miniware/BSP.cpp b/source/Core/BSP/Miniware/BSP.cpp index 2de98bf2..ee20ec5a 100644 --- a/source/Core/BSP/Miniware/BSP.cpp +++ b/source/Core/BSP/Miniware/BSP.cpp @@ -6,6 +6,7 @@ #include "Pins.h" #include "Setup.h" #include "TipThermoModel.h" +#include "configuration.h" #include "history.hpp" #include "main.hpp" #include diff --git a/source/Core/BSP/Pine64/BSP.cpp b/source/Core/BSP/Pine64/BSP.cpp index 70cc04f1..a6990732 100644 --- a/source/Core/BSP/Pine64/BSP.cpp +++ b/source/Core/BSP/Pine64/BSP.cpp @@ -2,13 +2,14 @@ #include "BSP.h" #include "I2C_Wrapper.hpp" +#include "IRQ.h" #include "Pins.h" #include "Setup.h" #include "TipThermoModel.h" +#include "configuration.h" #include "gd32vf103_timer.h" #include "history.hpp" #include "main.hpp" -#include const uint16_t powerPWM = 255; const uint8_t holdoffTicks = 25; // delay of 7 ms diff --git a/source/Core/BSP/Pine64/ThermoModel.cpp b/source/Core/BSP/Pine64/ThermoModel.cpp index a8efdcb0..1f4da291 100644 --- a/source/Core/BSP/Pine64/ThermoModel.cpp +++ b/source/Core/BSP/Pine64/ThermoModel.cpp @@ -11,7 +11,7 @@ #ifdef TEMP_uV_LOOKUP_HAKKO const uint16_t uVtoDegC[] = { // - // + // uv -> temp in C 0, 0, // 266, 10, // 522, 20, // diff --git a/source/Core/Drivers/TipThermoModel.cpp b/source/Core/Drivers/TipThermoModel.cpp index 7088d33f..789275d4 100644 --- a/source/Core/Drivers/TipThermoModel.cpp +++ b/source/Core/Drivers/TipThermoModel.cpp @@ -75,7 +75,9 @@ uint32_t TipThermoModel::getTipInC(bool sampleNow) { // 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... +#ifndef NO_THERMAL_MASS_COMP currentTipTempInC -= x10WattHistory.average() / 25; +#endif if (currentTipTempInC < 0) return 0; return currentTipTempInC; diff --git a/source/Core/Inc/configuration.h b/source/Core/Inc/configuration.h index e48e0671..7a31e9cc 100644 --- a/source/Core/Inc/configuration.h +++ b/source/Core/Inc/configuration.h @@ -129,6 +129,7 @@ #define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS100 // #define TEMP_uV_LOOKUP_HAKKO // #define USB_PD_VMAX 20 // Maximum voltage for PD to negotiate +#define PID_TIM_HZ (8) #endif #ifdef MODEL_Pinecil @@ -141,6 +142,7 @@ #define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS100 // Uses TS100 resistors #define TEMP_uV_LOOKUP_HAKKO // Use Hakko lookup table #define USB_PD_VMAX 20 // Maximum voltage for PD to negotiate +#define PID_TIM_HZ (8) #endif #ifdef MODEL_TS80 @@ -153,6 +155,7 @@ #define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80 // #define TEMP_uV_LOOKUP_TS80 // #define USB_PD_VMAX 12 // Maximum voltage for PD to negotiate +#define PID_TIM_HZ (8) #endif #ifdef MODEL_TS80P @@ -165,17 +168,20 @@ #define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80 // #define TEMP_uV_LOOKUP_TS80 // #define USB_PD_VMAX 12 // Maximum voltage for PD to negotiate +#define PID_TIM_HZ (8) #endif #ifdef MODEL_MHP30 -#define VOLTAGE_DIV 355 // Default for MHP30 -#define PID_POWER_LIMIT 65 // Sets the max pwm power limit -#define CALIBRATION_OFFSET 0 // the adc offset in uV - MHP compensates automagically -#define POWER_LIMIT 65 // 65 watts default power limit -#define MAX_POWER_LIMIT 65 // -#define POWER_LIMIT_STEPS 2 // -#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_MHP30 // -#define USB_PD_VMAX 20 // Maximum voltage for PD to negotiate +#define VOLTAGE_DIV 355 // Default for MHP30 +#define PID_POWER_LIMIT 65 // Sets the max pwm power limit +#define CALIBRATION_OFFSET 0 // the adc offset in uV - MHP compensates automagically +#define POWER_LIMIT 65 // 65 watts default power limit +#define MAX_POWER_LIMIT 65 // +#define POWER_LIMIT_STEPS 2 // +#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_MHP30 // +#define USB_PD_VMAX 20 // Maximum voltage for PD to negotiate +#define PID_TIM_HZ (32) // We run a faster update rate (ballpark no for now) +#define NO_THERMAL_MASS_COMP // The temp sensor is mounted seperate to the heater so we dont need this #endif #ifdef MODEL_TS100 diff --git a/source/Core/Threads/PIDThread.cpp b/source/Core/Threads/PIDThread.cpp index 66302f99..83939916 100644 --- a/source/Core/Threads/PIDThread.cpp +++ b/source/Core/Threads/PIDThread.cpp @@ -73,7 +73,6 @@ void startPIDTask(void const *argument __unused) { // Once we have feed-forward temp estimation we should be able to better tune this. int32_t x10WattsNeeded = tempToX10Watts(tError); - // tempError.average()); // note that milliWattsNeeded is sometimes negative, this counters overshoot // from I term's inertia. x10WattsOut += x10WattsNeeded; @@ -106,7 +105,7 @@ void startPIDTask(void const *argument __unused) { } // Secondary safety check to forcefully disable header when within ADC noise of top of ADC - if (getTipRawTemp(0) > (0x7FFF - 150)) { + if (getTipRawTemp(0) > (0x7FFF - 32)) { x10WattsOut = 0; } if (systemSettings.powerLimit && x10WattsOut > (systemSettings.powerLimit * 10)) {