mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Add voltage calibration
This commit is contained in:
@@ -38,7 +38,7 @@ extern "C" {
|
||||
|
||||
uint16_t getHandleTemperature();
|
||||
uint16_t getTipRawTemp(uint8_t instant);
|
||||
uint16_t getInputVoltageX10();
|
||||
uint16_t getInputVoltageX10(uint8_t divisor);
|
||||
uint16_t getTipInstantTemperature();
|
||||
uint8_t getTipPWM();
|
||||
void setTipPWM(uint8_t pulse);
|
||||
|
||||
@@ -80,8 +80,8 @@ void resetSettings() {
|
||||
systemSettings.advancedScreens = 0; //Do we show detailed screens?
|
||||
systemSettings.OrientationMode = 2; //Default to automatic
|
||||
systemSettings.sensitivity = 8; //Default high sensitivity
|
||||
systemSettings.voltageDiv = 144; //Default divider from schematic
|
||||
systemSettings.ShutdownTime = 30; //How many minutes until the unit turns itself off
|
||||
systemSettings.voltageDiv = 117; //Default divider from schematic
|
||||
systemSettings.ShutdownTime = 15; //How many minutes until the unit turns itself off
|
||||
systemSettings.boostModeEnabled = 1; //Default to safe, with no boost mode
|
||||
systemSettings.BoostTemp = 420; //default to 400C
|
||||
systemSettings.powerDisplay = 0; //default to power display being off
|
||||
|
||||
@@ -47,7 +47,7 @@ uint16_t getADC(uint8_t channel) {
|
||||
uint32_t sum = 0;
|
||||
for (uint8_t i = 0; i < 32; i++)
|
||||
sum += ADCReadings[channel + (i * 2)];
|
||||
return sum >> 3;
|
||||
return sum >> 2;
|
||||
}
|
||||
|
||||
/** System Clock Configuration
|
||||
|
||||
@@ -33,14 +33,16 @@ const char* SettingsLongNames[14] = {
|
||||
"Temperature when in \"boost\" mode", //
|
||||
"Automatically starts the iron into soldering on power up. T=Soldering, S= Sleep mode,F=Off", //
|
||||
"Blink the temperature on the cooling screen while the tip is still hot.", //
|
||||
"Calibrate tip offset.", //s
|
||||
"Reset all settings", };
|
||||
"Calibrate tip offset.", //
|
||||
"Reset all settings", //
|
||||
"VIN Calibration. Buttons adjust, long press to exit", //
|
||||
};
|
||||
|
||||
const char* SettingsCalibrationWarning = "Please ensure the tip is at room temperature before continuing!";
|
||||
const char* UVLOWarningString = "LOW VOLT"; //Fixed width 8 chars
|
||||
const char* SleepingSimpleString = "ZZzz"; // Must be <= 4 chars
|
||||
const char* SleepingAdvancedString = "Sleeping..."; // <=17 chars
|
||||
const char* WarningSimpleString = "WARN"; //Must be <= 4 chars
|
||||
const char* WarningSimpleString = "HOT!"; //Must be <= 4 chars
|
||||
const char* WarningAdvancedString = "WARNING! TIP HOT!";
|
||||
|
||||
const char SettingTrueChar = 'V';
|
||||
|
||||
@@ -37,6 +37,8 @@ static void settings_setResetSettings(void);
|
||||
static void settings_displayResetSettings(void);
|
||||
static void settings_setCalibrate(void);
|
||||
static void settings_displayCalibrate(void);
|
||||
static void settings_setCalibrateVIN(void);
|
||||
static void settings_displayCalibrateVIN(void);
|
||||
|
||||
bool settingsResetRequest = false;
|
||||
const menuitem settingsMenu[] = { /*Struct used for all settings options in the settings menu*/
|
||||
@@ -47,13 +49,14 @@ const menuitem settingsMenu[] = { /*Struct used for all settings options in the
|
||||
{ (const char*) SettingsLongNames[4], { settings_setSensitivity }, { settings_displaySensitivity } },/* Motion Sensitivity*/
|
||||
{ (const char*) SettingsLongNames[5], { settings_setTempF }, { settings_displayTempF } },/* Motion Sensitivity*/
|
||||
{ (const char*) SettingsLongNames[6], { settings_setAdvancedScreens }, { settings_displayAdvancedScreens } },/* Advanced screens*/
|
||||
{ (const char*) SettingsLongNames[7], { settings_setDisplayRotation }, { settings_displayDisplayRotation } }, /**/
|
||||
{ (const char*) SettingsLongNames[8], { settings_setBoostModeEnabled }, { settings_displayBoostModeEnabled } }, /**/
|
||||
{ (const char*) SettingsLongNames[9], { settings_setBoostTemp }, { settings_displayBoostTemp } }, /**/
|
||||
{ (const char*) SettingsLongNames[10], { settings_setAutomaticStartMode }, { settings_displayAutomaticStartMode } },/**/
|
||||
{ (const char*) SettingsLongNames[11], { settings_setCoolingBlinkEnabled }, { settings_displayCoolingBlinkEnabled } }, /**/
|
||||
{ (const char*) SettingsLongNames[12], { settings_setCalibrate }, { settings_displayCalibrate } }, /**/
|
||||
{ (const char*) SettingsLongNames[13], { settings_setResetSettings }, { settings_displayResetSettings } }, /**/
|
||||
{ (const char*) SettingsLongNames[7], { settings_setDisplayRotation }, { settings_displayDisplayRotation } }, /*Display Rotation*/
|
||||
{ (const char*) SettingsLongNames[8], { settings_setBoostModeEnabled }, { settings_displayBoostModeEnabled } }, /*Enable Boost*/
|
||||
{ (const char*) SettingsLongNames[9], { settings_setBoostTemp }, { settings_displayBoostTemp } }, /*Boost Temp*/
|
||||
{ (const char*) SettingsLongNames[10], { settings_setAutomaticStartMode }, { settings_displayAutomaticStartMode } },/*Auto start*/
|
||||
{ (const char*) SettingsLongNames[11], { settings_setCoolingBlinkEnabled }, { settings_displayCoolingBlinkEnabled } }, /*Cooling blink warning*/
|
||||
{ (const char*) SettingsLongNames[12], { settings_setCalibrate }, { settings_displayCalibrate } }, /*Calibrate tip*/
|
||||
{ (const char*) SettingsLongNames[13], { settings_setResetSettings }, { settings_displayResetSettings } }, /*Resets settings*/
|
||||
{ (const char*) SettingsLongNames[14], { settings_setCalibrateVIN }, { settings_displayCalibrateVIN } }, /*Voltage input cal*/
|
||||
{ NULL, { NULL }, { NULL } } //end of menu marker. DO NOT REMOVE
|
||||
};
|
||||
|
||||
@@ -269,3 +272,48 @@ static void settings_setCalibrate(void) {
|
||||
static void settings_displayCalibrate(void) {
|
||||
lcd.print(SettingsShortNames[12]);
|
||||
}
|
||||
|
||||
static void settings_setCalibrateVIN(void) {
|
||||
//Jump to the voltage calibration subscreen
|
||||
lcd.setFont(0);
|
||||
lcd.clearScreen();
|
||||
lcd.setCursor(0, 0);
|
||||
for (;;) {
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv)/10,2);
|
||||
lcd.print(".");
|
||||
lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv)%10,1);
|
||||
lcd.print("V");
|
||||
|
||||
ButtonState buttons = getButtonState();
|
||||
switch (buttons) {
|
||||
case BUTTON_F_SHORT:
|
||||
systemSettings.voltageDiv++;
|
||||
break;
|
||||
case BUTTON_B_SHORT:
|
||||
systemSettings.voltageDiv--;
|
||||
break;
|
||||
case BUTTON_BOTH:
|
||||
case BUTTON_F_LONG:
|
||||
case BUTTON_B_LONG:
|
||||
saveSettings();
|
||||
return;
|
||||
break;
|
||||
case BUTTON_NONE:
|
||||
break;
|
||||
}
|
||||
lcd.refresh();
|
||||
osDelay(50);
|
||||
if(systemSettings.voltageDiv<90)
|
||||
systemSettings.voltageDiv=90;
|
||||
else if (systemSettings.voltageDiv>130)
|
||||
systemSettings.voltageDiv=130;
|
||||
//Cap to sensible values
|
||||
}
|
||||
}
|
||||
static void settings_displayCalibrateVIN(void) {
|
||||
lcd.clearScreen();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("CAL VIN?");
|
||||
|
||||
}
|
||||
|
||||
@@ -16,15 +16,15 @@ uint16_t getHandleTemperature() {
|
||||
// We return the current handle temperature in X10 C
|
||||
// TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for example)
|
||||
// STM32 = 4096 count @ 3.3V input -> But
|
||||
// We oversample by 32/(2^3) = 4 times oversampling
|
||||
// Therefore 16384 is the 3.3V input, so 0.201416015625 mV per count
|
||||
// We oversample by 32/(2^2) = 8 times oversampling
|
||||
// Therefore 32768 is the 3.3V input, so 0.201416015625 mV per count
|
||||
// So we need to subtract an offset of 0.5V to center on 0C (2482 counts)
|
||||
//
|
||||
uint16_t result = getADC(0);
|
||||
if (result < 2482)
|
||||
if (result < 4964)
|
||||
return 0;
|
||||
result -= 2482;
|
||||
result /= 5; //convert to X10 C
|
||||
result -= 4964;//remove 0.5V offset
|
||||
result /= 10; //convert to X10 C
|
||||
return result;
|
||||
|
||||
}
|
||||
@@ -87,11 +87,12 @@ uint16_t getTipRawTemp(uint8_t instant) {
|
||||
return total / filterDepth2;
|
||||
}
|
||||
}
|
||||
uint16_t getInputVoltageX10() {
|
||||
uint16_t getInputVoltageX10(uint8_t divisor) {
|
||||
//ADC maximum is 16384 == 3.3V at input == 28V at VIN
|
||||
//Therefore we can divide down from there
|
||||
//Ideal term is 57.69.... 58 is quite close
|
||||
return getADC(1) / 58;
|
||||
//Ideal term is 117
|
||||
|
||||
return getADC(1) / divisor;
|
||||
}
|
||||
uint8_t getTipPWM() {
|
||||
return htim2.Instance->CCR4;
|
||||
|
||||
@@ -71,7 +71,10 @@ int main(void) {
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
void GUIDelay()
|
||||
{
|
||||
osDelay(50);
|
||||
}
|
||||
ButtonState getButtonState() {
|
||||
/*
|
||||
* Read in the buttons and then determine if a state change needs to occur
|
||||
@@ -139,14 +142,13 @@ static void waitForButtonPress() {
|
||||
ButtonState buttons = getButtonState();
|
||||
while (buttons) {
|
||||
buttons = getButtonState();
|
||||
osDelay(100);
|
||||
GUIDelay();
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
lcd.refresh();
|
||||
}
|
||||
while (!buttons) {
|
||||
buttons = getButtonState();
|
||||
|
||||
osDelay(100);
|
||||
GUIDelay();
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
lcd.refresh();
|
||||
}
|
||||
@@ -160,7 +162,7 @@ static void waitForButtonPressOrTimeout(uint32_t timeout) {
|
||||
return;
|
||||
if (HAL_GetTick() > timeout)
|
||||
return;
|
||||
osDelay(50);
|
||||
GUIDelay();
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
|
||||
}
|
||||
@@ -168,7 +170,7 @@ static void waitForButtonPressOrTimeout(uint32_t timeout) {
|
||||
|
||||
//returns true if undervoltage has occured
|
||||
static bool checkVoltageForExit() {
|
||||
uint16_t v = getInputVoltageX10();
|
||||
uint16_t v = getInputVoltageX10(systemSettings.voltageDiv);
|
||||
if ((v < lookupVoltageLevel(systemSettings.cutoutSetting))) {
|
||||
lcd.clearScreen();
|
||||
lcd.setCursor(0, 0);
|
||||
@@ -177,9 +179,9 @@ static bool checkVoltageForExit() {
|
||||
lcd.print("Undervoltage");
|
||||
lcd.setCursor(0, 8);
|
||||
lcd.print("Input V: ");
|
||||
lcd.printNumber(getInputVoltageX10() / 10, 2);
|
||||
lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) / 10, 2);
|
||||
lcd.drawChar('.');
|
||||
lcd.printNumber(getInputVoltageX10() % 10, 1);
|
||||
lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) % 10, 1);
|
||||
lcd.print("V");
|
||||
|
||||
} else {
|
||||
@@ -199,7 +201,7 @@ static void gui_drawBatteryIcon() {
|
||||
//User is on a lithium battery
|
||||
//we need to calculate which of the 10 levels they are on
|
||||
uint8_t cellCount = systemSettings.cutoutSetting + 2;
|
||||
uint16_t cellV = getInputVoltageX10() / cellCount;
|
||||
uint16_t cellV = getInputVoltageX10(systemSettings.voltageDiv) / cellCount;
|
||||
//Should give us approx cell voltage X10
|
||||
//Range is 42 -> 33 = 9 steps therefore we will use battery 1-10
|
||||
if (cellV < 33)
|
||||
@@ -280,7 +282,7 @@ static void gui_solderingTempAdjust() {
|
||||
lcd.drawChar(' ');
|
||||
lcd.drawChar('>');
|
||||
lcd.refresh();
|
||||
osDelay(10);
|
||||
GUIDelay();
|
||||
}
|
||||
}
|
||||
static void gui_settingsMenu() {
|
||||
@@ -341,7 +343,7 @@ static void gui_settingsMenu() {
|
||||
}
|
||||
}
|
||||
lcd.refresh(); //update the LCD
|
||||
osDelay(20); //pause for a sec
|
||||
GUIDelay();
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
|
||||
}
|
||||
@@ -392,7 +394,7 @@ static void gui_showTipTempWarning() {
|
||||
return;
|
||||
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
osDelay(200);
|
||||
GUIDelay();
|
||||
}
|
||||
}
|
||||
static int gui_SolderingSleepingMode() {
|
||||
@@ -432,9 +434,9 @@ static int gui_SolderingSleepingMode() {
|
||||
lcd.print("C");
|
||||
|
||||
lcd.print(" VIN:");
|
||||
lcd.printNumber(getInputVoltageX10() / 10, 2);
|
||||
lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) / 10, 2);
|
||||
lcd.drawChar('.');
|
||||
lcd.printNumber(getInputVoltageX10() % 10, 1);
|
||||
lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) % 10, 1);
|
||||
} else {
|
||||
lcd.setFont(0);
|
||||
lcd.print(SleepingSimpleString);
|
||||
@@ -452,7 +454,7 @@ static int gui_SolderingSleepingMode() {
|
||||
return 1; //we want to exit soldering mode
|
||||
}
|
||||
lcd.refresh();
|
||||
osDelay(100);
|
||||
GUIDelay();
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
|
||||
}
|
||||
@@ -597,7 +599,7 @@ static void gui_solderingMode() {
|
||||
if (gui_SolderingSleepingMode())
|
||||
return; //If the function returns non-0 then exit
|
||||
}
|
||||
osDelay(100);
|
||||
GUIDelay();
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
|
||||
@@ -682,7 +684,6 @@ void startGUITask(void const * argument) {
|
||||
gui_solderingMode(); //enter soldering mode
|
||||
tempWarningState = 0; //make sure warning can show
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
osDelay(500);
|
||||
break;
|
||||
case BUTTON_B_SHORT:
|
||||
lcd.setFont(0);
|
||||
@@ -691,7 +692,6 @@ void startGUITask(void const * argument) {
|
||||
saveSettings();
|
||||
setCalibrationOffset(systemSettings.CalibrationOffset);
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
osDelay(250);
|
||||
break;
|
||||
}
|
||||
currentlyActiveTemperatureTarget = 0; //ensure tip is off
|
||||
@@ -733,9 +733,9 @@ void startGUITask(void const * argument) {
|
||||
}
|
||||
lcd.setCursor(0, 8);
|
||||
lcd.print("Input V: ");
|
||||
lcd.printNumber(getInputVoltageX10() / 10, 2);
|
||||
lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) / 10, 2);
|
||||
lcd.drawChar('.');
|
||||
lcd.printNumber(getInputVoltageX10() % 10, 1);
|
||||
lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) % 10, 1);
|
||||
lcd.print("V");
|
||||
|
||||
} else {
|
||||
@@ -754,7 +754,7 @@ void startGUITask(void const * argument) {
|
||||
lcd.refresh();
|
||||
animationStep++;
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
osDelay(80);
|
||||
GUIDelay();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -869,7 +869,7 @@ void startMOVTask(void const * argument) {
|
||||
|
||||
}
|
||||
|
||||
osDelay(10);
|
||||
osDelay(20);//Slow down update rate
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user