mirror of https://github.com/Desuuuu/klipper.git
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>
This commit is contained in:
parent
fe95ea221b
commit
872b08601a
|
@ -256,7 +256,6 @@ class MCU_pwm:
|
||||||
self._last_clock = clock
|
self._last_clock = clock
|
||||||
|
|
||||||
class MCU_adc:
|
class MCU_adc:
|
||||||
ADC_MAX = 1024 # 10bit adc
|
|
||||||
def __init__(self, mcu, pin):
|
def __init__(self, mcu, pin):
|
||||||
self._mcu = mcu
|
self._mcu = mcu
|
||||||
self._oid = mcu.create_oid()
|
self._oid = mcu.create_oid()
|
||||||
|
@ -283,7 +282,8 @@ class MCU_adc:
|
||||||
minval = 0
|
minval = 0
|
||||||
if maxval is None:
|
if maxval is None:
|
||||||
maxval = 0xffff
|
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._min_sample = int(minval * max_adc)
|
||||||
self._max_sample = min(0xffff, int(math.ceil(maxval * max_adc)))
|
self._max_sample = min(0xffff, int(math.ceil(maxval * max_adc)))
|
||||||
self._inv_max_adc = 1.0 / max_adc
|
self._inv_max_adc = 1.0 / max_adc
|
||||||
|
|
|
@ -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
|
struct gpio_adc
|
||||||
gpio_adc_setup(uint8_t pin)
|
gpio_adc_setup(uint8_t pin)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue