I'm having huge problems getting the ADC to work with any analog inputs or an external reference. It works fine when measuring internal inputs with the internal reference, but as soon as I enable any external signal (sampling an external input OR using an external reference) I get ridiculous values.
1. Internal signals with external reference:
I've got a 2.5V external reference (3.3V analog supply) but looking at the values I get when measuring the internal supplies, it's giving the same values I'd get if the external reference was 2V, not 2.5V. I have checked the external reference multiple times and it's certainly the correct value with almost no noise.
2. External signals with external reference
If I use 1x gain, both inputs give full-scale readings, despite one being 1.82V and the other begin 0V, with a 2.5V reference. If I set the gain to DIV2, both inputs give me the same value - about 1100 counts (out of 4096) but with lots of noise (+/- 100 counts)
This is my setup code (for reading the external signals with external reference; what I actually need to do):
Code: Select all
PORT->Group.WRCONFIG.reg = PORT_WRCONFIG_WRPINCFG | PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUX(1) | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PINMASK(0x0038); ADC->CTRLA.reg = ADC_CTRLA_SWRST; while (ADC->STATUS.bit.SYNCBUSY) ; ADC->REFCTRL.reg = ADC_REFCTRL_REFSEL_AREFA; ADC->SAMPCTRL.reg = ADC_SAMPCTRL_SAMPLEN(63); ADC->CTRLB.reg = ADC_CTRLB_PRESCALER_DIV32; ADC->INPUTCTRL.reg = ADC_INPUTCTRL_GAIN_1X | ADC_INPUTCTRL_INPUTOFFSET(0) | ADC_INPUTCTRL_INPUTSCAN(1) | ADC_INPUTCTRL_MUXNEG_IOGND | ADC_INPUTCTRL_MUXPOS_PIN4; ADC->INTENSET.reg = ADC_INTENSET_RESRDY; ADC->EVCTRL.reg = ADC_EVCTRL_STARTEI; ADC->CTRLA.reg = ADC_CTRLA_ENABLE; while (ADC->STATUS.bit.SYNCBUSY) ;
Code: Select all
while (ADC->STATUS.bit.SYNCBUSY) ; if (ADC->INPUTCTRL.bit.INPUTOFFSET) debugPrintf("%u, ", ADC->RESULT.reg); else debugPrintf("%u\r\n", ADC->RESULT.reg); ADC->INTFLAG.reg = ADC->INTFLAG.reg;
I have stepped through my code with the debugger several times and confirmed that the registers do have the correct values that I'm writing to them. Changing the ADC clock speed or sampling time doesn't make any difference. Neither does averaging (except for smoothing out some of the randomness). Neither does removing the input scan and only converting one input.
Does anyone have ideas of what I could be doing wrong?
[UPDATE] It was improperly soldered pins for all three analog inputs