I have been Mildly Annoyed, and decided to do something about it.
I have been having the same issue as some other folks, but I can’t post more than 2 links here, so you’ll have to check out the original issue at Clock sync and unrealistic extruder temps after restart · Issue #6619 · Klipper3d/klipper · GitHub
In short, when using a SB2209 CAN bus toolhead board, when restarting Klipper with RESTART
, the extruder temperature is reported as a very large number, either negative or positive, before returning to normal over the next ~10 seconds. This doesn’t happen all the time; it’s pretty random.
Here is the cause as well as I can understand it:
- The toolhead keeps sending
thermocouple_result
commands, because it wasn’t restarted. - When a
thermocouple_result
command is sent before clock sync finishes,SecondarySync
’sclock_adj
still has 1 for the mcu frequency, which results in spi_temperature.py’s_handle_temperature_response
getting an undivided value from its call toclock_to_print_time()
. - If the temperature reading has changed on the first
thermocouple_result
command after clock sync has finished,temperature_callback
in heaters.py will multiply the difference in temperature by the difference between the undivided value and the new correct value, resulting in a very large “smoothed” temperature, either negative or positive depending on the direction of the temperature change.
On my machine, I implemented the following fix:
In _handle_spi_response
in spi_temperature.py:
last_read_time = self.mcu.clock_to_print_time(last_read_clock)
+ if last_read_time == last_read_clock:
+ logging.warning("Ignoring untrustworthy clock sync")
+ return
self._callback(last_read_time, temp)
I’m not sure if this is the appropriate fix, as this is the first time I’ve touched the Klipper codebase, but I rather doubt it. It feels like something more fundamental should change, like maybe clock_to_print_time
should throw an error if the clock isn’t synced.