diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-12-22 23:58:51 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-12-23 17:06:10 -0500 |
commit | 872b08601a6b749de2f83b3f270a2c311dd22bbc (patch) | |
tree | d0525ecde954a6e7548e617da143dbf2d54652b9 | |
parent | fe95ea221b2b88e9cb52a6378ff2018ee752094b (diff) | |
download | kutter-872b08601a6b749de2f83b3f270a2c311dd22bbc.tar.gz kutter-872b08601a6b749de2f83b3f270a2c311dd22bbc.tar.xz kutter-872b08601a6b749de2f83b3f270a2c311dd22bbc.zip |
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 <kevin@koconnor.net>
-rw-r--r-- | klippy/mcu.py | 4 | ||||
-rw-r--r-- | 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) { |