1
0
forked from me/IronOS

Calibrate CJC at next boot (#1398)

Changes Cold Junction Compensation (Tip Offset / CJC) to be performed during bootup time. (After starting in settings)
This commit is contained in:
discip
2022-09-10 12:52:57 +02:00
committed by GitHub
parent 19a6e169a7
commit c89db78b45
45 changed files with 572 additions and 557 deletions

View File

@@ -50,9 +50,10 @@ enum SettingsOptions {
OLEDInversion = 33, // Invert the colours on the display
OLEDBrightness = 34, // Brightness for the OLED display
LOGOTime = 35, // Duration the logo will be displayed for
CalibrateCJC = 36, // Toggle calibrate CJC at next boot
//
SettingsOptionsLength = 36, //
SettingsOptionsLength = 37, //
};
typedef enum {

View File

@@ -46,7 +46,7 @@ enum class SettingsItemIndex : uint8_t {
BoostTemperature,
AutoStart,
CooldownBlink,
TemperatureCalibration,
CalibrateCJC,
SettingsReset,
VoltageCalibration,
AdvancedSoldering,

View File

@@ -85,6 +85,7 @@ static const SettingConstants settingsConstants[(int)SettingsOptions::SettingsOp
{0, 1, 1, 0}, // OLEDInversion
{0, 99, 11, 33}, // OLEDBrightness
{0, 5, 1, 1}, // LOGOTime
{0, 1, 1, 0}, // CalibrateCJC
};
static_assert((sizeof(settingsConstants) / sizeof(SettingConstants)) == ((int)SettingsOptions::SettingsOptionsLength));

View File

@@ -101,8 +101,8 @@ static bool enterAdvancedMenu(void);
* Soldering
* Boost Mode Temp
* Auto Start
* Temp change short step
* Temp change long step
* Temp Change Short Step
* Temp Change Long Step
* Locking Mode
*
* Power Saving
@@ -114,10 +114,10 @@ static bool enterAdvancedMenu(void);
*
* UI
* Temperature Unit
* Display orientation
* Cooldown blink
* Display Orientation
* Cooldown Blink
* Scrolling Speed
* Reverse Temp change buttons + -
* Swap Temp Change Buttons + -
* Animation Speed
* -Animation Loop
* OLED Brightness
@@ -128,11 +128,11 @@ static bool enterAdvancedMenu(void);
*
* Advanced
* Power Limit
* Calibrate Temperature
* Calibrate CJC At Next Boot
* Calibrate Input V
* Power Pulse
* -Power Pulse Delay
* -Power Pulse duration
* -Power Pulse Duration
* Factory Reset
*
*/
@@ -184,8 +184,8 @@ const menuitem solderingMenu[] = {
/*
* Boost Mode Temp
* Auto Start
* Temp change short step
* Temp change long step
* Temp Change Short Step
* Temp Change Long Step
* Locking Mode
*/
{SETTINGS_DESC(SettingsItemIndex::BoostTemperature), setBoostTemp, displayBoostTemp, nullptr, SettingsOptions::SettingsOptionsLength, SettingsItemIndex::BoostTemperature, 5}, /*Boost Temp*/
@@ -221,10 +221,10 @@ const menuitem PowerSavingMenu[] = {
const menuitem UIMenu[] = {
/*
* Temperature Unit
* Display orientation
* Cooldown blink
* Display Orientation
* Cooldown Blink
* Scrolling Speed
* Reverse Temp change buttons + -
* Swap Temp Change Buttons + -
* Animation Speed
* -Animation Loop
* OLED Brightness
@@ -257,16 +257,16 @@ const menuitem UIMenu[] = {
const menuitem advancedMenu[] = {
/*
* Power Limit
* Calibrate Temperature
* Calibrate CJC At Next Boot
* Calibrate Input V
* Power Pulse
* -Power Pulse Delay
* -Power Pulse duration
* -Power Pulse Duration
* Factory Reset
*/
{SETTINGS_DESC(SettingsItemIndex::PowerLimit), nullptr, displayPowerLimit, nullptr, SettingsOptions::PowerLimit, SettingsItemIndex::PowerLimit, 5}, /*Power limit*/
{SETTINGS_DESC(SettingsItemIndex::TemperatureCalibration), setCalibrate, displayCalibrate, nullptr, SettingsOptions::SettingsOptionsLength, SettingsItemIndex::TemperatureCalibration,
5}, /*Calibrate tip*/
{SETTINGS_DESC(SettingsItemIndex::CalibrateCJC), setCalibrate, displayCalibrate, nullptr, SettingsOptions::SettingsOptionsLength, SettingsItemIndex::CalibrateCJC,
7}, /*Calibrate Cold Junktion Compensation at next boot*/
{SETTINGS_DESC(SettingsItemIndex::VoltageCalibration), setCalibrateVIN, displayCalibrateVIN, nullptr, SettingsOptions::SettingsOptionsLength, SettingsItemIndex::VoltageCalibration,
5}, /*Voltage input cal*/
{SETTINGS_DESC(SettingsItemIndex::PowerPulsePower), nullptr, displayPowerPulse, nullptr, SettingsOptions::KeepAwakePulse, SettingsItemIndex::PowerPulsePower, 5}, /*Power Pulse adjustment */
@@ -644,49 +644,20 @@ static void displayPowerLimit(void) {
}
}
static void setTipOffset() {
uint16_t setoffset = 0;
// If the thermo-couple at the end of the tip, and the handle are at
// equilibrium, then the output should be zero, as there is no temperature
// differential.
while (setoffset == 0) {
uint32_t offset = 0;
for (uint8_t i = 0; i < 16; i++) {
offset += getTipRawTemp(1);
// cycle through the filter a fair bit to ensure we're stable.
OLED::clearScreen();
OLED::setCursor(0, 0);
OLED::print(SymbolDot, FontStyle::LARGE);
for (uint8_t x = 0; x < (i / 4); x++)
OLED::print(SymbolDot, FontStyle::LARGE);
OLED::refresh();
osDelay(100);
}
setoffset = TipThermoModel::convertTipRawADCTouV(offset / 16, true);
}
setSettingValue(SettingsOptions::CalibrationOffset, setoffset);
OLED::clearScreen();
OLED::setCursor(0, 0);
OLED::drawCheckbox(true);
OLED::printNumber(setoffset, 4, FontStyle::LARGE);
OLED::refresh();
osDelay(1200);
}
// Provide the user the option to tune their own tip if custom is selected
// If not only do single point tuning as per usual
static bool setCalibrate(void) {
if (userConfirmation(translatedString(Tr->SettingsCalibrationWarning))) {
// User confirmed
// So we now perform the actual calculation
setTipOffset();
if (getSettingValue(SettingsOptions::CalibrateCJC) < 1) {
if (userConfirmation(translatedString(Tr->SettingsCalibrationWarning))) {
// User confirmed
// So we now set the tick
setSettingValue(SettingsOptions::CalibrateCJC, 1);
}
} else {
setSettingValue(SettingsOptions::CalibrateCJC, 0);
}
return false;
}
static void displayCalibrate(void) {}
static void displayCalibrate(void) { OLED::drawCheckbox(getSettingValue(SettingsOptions::CalibrateCJC)); }
static bool setCalibrateVIN(void) {
// Jump to the voltage calibration subscreen

View File

@@ -94,6 +94,42 @@ void gui_drawTipTemp(bool symbol, const FontStyle font) {
}
}
}
void performCJCC() {
// Calibrate Cold Junction Compensation directly at boot, before internal components get warm.
OLED::refresh();
osDelay(50);
if (!isTipDisconnected() && (TipThermoModel::getTipInC() - getHandleTemperature(0) / 10) < 10) {
uint16_t setoffset = 0;
// If the thermo-couple at the end of the tip, and the handle are at
// equilibrium, then the output should be zero, as there is no temperature
// differential.
while (setoffset == 0) {
uint32_t offset = 0;
for (uint8_t i = 0; i < 16; i++) {
offset += getTipRawTemp(1);
// cycle through the filter a fair bit to ensure we're stable.
OLED::clearScreen();
OLED::setCursor(0, 0);
OLED::print(SymbolDot, FontStyle::LARGE);
for (uint8_t x = 0; x < (i / 4); x++)
OLED::print(SymbolDot, FontStyle::LARGE);
OLED::refresh();
osDelay(100);
}
setoffset = TipThermoModel::convertTipRawADCTouV(offset / 16, true);
}
setSettingValue(SettingsOptions::CalibrationOffset, setoffset);
OLED::clearScreen();
OLED::setCursor(0, 0);
OLED::drawCheckbox(true);
OLED::printNumber(setoffset, 5, FontStyle::LARGE);
OLED::refresh();
osDelay(1200);
// Preventing to repeat calibration at boot automatically (only one shot).
setSettingValue(SettingsOptions::CalibrateCJC, 0);
saveSettings();
}
}
#ifdef POW_DC
// returns true if undervoltage has occured
@@ -688,10 +724,9 @@ void showDebugMenu(void) {
OLED::setCursor(0, 8); // second line
OLED::print(DebugMenu[screen], FontStyle::SMALL);
switch (screen) {
case 0: // Build Date
case 0: // Build Date
break;
case 1:
// Device ID
case 1: // Device ID
{
uint64_t id = getDeviceID();
#ifdef DEVICE_HAS_VALIDATION_CODE
@@ -706,46 +741,10 @@ void showDebugMenu(void) {
OLED::drawHex((uint32_t)(id & 0xFFFFFFFF), FontStyle::SMALL, 8);
}
break;
case 2:
// System Uptime
OLED::printNumber(xTaskGetTickCount() / TICKS_100MS, 5, FontStyle::SMALL);
break;
case 3:
// Movement Timestamp
OLED::printNumber(lastMovementTime / TICKS_100MS, 5, FontStyle::SMALL);
break;
case 4:
// ACC Type
case 2: // ACC Type
OLED::print(AccelTypeNames[(int)DetectedAccelerometerVersion], FontStyle::SMALL);
break;
case 5:
// Tip Resistance
OLED::printNumber(getTipResistanceX10() / 10, 4, FontStyle::SMALL); // large to pad over so that we cover ID left overs
OLED::print(SymbolDot, FontStyle::SMALL);
OLED::printNumber(getTipResistanceX10() % 10, 1, FontStyle::SMALL);
break;
case 6:
// Raw Tip in uV
{ OLED::printNumber(TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true), 6, FontStyle::SMALL); }
break;
case 7:
// Temp in C
OLED::printNumber(TipThermoModel::getTipInC(), 5, FontStyle::SMALL);
break;
case 8:
// Handle Temp in C
OLED::printNumber(getHandleTemperature(0), 6, FontStyle::SMALL);
break;
case 9:
// Max C Limit
OLED::printNumber(TipThermoModel::getTipMaxInC(), 3, FontStyle::SMALL);
break;
case 10:
// Input Voltage
printVoltage();
break;
case 11:
// Power Negotiation Status
case 3: // Power Negotiation Status
{
int sourceNumber = 0;
if (getIsPoweredByDCIN()) {
@@ -780,22 +779,49 @@ void showDebugMenu(void) {
OLED::print(PowerSourceNames[sourceNumber], FontStyle::SMALL);
}
break;
case 12:
// High Water Mark for GUI
OLED::printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5, FontStyle::SMALL);
case 4: // Input Voltage
printVoltage();
break;
case 13:
// High Water Mark for Movement Task
OLED::printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5, FontStyle::SMALL);
case 5: // Temp in °C
OLED::printNumber(TipThermoModel::getTipInC(), 6, FontStyle::SMALL);
break;
case 14:
// High Water Mark for PID Task
OLED::printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5, FontStyle::SMALL);
case 6: // Handle Temp in °C
OLED::printNumber(getHandleTemperature(0) / 10, 6, FontStyle::SMALL);
OLED::print(SymbolDot, FontStyle::SMALL);
OLED::printNumber(getHandleTemperature(0) % 10, 1, FontStyle::SMALL);
break;
case 7: // Max Temp Limit in °C
OLED::printNumber(TipThermoModel::getTipMaxInC(), 6, FontStyle::SMALL);
break;
case 8: // System Uptime
OLED::printNumber(xTaskGetTickCount() / TICKS_100MS, 8, FontStyle::SMALL);
break;
case 9: // Movement Timestamp
OLED::printNumber(lastMovementTime / TICKS_100MS, 8, FontStyle::SMALL);
break;
case 10: // Tip Resistance in Ω
OLED::printNumber(getTipResistanceX10() / 10, 6, FontStyle::SMALL); // large to pad over so that we cover ID left overs
OLED::print(SymbolDot, FontStyle::SMALL);
OLED::printNumber(getTipResistanceX10() % 10, 1, FontStyle::SMALL);
break;
case 11: // Raw Tip in µV
OLED::printNumber(TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true), 8, FontStyle::SMALL);
break;
case 12: // Tip Cold Junction Compensation Offset in µV
OLED::printNumber(getSettingValue(SettingsOptions::CalibrationOffset), 8, FontStyle::SMALL);
break;
case 13: // High Water Mark for GUI
OLED::printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 8, FontStyle::SMALL);
break;
case 14: // High Water Mark for Movement Task
OLED::printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 8, FontStyle::SMALL);
break;
case 15: // High Water Mark for PID Task
OLED::printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 8, FontStyle::SMALL);
break;
break;
#ifdef HALL_SENSOR
case 15:
// Raw Hall Effect Value
case 16: // Raw Hall Effect Value
{
int16_t hallEffectStrength = getRawHallEffect();
if (hallEffectStrength < 0)
@@ -816,9 +842,9 @@ void showDebugMenu(void) {
else if (b == BUTTON_F_SHORT) {
screen++;
#ifdef HALL_SENSOR
screen = screen % 16;
screen = screen % 17;
#else
screen = screen % 15;
screen = screen % 16;
#endif
}
GUIDelay();
@@ -996,6 +1022,11 @@ void startGUITask(void const *argument) {
}
#endif
#endif
if (getSettingValue(SettingsOptions::CalibrateCJC) > 0) {
performCJCC();
}
// If the boot logo is enabled (but it times out) and the autostart mode is enabled (but not set to sleep w/o heat), start heating during boot logo
if (getSettingValue(SettingsOptions::LOGOTime) > 0 && getSettingValue(SettingsOptions::LOGOTime) < 5 && getSettingValue(SettingsOptions::AutoStartMode) > 0
&& getSettingValue(SettingsOptions::AutoStartMode) < 3) {
@@ -1005,7 +1036,7 @@ void startGUITask(void const *argument) {
} else {
sleepTempDegC = getSettingValue(SettingsOptions::SleepTemp);
}
// Only heat to sleep temperature (but no higher than 75*C for safety)
// Only heat to sleep temperature (but no higher than 75°C for safety)
currentTempTargetDegC = min(sleepTempDegC, 75);
}