Skip to content

Commit df43fb4

Browse files
committed
samd/ADC: Apply the channel's VRef setting at each read.
1 parent e8712db commit df43fb4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ports/samd/machine_adc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ STATIC mp_obj_t adc_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_
207207

208208
// flag the device/channel as being in use.
209209
ch_busy_flags |= (1 << (self->adc_config.device * 16 + self->adc_config.channel));
210+
device_mgmt[self->adc_config.device].init = false;
210211
self->dma_channel = -1;
211212
self->tc_index = -1;
212213

@@ -225,6 +226,8 @@ STATIC mp_obj_t machine_adc_read_u16(mp_obj_t self_in) {
225226
mp_raise_OSError(MP_EBUSY);
226227
}
227228

229+
// Set the reference voltage. Default: external AREFA.
230+
adc->REFCTRL.reg = adc_vref_table[self->vref];
228231
// Set Input channel and resolution
229232
// Select the pin as positive input and gnd as negative input reference, non-diff mode by default
230233
adc->INPUTCTRL.reg = ADC_INPUTCTRL_MUXNEG_GND | self->adc_config.channel;
@@ -262,6 +265,8 @@ STATIC mp_obj_t machine_adc_read_timed(mp_obj_t self_in, mp_obj_t values, mp_obj
262265
if (self->tc_index == -1) {
263266
self->tc_index = allocate_tc_instance();
264267
}
268+
// Set the reference voltage. Default: external AREFA.
269+
adc->REFCTRL.reg = adc_vref_table[self->vref];
265270
// Set Input channel and resolution
266271
// Select the pin as positive input and gnd as negative input reference, non-diff mode by default
267272
adc->INPUTCTRL.reg = ADC_INPUTCTRL_MUXNEG_GND | self->adc_config.channel;
@@ -432,7 +437,7 @@ static void adc_init(machine_adc_obj_t *self) {
432437
// Divide a 48MHz clock by 32 to obtain 1.5 MHz clock to adc
433438
adc->CTRLB.reg = ADC_CTRLB_PRESCALER_DIV32;
434439
// Select external AREFA as reference voltage.
435-
adc->REFCTRL.reg = self->vref;
440+
adc->REFCTRL.reg = adc_vref_table[self->vref];
436441
// Average: Accumulate samples and scale them down accordingly
437442
adc->AVGCTRL.reg = self->avg | ADC_AVGCTRL_ADJRES(self->avg);
438443
// Enable ADC and wait to be ready

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy