heater: Force set_pwm of zero when target_temp is zero
Fix a corner case where a residual in the PID could cause a non-zero pwm request even when the target_temp is zero. (Which could lead to a firmware "Missed scheduling of next pwm event" shutdown.) Simplify the logic for suppressing duplicate pwm updates and make sure a zero target_temp always results in a zero pwm update on the following set_pwm calculation. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
f66b1ac450
commit
e60779bfe1
|
@ -72,14 +72,11 @@ class PrinterHeater:
|
|||
self.next_pwm_time = 0.
|
||||
self.last_pwm_value = 0
|
||||
def set_pwm(self, read_time, value):
|
||||
if value:
|
||||
if self.target_temp <= 0.:
|
||||
return
|
||||
if (read_time < self.next_pwm_time
|
||||
and abs(value - self.last_pwm_value) < 0.05):
|
||||
return
|
||||
elif not self.last_pwm_value and (
|
||||
self.target_temp <= 0. or read_time < self.next_pwm_time):
|
||||
if self.target_temp <= 0.:
|
||||
value = 0.
|
||||
if ((read_time < self.next_pwm_time or not self.last_pwm_value)
|
||||
and abs(value - self.last_pwm_value) < 0.05):
|
||||
# No significant change in value - can suppress update
|
||||
return
|
||||
pwm_time = read_time + REPORT_TIME + SAMPLE_TIME*SAMPLE_COUNT
|
||||
self.next_pwm_time = pwm_time + 0.75 * MAX_HEAT_TIME
|
||||
|
|
Loading…
Reference in New Issue