Hello,
I am trying to read 2 analog inputs off of my Adafruit M0 Express by modifying some registers during my setup. The input pins are AIN1 and AIN2(PB08 and PB09 on SAMD21 datasheet)that im trying to read from. But im having trouble, im still kinda new to directly writing to the registers properly. From what Ive read, you can enable pin scan mode to read from multiple pins. But I have become a bit confused.So far my setup code is:
uint32_t fastADCsetup() {
//Set input control register
ADCsync();
ADC->INPUTCTRL.reg |= ADC_INPUTCTRL_GAIN_1X_Val
| (inputs << ADC_INPUTCTRL_INPUTSCAN_Pos) | ADC_INPUTCTRL_MUXNEG_GND;
// ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain select as 1X
ADCsync();
ADC->INPUTCTRL.bit.INPUTSCAN =0x01;
ADCsync();
ADC->INPUTCTRL.bit.INPUTOFFSET = 0x01;
ADCsync();
ADC->INPUTCTRL.bit.MUXPOS = ADC_INPUTCTRL_MUXPOS_PIN1;
ADCsync();
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC0_Val;// 2.2297 V Supply VDDANA //ADC_REFCTRL_REFSEL_INT1V_Val; // ref is 1 V band gap internal
// Set sample length and averaging
ADCsync();
ADC->AVGCTRL.reg = 0x00 ; //Single conversion no averaging
ADCsync();
ADC->SAMPCTRL.reg = 0x00; //Minimal sample length is 1/2 CLK_ADC cycle
// Set up clock to 8 Mhz oscillator
syncGCLK();
GCLK->CLKCTRL.reg = 0x431E; //enable GCLK for ADC, CLKGEN3 = 8 MHz oscillator
syncGCLK();
//Control B register
ADCsync();
ADC->CTRLB.reg = 0x000;//was 0x000 // Prescale 4, 12 bit resolution, single conversion
// Enable ADC in control A register
ADCsync();
ADC->CTRLA.bit.ENABLE = 0x01;
It reads from 1 of the inputs properly but the other input is just the REF Voltage, when I feed a signal into the 2 analog inputs im trying to read. Any help is nice