diff options
author | David Crocker <dcrocker@eschertech.com> | 2016-11-05 23:00:39 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2016-11-05 23:01:02 +0300 |
commit | 619e5c489f7a29dc78fe900e16ee0ea5a13df4c5 (patch) | |
tree | 36d599f39034a764e17e36fc8138c8c91aec8de6 /src/Fan.cpp | |
parent | 6f71c760185f338843870b1642a540c3dce5b2c8 (diff) |
Version 1.16rc2
Fixed several bugs in file time stamping
Fixed M280 and M42 commands using unused heaster channels on Duet 0.6
and 0.8.5
Reduced the amount of I2C traffic, by using DueX5 interrupt line to tell
if new data is available and by only sending fan PWM values when they
change
Display TMC2660 driver status and DueX2/X5 stall status in M122 response
Removed E parameter from M574 command (use M558 I parameter instead)
Fixed response to M307 with H parameter only
Diffstat (limited to 'src/Fan.cpp')
-rw-r--r-- | src/Fan.cpp | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/src/Fan.cpp b/src/Fan.cpp index b4358238..89e2f972 100644 --- a/src/Fan.cpp +++ b/src/Fan.cpp @@ -12,13 +12,13 @@ void Fan::Init(Pin p_pin, bool hwInverted) val = 0.0; minVal = 0.1; // 10% minimum fan speed blipTime = 100; // 100ms fan blip - blipStartTime = 0; freq = DefaultFanPwmFreq; pin = p_pin; hardwareInverted = hwInverted; - inverted = false; + inverted = blipping = false; heatersMonitored = 0; triggerTemperature = HOT_END_FAN_TEMPERATURE; + lastPwm = -1.0; Refresh(); } @@ -28,10 +28,11 @@ void Fan::SetValue(float speed) { speed /= 255.0; } - const float newVal = (speed > 0.0) ? constrain<float>(speed, minVal, 1.0) : 0.0; - if (val == 0.0 && newVal < 1.0 && blipTime != 0) + const float newVal = constrain<float>(speed, 0.0, 1.0); + if (val == 0.0 && newVal > 0.0 && newVal < 1.0 && blipTime != 0) { // Starting the fan from standstill, so blip the fan + blipping = true; blipStartTime = millis(); } val = newVal; @@ -68,7 +69,17 @@ void Fan::SetHardwarePwm(float pwmVal) { invert = !invert; } - Platform::WriteAnalog(pin, (invert) ? (1.0 - pwmVal) : pwmVal, freq); + if (invert) + { + pwmVal = 1.0 - pwmVal; + } + + // Only set the PWM if it has changed, to avoid a lot of I2C traffic when we have a DueX5 connected + if (pwmVal != lastPwm) + { + lastPwm = pwmVal; + Platform::WriteAnalog(pin, pwmVal, freq); + } } } @@ -91,23 +102,31 @@ void Fan::Refresh() : (reprap.GetPlatform()->AnyHeaterHot(heatersMonitored, triggerTemperature)) ? max<float>(0.5, val) // make sure that thermostatic fans always run at 50% speed or more : 0.0; - if (reqVal > 0.0 && millis() - blipStartTime < blipTime) - { - SetHardwarePwm(1.0); - } - else if (reqVal > 0.0 && reqVal < minVal) + if (reqVal > 0.0) { - SetHardwarePwm(minVal); - } - else - { - SetHardwarePwm(reqVal); + if (reqVal < minVal) + { + reqVal = minVal; + } + + if (blipping) + { + if (millis() - blipStartTime < blipTime) + { + reqVal = 1.0; + } + else + { + blipping = false; + } + } } + SetHardwarePwm(reqVal); } void Fan::Check() { - if (heatersMonitored != 0 || blipTime != 0) + if (heatersMonitored != 0 || blipping) { Refresh(); } |