From 872b08601a6b749de2f83b3f270a2c311dd22bbc Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 22 Dec 2016 23:58:51 -0500 Subject: [PATCH] mcu: Obtain the maximum adc value from the firmware Don't assume the hardware ADC has 10bit resultion - instead have the firmware define a constant and read that constant in the host. Signed-off-by: Kevin O'Connor --- klippy/mcu.py | 4 ++-- src/avr/gpio.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index b49c29cc..e50a6cb3 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -256,7 +256,6 @@ class MCU_pwm: self._last_clock = clock class MCU_adc: - ADC_MAX = 1024 # 10bit adc def __init__(self, mcu, pin): self._mcu = mcu self._oid = mcu.create_oid() @@ -283,7 +282,8 @@ class MCU_adc: minval = 0 if maxval is None: maxval = 0xffff - max_adc = sample_count * self.ADC_MAX + mcu_adc_max = float(self._mcu.serial.msgparser.config["ADC_MAX"]) + max_adc = sample_count * mcu_adc_max self._min_sample = int(minval * max_adc) self._max_sample = min(0xffff, int(math.ceil(maxval * max_adc))) self._inv_max_adc = 1.0 / max_adc diff --git a/src/avr/gpio.c b/src/avr/gpio.c index 3df6e9e8..69114f05 100644 --- a/src/avr/gpio.c +++ b/src/avr/gpio.c @@ -258,6 +258,8 @@ gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val) } +DECL_CONSTANT(ADC_MAX, 1024); + struct gpio_adc gpio_adc_setup(uint8_t pin) {