diff options
author | Kyle Repinski <[email protected]> | 2018-09-20 01:35:33 -0500 |
---|---|---|
committer | Ben V. Brown <[email protected]> | 2018-09-20 16:35:33 +1000 |
commit | 0c7be326e5f89388a94fdf3a8b38043898f802c3 (patch) | |
tree | 8728a5fb9a465947397d323692cc54e15a004d96 | |
parent | 54ec20cd9fe13af4e719b83358da96e5aa87f711 (diff) | |
download | IronOS-0c7be326e5f89388a94fdf3a8b38043898f802c3.tar.gz IronOS-0c7be326e5f89388a94fdf3a8b38043898f802c3.zip |
Allow more precise input voltage divider calibration. (#359)
Finer input voltage calibration
Settings divisor is stored as uint16_t, not uint8_t.
* Allow more precise input voltage divider calibration.
The existing code changed the input voltage by multiple
tenths of a volt per adjustment, which is way too coarse.
This commit simply multiplies the ADC value (and its divisor)
by 4, which allows for finer calibration adjustments.
Unfortunately, for safety reasons this requires a settings
version bump. While old stored divider values can be detected
and multiplied by 4 on startup to update them, if the user
downgrades firmware it will happily read the new higher value
and cause all sorts of problems (which could be either reading
higher *or* lower depending on how getInputVoltageX10's
parameter wraps around in old firmware due to incorrect type.
-rw-r--r-- | workspace/TS100/inc/hardware.h | 2 | ||||
-rw-r--r-- | workspace/TS100/src/Settings.cpp | 2 | ||||
-rw-r--r-- | workspace/TS100/src/gui.cpp | 8 | ||||
-rw-r--r-- | workspace/TS100/src/hardware.c | 9 |
4 files changed, 11 insertions, 10 deletions
diff --git a/workspace/TS100/inc/hardware.h b/workspace/TS100/inc/hardware.h index 93a5ddc2..6d945b3f 100644 --- a/workspace/TS100/inc/hardware.h +++ b/workspace/TS100/inc/hardware.h @@ -54,7 +54,7 @@ enum TipType { uint16_t getHandleTemperature(); uint16_t getTipRawTemp(uint8_t instant); -uint16_t getInputVoltageX10(uint8_t divisor); +uint16_t getInputVoltageX10(uint16_t divisor); uint16_t getTipInstantTemperature(); uint8_t getTipPWM(); void setTipPWM(uint8_t pulse); diff --git a/workspace/TS100/src/Settings.cpp b/workspace/TS100/src/Settings.cpp index 5ceea20f..fbafa8f7 100644 --- a/workspace/TS100/src/Settings.cpp +++ b/workspace/TS100/src/Settings.cpp @@ -83,7 +83,7 @@ void resetSettings() { systemSettings.detailedIDLE = 0;// Detailed idle screen (off for first time users) systemSettings.OrientationMode = 2; //Default to automatic systemSettings.sensitivity = 7; //Default high sensitivity - systemSettings.voltageDiv = 117; //Default divider from schematic + systemSettings.voltageDiv = 467; //Default divider from schematic systemSettings.ShutdownTime = 10;//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 diff --git a/workspace/TS100/src/gui.cpp b/workspace/TS100/src/gui.cpp index 59b3e74e..8f3c109d 100644 --- a/workspace/TS100/src/gui.cpp +++ b/workspace/TS100/src/gui.cpp @@ -839,10 +839,10 @@ static void settings_setCalibrateVIN(void) { osDelay(40); // Cap to sensible values - if (systemSettings.voltageDiv < 90) { - systemSettings.voltageDiv = 90; - } else if (systemSettings.voltageDiv > 130) { - systemSettings.voltageDiv = 130; + if (systemSettings.voltageDiv < 360) { + systemSettings.voltageDiv = 360; + } else if (systemSettings.voltageDiv > 520) { + systemSettings.voltageDiv = 520; } } } diff --git a/workspace/TS100/src/hardware.c b/workspace/TS100/src/hardware.c index 0dc1172f..ce383790 100644 --- a/workspace/TS100/src/hardware.c +++ b/workspace/TS100/src/hardware.c @@ -131,10 +131,11 @@ uint16_t __attribute__ ((long_call, section (".data.ramfuncs"))) getTipRawTemp( return filterFP >> 9; } } -uint16_t getInputVoltageX10(uint8_t divisor) { - //ADC maximum is 16384 == 3.3V at input == 28V at VIN +uint16_t getInputVoltageX10(uint16_t divisor) { + //ADC maximum is 32767 == 3.3V at input == 28.05V at VIN //Therefore we can divide down from there - //Ideal term is 117 + //Multiplying ADC max by 4 for additional calibration options, + //ideal term is 467 #define BATTFILTERDEPTH 64 static uint8_t preFillneeded = 1; static uint32_t samples[BATTFILTERDEPTH]; @@ -154,7 +155,7 @@ uint16_t getInputVoltageX10(uint8_t divisor) { sum /= BATTFILTERDEPTH; if (sum < 50) preFillneeded = 1; - return sum / divisor; + return sum * 4 / divisor; } volatile uint32_t pendingPWM = 0; uint8_t getTipPWM() { |