Cleaning up fast/slow PWM change
This commit is contained in:
@@ -227,28 +227,33 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODEL_TS100
|
#ifdef MODEL_TS100
|
||||||
const int32_t tipMass = 65; // X10 watts to raise 1 deg C in 1 second
|
const int32_t HARDWARE_MAX_WATTAGE_X10 = 750;
|
||||||
const uint8_t tipResistance = 75; // x10 ohms, 7.5 typical for ts100 tips
|
const int32_t TIP_THERMAL_MASS = 65; // X10 watts to raise 1 deg C in 1 second
|
||||||
|
const uint8_t tipResistance = 75; // x10 ohms, 7.5 typical for ts100 tips
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODEL_Pinecil
|
#ifdef MODEL_Pinecil
|
||||||
const int32_t tipMass = 45; // X10 watts to raise 1 deg C in 1 second
|
const int32_t HARDWARE_MAX_WATTAGE_X10 = 750;
|
||||||
const uint8_t tipResistance = 75; // x10 ohms, 7.5 typical for ts100 tips
|
const int32_t TIP_THERMAL_MASS = 65; // X10 watts to raise 1 deg C in 1 second
|
||||||
|
const uint8_t tipResistance = 75; // x10 ohms, 7.5 typical for ts100 tips
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODEL_TS80
|
#ifdef MODEL_TS80
|
||||||
const uint32_t tipMass = 40;
|
const int32_t HARDWARE_MAX_WATTAGE_X10 = 180;
|
||||||
const uint8_t tipResistance = 45; // x10 ohms, 4.5 typical for ts80 tips
|
const uint32_t TIP_THERMAL_MASS = 40;
|
||||||
|
const uint8_t tipResistance = 45; // x10 ohms, 4.5 typical for ts80 tips
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODEL_TS80P
|
#ifdef MODEL_TS80P
|
||||||
const uint32_t tipMass = 40;
|
const int32_t HARDWARE_MAX_WATTAGE_X10 = 300;
|
||||||
const uint8_t tipResistance = 45; // x10 ohms, 4.5 typical for ts80 tips
|
const uint32_t TIP_THERMAL_MASS = 40;
|
||||||
|
const uint8_t tipResistance = 45; // x10 ohms, 4.5 typical for ts80 tips
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODEL_MHP30
|
#ifdef MODEL_MHP30
|
||||||
const uint32_t tipMass = 45; // TODO
|
const int32_t HARDWARE_MAX_WATTAGE_X10 = 650;
|
||||||
const uint8_t tipResistance = 60; // x10 ohms, ~6 typical
|
const uint32_t TIP_THERMAL_MASS = 65; // TODO, needs refinement
|
||||||
|
const uint8_t tipResistance = 60; // x10 ohms, ~6 typical
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef POW_QC_20V
|
#ifdef POW_QC_20V
|
||||||
|
|||||||
@@ -13,18 +13,31 @@ static int32_t PWMToX10Watts(uint8_t pwm, uint8_t sample);
|
|||||||
|
|
||||||
expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory = {0};
|
expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory = {0};
|
||||||
|
|
||||||
|
bool shouldBeUsingFastPWMMode(const uint8_t pwmTicks) {
|
||||||
|
// Determine if we should use slow or fast PWM mode
|
||||||
|
// Crossover between modes set around the midpoint of the PWM control point
|
||||||
|
static bool lastPWMWasFast = true;
|
||||||
|
if (pwmTicks > (128 + 8) && lastPWMWasFast) {
|
||||||
|
lastPWMWasFast = false;
|
||||||
|
} else if (pwmTicks < (128 - 8) && !lastPWMWasFast) {
|
||||||
|
lastPWMWasFast = true;
|
||||||
|
}
|
||||||
|
return lastPWMWasFast;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tempToX10Watts(int32_t rawTemp) {
|
int32_t tempToX10Watts(int32_t rawTemp) {
|
||||||
// mass is in milliJ/*C, rawC is raw per degree C
|
// mass is in x10J/*C, rawC is raw per degree C
|
||||||
// returns milliWatts needed to raise/lower a mass by rawTemp
|
// returns x10Watts needed to raise/lower a mass by rawTemp
|
||||||
// degrees in one cycle.
|
// degrees in one cycle.
|
||||||
int32_t milliJoules = tipMass * rawTemp;
|
int32_t x10Watts = TIP_THERMAL_MASS * rawTemp;
|
||||||
return milliJoules;
|
return x10Watts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTipX10Watts(int32_t mw) {
|
void setTipX10Watts(int32_t mw) {
|
||||||
int32_t output = X10WattsToPWM(mw, 1);
|
int32_t outputPWMLevel = X10WattsToPWM(mw, 1);
|
||||||
setTipPWM(output);
|
const bool shouldUseFastPWM = shouldBeUsingFastPWMMode(outputPWMLevel);
|
||||||
uint32_t actualMilliWatts = PWMToX10Watts(output, 0);
|
setTipPWM(outputPWMLevel, shouldUseFastPWM);
|
||||||
|
uint32_t actualMilliWatts = PWMToX10Watts(outputPWMLevel, 0);
|
||||||
|
|
||||||
x10WattHistory.update(actualMilliWatts);
|
x10WattHistory.update(actualMilliWatts);
|
||||||
}
|
}
|
||||||
@@ -45,7 +58,6 @@ static uint32_t availableW10(uint8_t sample) {
|
|||||||
// availableMilliWattsX10 is now an accurate representation
|
// availableMilliWattsX10 is now an accurate representation
|
||||||
return availableWattsX10;
|
return availableWattsX10;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t X10WattsToPWM(int32_t milliWatts, uint8_t sample) {
|
uint8_t X10WattsToPWM(int32_t milliWatts, uint8_t sample) {
|
||||||
// Scale input milliWatts to the pwm range available
|
// Scale input milliWatts to the pwm range available
|
||||||
if (milliWatts < 1) {
|
if (milliWatts < 1) {
|
||||||
@@ -56,15 +68,12 @@ uint8_t X10WattsToPWM(int32_t milliWatts, uint8_t sample) {
|
|||||||
|
|
||||||
// Calculate desired milliwatts as a percentage of availableW10
|
// Calculate desired milliwatts as a percentage of availableW10
|
||||||
uint32_t pwm;
|
uint32_t pwm;
|
||||||
do {
|
pwm = (powerPWM * milliWatts) / availableW10(sample);
|
||||||
pwm = (powerPWM * milliWatts) / availableW10(sample);
|
if (pwm > powerPWM) {
|
||||||
if (pwm > powerPWM) {
|
// constrain to max PWM counter, shouldn't be possible,
|
||||||
// constrain to max PWM counter, shouldn't be possible,
|
// but small cost for safety to avoid wraps
|
||||||
// but small cost for safety to avoid wraps
|
pwm = powerPWM;
|
||||||
pwm = powerPWM;
|
}
|
||||||
}
|
|
||||||
} while (tryBetterPWM(pwm));
|
|
||||||
|
|
||||||
return pwm;
|
return pwm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user