mirror of https://github.com/Desuuuu/klipper.git
mcu: Limit ADC min/max range to a 16bit integer
Make sure the ADC range sent to the MCU can be encoded into a 16bit integer. Otherwise, if the provided min_temp/max_temp was outside the range of possible values it could result in a spurious mcu shutdown. In particular, the AD595 could not properly encode a min_temp of zero. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
7083a33ecd
commit
36de6118c1
|
@ -396,8 +396,9 @@ class MCU_adc:
|
|||
max_adc = self._sample_count * mcu_adc_max
|
||||
self._inv_max_adc = 1.0 / max_adc
|
||||
self._report_clock = int(self._report_time * self._mcu_freq)
|
||||
min_sample = int(self._min_sample * max_adc)
|
||||
max_sample = min(0xffff, int(math.ceil(self._max_sample * max_adc)))
|
||||
min_sample = max(0, min(0xffff, int(self._min_sample * max_adc)))
|
||||
max_sample = max(0, min(0xffff, int(
|
||||
math.ceil(self._max_sample * max_adc))))
|
||||
self._mcu.add_config_cmd(
|
||||
"query_analog_in oid=%d clock=%d sample_ticks=%d sample_count=%d"
|
||||
" rest_ticks=%d min_value=%d max_value=%d" % (
|
||||
|
|
Loading…
Reference in New Issue