diff options
author | Ben V. Brown <[email protected]> | 2020-12-28 16:13:30 +1100 |
---|---|---|
committer | Ben V. Brown <[email protected]> | 2020-12-28 16:13:30 +1100 |
commit | 27bf2a17110373cb1a30bed259ac2fbc1b374c5c (patch) | |
tree | ed29997f3c9c935c0d1f7f09cb11bf8f3c900798 /workspace | |
parent | 53deac02e78d96eed082def9839b576a07b898fd (diff) | |
download | IronOS-27bf2a17110373cb1a30bed259ac2fbc1b374c5c.tar.gz IronOS-27bf2a17110373cb1a30bed259ac2fbc1b374c5c.zip |
Move to lookuptable for tip calibration
Diffstat (limited to 'workspace')
-rwxr-xr-x | workspace/TS100/Core/Drivers/TipThermoModel.cpp | 75 | ||||
-rwxr-xr-x | workspace/TS100/Core/Inc/Settings.h | 1 | ||||
-rwxr-xr-x | workspace/TS100/Core/Src/Settings.cpp | 1 | ||||
-rwxr-xr-x | workspace/TS100/Core/Src/gui.cpp | 100 |
4 files changed, 115 insertions, 62 deletions
diff --git a/workspace/TS100/Core/Drivers/TipThermoModel.cpp b/workspace/TS100/Core/Drivers/TipThermoModel.cpp index 18ab0a10..c472932a 100755 --- a/workspace/TS100/Core/Drivers/TipThermoModel.cpp +++ b/workspace/TS100/Core/Drivers/TipThermoModel.cpp @@ -39,6 +39,7 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) { uint32_t valueuV = rawInputmVX10 * 100; // shift into uV //Now to divide this down by the gain valueuV = (valueuV) / OP_AMP_GAIN_STAGE; + //Remove uV tipOffset if (valueuV >= systemSettings.CalibrationOffset) valueuV -= systemSettings.CalibrationOffset; @@ -68,17 +69,71 @@ int32_t LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_ return y1 + (((((x - x1) * 1000) / (x2 - x1)) * (y2 - y1))) / 1000; } +const uint16_t uVtoDegC[] = { 0, 0, // + 175, 10, // + 381, 20, // + 587, 30, // + 804, 40, // + 1005, 50, // + 1007, 60, // + 1107, 70, // + 1310, 80, // + 1522, 90, // + 1731, 100, // + 1939, 110, // + 2079, 120, // + 2265, 130, // + 2470, 140, // + 2676, 150, // + 2899, 160, // + 3081, 170, // + 3186, 180, // + 3422, 190, // + 3622, 200, // + 3830, 210, // + 4044, 220, // + 4400, 230, // + 4691, 240, // + 4989, 250, // + 5289, 260, // + 5583, 270, // + 5879, 280, // + 6075, 290, // + 6332, 300, // + 6521, 310, // + 6724, 320, // + 6929, 330, // + 7132, 340, // + 7356, 350, // + 7561, 360, // + 7774, 370, // + 7992, 380, // + 8200, 390, // + 8410, 400, // + 8626, 410, // + 8849, 420, // + 9060, 430, // + 9271, 440, // + 9531, 450, // + 9748, 460, // + 10210, 470, // + 10219, 480, // + 10429, 490, // + 10649, 500, // + + }; uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { - //based on new measurements, tip is quite linear - // - tipuVDelta *= 10; - tipuVDelta /= systemSettings.TipGain; - -#if defined( MODEL_TS80)+defined( MODEL_TS80P)>0 - tipuVDelta /= OP_AMP_GAIN_STAGE_TS100 / OP_AMP_GAIN_STAGE_TS80; -#endif - - return tipuVDelta; + if (tipuVDelta) { + int noItems = sizeof(uVtoDegC) / (2 * sizeof(uint16_t)); + for (int i = 1; i < (noItems - 1); i++) { + //If current tip temp is less than current lookup, then this current loopup is the higher point to interpolate + if (tipuVDelta < uVtoDegC[i * 2]) { + return LinearInterpolate(uVtoDegC[(i - 1) * 2], uVtoDegC[((i - 1) * 2) + 1], uVtoDegC[i * 2], uVtoDegC[(i * 2) + 1], tipuVDelta); + } + } + return LinearInterpolate(uVtoDegC[(noItems - 2) * 2], uVtoDegC[((noItems - 2) * 2) + 1], uVtoDegC[(noItems - 1) * 2], uVtoDegC[((noItems - 1) * 2) + 1], tipuVDelta); + } + return 0; } #ifdef ENABLED_FAHRENHEIT_SUPPORT diff --git a/workspace/TS100/Core/Inc/Settings.h b/workspace/TS100/Core/Inc/Settings.h index e9ca84e9..b1524399 100755 --- a/workspace/TS100/Core/Inc/Settings.h +++ b/workspace/TS100/Core/Inc/Settings.h @@ -51,7 +51,6 @@ typedef struct { uint8_t powerLimit; // Maximum power iron allowed to output - uint16_t TipGain; // uV/C * 10, it can be used to convert tip thermocouple voltage to temperateture TipV/TipGain = TipTemp uint8_t ReverseButtonTempChangeEnabled; // Change the plus and minus button assigment uint16_t TempChangeLongStep; // Change the plus and minus button assigment diff --git a/workspace/TS100/Core/Src/Settings.cpp b/workspace/TS100/Core/Src/Settings.cpp index 581a3f40..3faa0ea3 100755 --- a/workspace/TS100/Core/Src/Settings.cpp +++ b/workspace/TS100/Core/Src/Settings.cpp @@ -77,7 +77,6 @@ void resetSettings() { systemSettings.TempChangeShortStep = TEMP_CHANGE_SHORT_STEP; // systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP; // systemSettings.KeepAwakePulse = POWER_PULSE_DEFAULT; - systemSettings.TipGain = TIP_GAIN; systemSettings.hallEffectSensitivity = 1; saveSettings(); // Save defaults } diff --git a/workspace/TS100/Core/Src/gui.cpp b/workspace/TS100/Core/Src/gui.cpp index 0518d8e4..002f9ef1 100755 --- a/workspace/TS100/Core/Src/gui.cpp +++ b/workspace/TS100/Core/Src/gui.cpp @@ -59,8 +59,8 @@ static bool settings_setResetSettings(void); static void settings_displayResetSettings(void); static bool settings_setCalibrate(void); static void settings_displayCalibrate(void); -static bool settings_setTipGain(void); -static void settings_displayTipGain(void); +//static bool settings_setTipGain(void); +//static void settings_displayTipGain(void); static bool settings_setCalibrateVIN(void); static void settings_displayCalibrateVIN(void); static void settings_displayReverseButtonTempChangeEnabled(void); @@ -212,7 +212,7 @@ const menuitem advancedMenu[] = { { (const char *) SettingsDescriptions[11], settings_setCalibrate, settings_displayCalibrate }, /*Calibrate tip*/ { (const char *) SettingsDescriptions[13], settings_setCalibrateVIN, settings_displayCalibrateVIN }, /*Voltage input cal*/ { (const char *) SettingsDescriptions[24], settings_setPowerPulse, settings_displayPowerPulse }, /*Power Pulse adjustment */ -{ (const char *) SettingsDescriptions[25], settings_setTipGain, settings_displayTipGain }, /*TipGain*/ +//{ (const char *) SettingsDescriptions[25], settings_setTipGain, settings_displayTipGain }, /*TipGain*/ { NULL, NULL, NULL } // end of menu marker. DO NOT REMOVE }; @@ -778,53 +778,53 @@ static bool settings_setCalibrateVIN(void) { } return false; } - -static bool settings_setTipGain(void) { - OLED::setFont(0); - OLED::clearScreen(); - - for (;;) { - OLED::setCursor(0, 0); - OLED::printNumber(systemSettings.TipGain / 10, 2); - OLED::print(SymbolDot); - OLED::printNumber(systemSettings.TipGain % 10, 1); - - ButtonState buttons = getButtonState(); - switch (buttons) { - case BUTTON_F_SHORT: - systemSettings.TipGain -= 1; - break; - - case BUTTON_B_SHORT: - systemSettings.TipGain += 1; - break; - - case BUTTON_BOTH: - case BUTTON_F_LONG: - case BUTTON_B_LONG: - saveSettings(); - return false; - case BUTTON_NONE: - default: - break; - } - - OLED::refresh(); - osDelay(40); - - // Cap to sensible values - if (systemSettings.TipGain < 150) { - systemSettings.TipGain = 150; - } else if (systemSettings.TipGain > 300) { - systemSettings.TipGain = 300; - } - } - return false; -} - -static void settings_displayTipGain(void) { - printShortDescription(25, 5); -} +// +//static bool settings_setTipGain(void) { +// OLED::setFont(0); +// OLED::clearScreen(); +// +// for (;;) { +// OLED::setCursor(0, 0); +// OLED::printNumber(systemSettings.TipGain / 10, 2); +// OLED::print(SymbolDot); +// OLED::printNumber(systemSettings.TipGain % 10, 1); +// +// ButtonState buttons = getButtonState(); +// switch (buttons) { +// case BUTTON_F_SHORT: +// systemSettings.TipGain -= 1; +// break; +// +// case BUTTON_B_SHORT: +// systemSettings.TipGain += 1; +// break; +// +// case BUTTON_BOTH: +// case BUTTON_F_LONG: +// case BUTTON_B_LONG: +// saveSettings(); +// return false; +// case BUTTON_NONE: +// default: +// break; +// } +// +// OLED::refresh(); +// osDelay(40); +// +// // Cap to sensible values +// if (systemSettings.TipGain < 150) { +// systemSettings.TipGain = 150; +// } else if (systemSettings.TipGain > 300) { +// systemSettings.TipGain = 300; +// } +// } +// return false; +//} +// +//static void settings_displayTipGain(void) { +// printShortDescription(25, 5); +//} static bool settings_setReverseButtonTempChangeEnabled(void) { systemSettings.ReverseButtonTempChangeEnabled = !systemSettings.ReverseButtonTempChangeEnabled; |