Skip to content

Commit 66dceba

Browse files
guenzel-kinexonkartben
authored andcommitted
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 <[email protected]>
1 parent ba5971e commit 66dceba

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/adc/adc_sam0.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ static int adc_sam0_channel_setup(const struct device *dev,
177177
#endif
178178
}
179179

180-
181180
uint32_t inputctrl = 0;
182181

183182
switch (channel_cfg->gain) {
@@ -255,7 +254,6 @@ static int adc_sam0_channel_setup(const struct device *dev,
255254
break;
256255
}
257256

258-
259257
return 0;
260258
}
261259

@@ -325,6 +323,12 @@ static int start_read(const struct device *dev,
325323
}
326324

327325
adc->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM(sequence->oversampling);
326+
if (sequence->oversampling < 4) {
327+
adc->AVGCTRL.reg |= ADC_AVGCTRL_ADJRES(sequence->oversampling);
328+
} else {
329+
adc->AVGCTRL.reg |= ADC_AVGCTRL_ADJRES(4);
330+
}
331+
328332
/* AVGCTRL is not synchronized */
329333

330334
#ifdef CONFIG_SOC_SERIES_SAMD20

0 commit comments

Comments
 (0)