ATSAMD21 ADC data

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have read the datasheet, checked the errata, scrounged forums and as a last ditch effort, I am hoping someone has experienced my problem before.

I have a simple ADC running in freerun mode on a single ADC channel. I am trying to get 15 bit resolution (64x accumulation with one addition right shift). I get some weird data coming in the RESULT register. It is always less than half what i expect it to be, sometimes 1/4 or 1/8. I have tried many configurations of various references and configurations and still have not come up with expected results. I'm running on the explained pro board with a analog signal ranging from 0-2.5 volts (current sensor) sitting at 1.12 volts input I get an RESULT register count of  0x1100 ish, where i should be around 0x2A00 ish glck is 47.9 mhz peripheral prescaler at 4

//Configuration
    while(REG_ADC_STATUS);
	REG_ADC_CALIB = ADC_CALIB_BIAS_CAL((*(uint32_t *)ADC_FUSES_BIASCAL_ADDR >> ADC_FUSES_BIASCAL_Pos))| ADC_CALIB_LINEARITY_CAL((*(uint64_t *)ADC_FUSES_LINEARITY_0_ADDR >> ADC_FUSES_LINEARITY_0_Pos));
	while(REG_ADC_STATUS);
	REG_ADC_REFCTRL |= ADC_REFCTRL_REFSEL_AREFA;  //3.3 volt reference
	while(REG_ADC_STATUS);
	REG_ADC_AVGCTRL |= ADC_AVGCTRL_ADJRES(0x1) | ADC_AVGCTRL_SAMPLENUM_64;//680 uA per count resolution max +-22.29 amps
	while(REG_ADC_STATUS);
	REG_ADC_CTRLB |= ADC_CTRLB_RESSEL_16BIT | ADC_CTRLB_FREERUN;
	while(REG_ADC_STATUS);
	REG_ADC_INTENSET |= ADC_INTENSET_RESRDY;
	while(REG_ADC_STATUS);
	REG_ADC_INPUTCTRL |= ADC_INPUTCTRL_MUXPOS_PIN0 | ADC_INPUTCTRL_MUXNEG_GND;
	while(REG_ADC_STATUS);
	REG_ADC_CTRLA = ADC_CTRLA_ENABLE;
	while(REG_ADC_STATUS);
	REG_ADC_SWTRIG = ADC_SWTRIG_START;

	NVIC_EnableIRQ(ADC_IRQn);

//ISR
void ADC_Handler(void)
{
        while(REG_ADC_STATUS);
		REG_ADC_INTFLAG = 0xf;
		ADC_index++;
		ADC_index = ADC_index % sizeof_ADC_buffer;
		while(REG_ADC_STATUS);
		ADC_data[ADC_index] = REG_ADC_RESULT;
		Current.feedback = ADC_data[ADC_index];
		Current.new_feedback = true;
}

 

This topic has a solution.

Engineering is the truest form of art

Last Edited: Fri. Jan 24, 2020 - 11:11 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

VDDANA-0.6V is the max reference voltage. And 2.1 MHz is the max ADC clock speed.

This information is in the "Electrical Characteristics" section.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lars, 

Thank you! I had been suspecting the clock was too fast. I hadn't thought to look in that section of the datasheet. Thank you for pointing that out and the analog reference would have bit me as well.  

Engineering is the truest form of art