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:
Kevin O'Connor 2016-12-22 23:58:51 -05:00
parent fe95ea221b
commit 872b08601a
2 changed files with 4 additions and 2 deletions

View File

@ -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

View File

@ -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)
{