Adding adc2 & new temperature calibration proceedures. [WiP] (#361)
* Add rough calls to ADC2 [untested] * Using dual ADC injected modes * Start both ADCs * Move some IRQ's to ram exec * Stabilize PID a bit more * Add in ideas for tip type selection * Add tiptype formula / settings struct * Add function ids to the settings menu * Rough tip selection * Rough out new cal routine for simple tips * Hardware test is fairly close for first pass * Add Simple calibration case [UNTESTED] This adds the calibration option that uses boiling water to the calibration menu. This is untested, and may need gain adjustments before use. * Simple Cal Roughly working * Rough out advanced cal
This commit is contained in:
@@ -52,11 +52,19 @@ static void settings_setCoolingBlinkEnabled(void);
|
||||
static void settings_displayCoolingBlinkEnabled(void);
|
||||
static void settings_setResetSettings(void);
|
||||
static void settings_displayResetSettings(void);
|
||||
static void settings_setTipModel(void);
|
||||
static void settings_displayTipModel(void);
|
||||
static void settings_setCalibrate(void);
|
||||
static void settings_displayCalibrate(void);
|
||||
static void settings_setCalibrateVIN(void);
|
||||
static void settings_displayCalibrateVIN(void);
|
||||
|
||||
//Calibration Menu
|
||||
static void calibration_displaySimpleCal(void); // Hot water cal
|
||||
static void calibration_enterSimpleCal(void);
|
||||
static void calibration_displayAdvancedCal(void); // two point cal
|
||||
static void calibration_enterAdvancedCal(void);
|
||||
|
||||
//Menu functions
|
||||
static void settings_displaySolderingMenu(void);
|
||||
static void settings_enterSolderingMenu(void);
|
||||
@@ -185,6 +193,8 @@ const menuitem advancedMenu[] = {
|
||||
settings_displayAdvancedSolderingScreens } }, /* Advanced soldering screen*/
|
||||
{ (const char*) SettingsDescriptions[13], { settings_setResetSettings }, {
|
||||
settings_displayResetSettings } }, /*Resets settings*/
|
||||
{ (const char*) SettingsDescriptions[17], { settings_setTipModel }, {
|
||||
settings_displayTipModel } }, /*Select tip Model */
|
||||
{ (const char*) SettingsDescriptions[12], { settings_setCalibrate }, {
|
||||
settings_displayCalibrate } }, /*Calibrate tip*/
|
||||
{ (const char*) SettingsDescriptions[14], { settings_setCalibrateVIN }, {
|
||||
@@ -201,6 +211,13 @@ const menuitem advancedMenu[] = {
|
||||
{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE
|
||||
};
|
||||
|
||||
const menuitem calibrationMenu[] { { (const char*) SettingsDescriptions[6], {
|
||||
calibration_enterSimpleCal }, { calibration_displaySimpleCal } },
|
||||
/* Simple Cal*/
|
||||
{ (const char*) SettingsDescriptions[6], { calibration_enterAdvancedCal }, {
|
||||
calibration_displayAdvancedCal } }, /* Advanced Cal */
|
||||
{ NULL, { NULL }, { NULL } } };
|
||||
|
||||
static void printShortDescriptionSingleLine(uint32_t shortDescIndex) {
|
||||
lcd.setFont(0);
|
||||
lcd.setCharCursor(0, 0);
|
||||
@@ -569,30 +586,214 @@ static void settings_displayResetSettings(void) {
|
||||
printShortDescription(13, 7);
|
||||
}
|
||||
|
||||
static void settings_setCalibrate(void) {
|
||||
if (userConfirmation(SettingsCalibrationWarning)) {
|
||||
//User confirmed
|
||||
//So we now perform the actual calculation
|
||||
static void settings_setTipModel(void) {
|
||||
systemSettings.tipType++;
|
||||
systemSettings.tipType %= (Tip_Custom + 1); //Wrap after custom
|
||||
|
||||
}
|
||||
static void settings_displayTipModel(void) {
|
||||
printShortDescription(17, 4);
|
||||
//Print in small text the tip model
|
||||
lcd.setFont(1);
|
||||
//set the cursor
|
||||
//Print the mfg
|
||||
lcd.setCursor(40, 0);
|
||||
if (systemSettings.tipType < Tip_MiniWare) {
|
||||
lcd.print("TS100");
|
||||
} else if (systemSettings.tipType < Tip_Hakko) {
|
||||
lcd.print("HAKKO");
|
||||
} else if (systemSettings.tipType == Tip_Custom) {
|
||||
lcd.print("User");
|
||||
}
|
||||
lcd.setCursor(40, 8);
|
||||
switch ((enum TipType) systemSettings.tipType) {
|
||||
case TS_B2:
|
||||
lcd.print(" B2 ");
|
||||
break;
|
||||
case TS_D24:
|
||||
lcd.print(" D24 ");
|
||||
break;
|
||||
case TS_BC2:
|
||||
lcd.print(" BC2 ");
|
||||
break;
|
||||
case TS_C1:
|
||||
lcd.print(" C1 ");
|
||||
break;
|
||||
case HAKKO_BC2:
|
||||
lcd.print(" BC2 ");
|
||||
break;
|
||||
case Tip_Custom:
|
||||
lcd.print("Tuned");
|
||||
break;
|
||||
default:
|
||||
lcd.print("????");
|
||||
break;
|
||||
}
|
||||
}
|
||||
static void calibration_displaySimpleCal(void) {
|
||||
printShortDescription(18, 5);
|
||||
}
|
||||
static void dotDelay() {
|
||||
for (uint8_t i = 0; i < 20; i++) {
|
||||
getTipRawTemp(1); //cycle through the filter a fair bit to ensure we're stable.
|
||||
lcd.clearScreen();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(".....");
|
||||
for (uint8_t x = 0; x < i / 4; x++)
|
||||
lcd.print(".");
|
||||
lcd.refresh();
|
||||
osDelay(50);
|
||||
}
|
||||
}
|
||||
static void setTipOffset() {
|
||||
setCalibrationOffset(0); //turn off the current offset
|
||||
dotDelay();
|
||||
|
||||
setCalibrationOffset(0); //turn off the current offset
|
||||
for (uint8_t i = 0; i < 20; i++) {
|
||||
getTipRawTemp(1); //cycle through the filter a fair bit to ensure we're stable.
|
||||
osDelay(20);
|
||||
//If the thermocouple at the end of the tip, and the handle are at equalibrium, then the output should be zero, as there is no temperature differential.
|
||||
|
||||
int32_t offset = 0;
|
||||
for (uint8_t i = 0; i < 15; i++) {
|
||||
offset += getTipRawTemp(1); //cycle through the filter a fair bit to ensure we're stable.
|
||||
|
||||
lcd.clearScreen();
|
||||
lcd.setCursor(0, 0);
|
||||
|
||||
for (uint8_t x = 0; x < i / 4; x++)
|
||||
lcd.print(".");
|
||||
lcd.refresh();
|
||||
osDelay(200);
|
||||
}
|
||||
systemSettings.CalibrationOffset = offset / 15;
|
||||
setCalibrationOffset(systemSettings.CalibrationOffset); //store the error
|
||||
osDelay(100);
|
||||
}
|
||||
static void calibration_enterSimpleCal(void) {
|
||||
//User has entered into the simple cal routine
|
||||
if (userConfirmation(SettingsCalibrationWarning)) {
|
||||
//User has confirmed their handle is at ambient
|
||||
//So take the offset measurement
|
||||
setTipOffset();
|
||||
//Next we want the user to put the tip into 100C water so we can calculate their tip's gain
|
||||
//Gain is the m term from rise/run plot of raw readings vs (tip-handle)
|
||||
//Thus we want to calculate ([TipRawHot-TipRawCold])/(ActualHot-HandleHot)-(ActualCold-HandleCold)
|
||||
//Thus we first need to store -> TiprawCold,HandleCold,ActualCold==HandleCold -> RawTipCold
|
||||
uint32_t RawTipCold = getTipRawTemp(0) * 10;
|
||||
lcd.clearScreen();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.setFont(1);
|
||||
lcd.print("Please Insert Tip\nInto Boiling Water");
|
||||
lcd.refresh();
|
||||
osDelay(200);
|
||||
waitForButtonPress();
|
||||
dotDelay(); //cycle the filter a bit
|
||||
//Now take the three hot measurements
|
||||
//Assume water is boiling at 100C
|
||||
uint32_t RawTipHot = getTipRawTemp(0) * 10;
|
||||
uint32_t HandleTempHot = getHandleTemperature() / 10;
|
||||
|
||||
uint32_t gain = (RawTipHot - RawTipCold) / (100 - HandleTempHot);
|
||||
|
||||
//Show this to the user
|
||||
lcd.clearScreen();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Your G: ");
|
||||
lcd.printNumber(gain, 6);
|
||||
lcd.print("\n~= 120-140");
|
||||
lcd.refresh();
|
||||
osDelay(2000);
|
||||
waitForButtonPress();
|
||||
lcd.clearScreen();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("H: ");
|
||||
lcd.printNumber(RawTipHot, 8);
|
||||
lcd.setCursor(0, 8);
|
||||
lcd.print("C: ");
|
||||
lcd.printNumber(RawTipCold, 8);
|
||||
lcd.refresh();
|
||||
osDelay(2000);
|
||||
waitForButtonPress();
|
||||
}
|
||||
}
|
||||
static void calibration_displayAdvancedCal(void) {
|
||||
printShortDescription(19, 5);
|
||||
}
|
||||
static void calibration_enterAdvancedCal(void) {
|
||||
//Advanced cal
|
||||
if (userConfirmation(SettingsCalibrationWarning)) {
|
||||
//User has confirmed their handle is at ambient
|
||||
//So take the offset measurement
|
||||
setTipOffset();
|
||||
//The tip now has a known ADC offset
|
||||
//Head up until it is at 350C
|
||||
//Then let the user adjust the gain value until it converges
|
||||
systemSettings.customTipGain = 120;
|
||||
bool exit = false;
|
||||
|
||||
while (exit == false) {
|
||||
//Set tip to 350C
|
||||
currentlyActiveTemperatureTarget = ctoTipMeasurement(350);
|
||||
//Check if user has pressed button to change the gain
|
||||
ButtonState buttons = getButtonState();
|
||||
switch (buttons) {
|
||||
case BUTTON_NONE:
|
||||
break;
|
||||
case BUTTON_BOTH:
|
||||
case BUTTON_B_LONG:
|
||||
case BUTTON_F_LONG:
|
||||
exit = true;
|
||||
break;
|
||||
case BUTTON_F_SHORT:
|
||||
systemSettings.customTipGain++;
|
||||
break;
|
||||
case BUTTON_B_SHORT: {
|
||||
systemSettings.customTipGain--;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (systemSettings.customTipGain > 200)
|
||||
systemSettings.customTipGain = 200;
|
||||
else if (systemSettings.customTipGain <= 100)
|
||||
systemSettings.customTipGain = 100;
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.clearScreen();
|
||||
lcd.setFont(0);
|
||||
if (lcd.getRotation())
|
||||
lcd.drawChar('-');
|
||||
else
|
||||
lcd.drawChar('+');
|
||||
|
||||
lcd.drawChar(' ');
|
||||
lcd.printNumber(systemSettings.customTipGain, 4);
|
||||
lcd.drawChar(' ');
|
||||
if (lcd.getRotation())
|
||||
lcd.drawChar('+');
|
||||
else
|
||||
lcd.drawChar('-');
|
||||
lcd.refresh();
|
||||
GUIDelay();
|
||||
}
|
||||
osDelay(100);
|
||||
|
||||
uint16_t rawTempC = tipMeasurementToC(getTipRawTemp(0));
|
||||
//We now measure the current reported tip temperature
|
||||
uint16_t handleTempC = getHandleTemperature() / 10;
|
||||
//We now have an error between these that we want to store as the offset
|
||||
rawTempC = rawTempC - handleTempC;
|
||||
systemSettings.CalibrationOffset = rawTempC;
|
||||
setCalibrationOffset(rawTempC); //store the error
|
||||
osDelay(100);
|
||||
}
|
||||
}
|
||||
//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 void settings_setCalibrate(void) {
|
||||
if (systemSettings.tipType == Tip_Custom) {
|
||||
//Two types of calibration
|
||||
//1. Basic, idle temp + hot water (100C)
|
||||
//2. Advanced, 100C + 350C, we keep PID tracking to a temperature target
|
||||
return gui_Menu(calibrationMenu);
|
||||
}
|
||||
//Else
|
||||
// Ask user if handle is at the tip temperature
|
||||
// Any error between handle and the tip will be a direct offset in the control loop
|
||||
|
||||
else if (userConfirmation(SettingsCalibrationWarning)) {
|
||||
//User confirmed
|
||||
//So we now perform the actual calculation
|
||||
setTipOffset();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user