Browse Source

driver: adjust res when oversampling

The SAM0 ADC has an internal register to divide the accumulated results
of oversampling the ADC by the amount of samples collected. This value
has to be set by the driver and was missing.

Signed-off-by: Patrick Günzel <patrick.guenzel@kinexon.com>
pull/83426/head
Patrick Günzel 6 months ago committed by Benjamin Cabé
parent
commit
66dceba537
  1. 8
      drivers/adc/adc_sam0.c

8
drivers/adc/adc_sam0.c

@ -177,7 +177,6 @@ static int adc_sam0_channel_setup(const struct device *dev, @@ -177,7 +177,6 @@ static int adc_sam0_channel_setup(const struct device *dev,
#endif
}
uint32_t inputctrl = 0;
switch (channel_cfg->gain) {
@ -255,7 +254,6 @@ static int adc_sam0_channel_setup(const struct device *dev, @@ -255,7 +254,6 @@ static int adc_sam0_channel_setup(const struct device *dev,
break;
}
return 0;
}
@ -325,6 +323,12 @@ static int start_read(const struct device *dev, @@ -325,6 +323,12 @@ static int start_read(const struct device *dev,
}
adc->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM(sequence->oversampling);
if (sequence->oversampling < 4) {
adc->AVGCTRL.reg |= ADC_AVGCTRL_ADJRES(sequence->oversampling);
} else {
adc->AVGCTRL.reg |= ADC_AVGCTRL_ADJRES(4);
}
/* AVGCTRL is not synchronized */
#ifdef CONFIG_SOC_SERIES_SAMD20

Loading…
Cancel
Save