Xmega ADC

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

Hello
Such a question about ADC
MK every few seconds makes metering ADC.
In the first case it works. I set up and run the ADC, and periodically get the new value.

void ADC_init()
{
	PORTA.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
	ADCA.CTRLB = ADC_RESOLUTION_12BIT_gc;
	ADCA.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
	ADCA.PRESCALER =ADC_PRESCALER_DIV32_gc;
	ADCA.REFCTRL = ADC_REFSEL_INT1V_gc | 0x02;
	ADCA.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN0_gc;
	ADCA.CTRLA = ADC_ENABLE_bm;
}

void ADCA_out(void)
{
	ADCA.CTRLA |= ADC_CH0START_bm;
	while((ADCA_CH0_INTFLAGS & 0x01) == 0 );
	DataADC = ADCA.CH0RES;
}

In the second case, in order to decrease power consumption, I decided to turn off the ADC is not in use.

 

void ADC_init()
{
	PORTA.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
	ADCA.CTRLB = ADC_RESOLUTION_12BIT_gc;
	ADCA.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
	ADCA.PRESCALER =ADC_PRESCALER_DIV32_gc;
	ADCA.REFCTRL = ADC_REFSEL_INT1V_gc | 0x02;
	ADCA.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN0_gc;
	ADCA.CTRLA = ADC_ENABLE_bm;
}


void ADCA_out(void)
{
	ADC_init();
	
	ADCA.CTRLA |= ADC_CH0START_bm;
	while((ADCA_CH0_INTFLAGS & 0x01) == 0 );
	DataADC = ADCA.CH0RES;
	
	ADCA.CTRLA = 0x00;
}

As a result, I get all the time the same value that does not change. ADC for the first time makes the correct measurement, and subsequently constantly sends the same value.

In other words, the only difference is. As in the first case, once I launched all the time to take readings, and periodically turn on the second - do measurement and turn off the ADC.
Please tell me what I'm doing wrong

Sorry for my bad english...

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

Hi,

I see don't see any error so far. But I'd try setting only the enable bit in the ADCA_out routine as everything else should not change. This saves you some clock cycles compared to reinitializing everything.

Maybe this also solves your problem, I don't know.

 

Good luck

-Patrick

"Some people die at 25 and aren't buried until 75." -Benjamin Franklin

 

What is life's greatest illusion?"  "Innocence, my brother." -Skyrim

 

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

Problem was solved independently.
The debug through the Atmel Studio noticed that ADC.INTFLAGS not reset before the new transformation.
Now, before each measurement I reset it manually. And everything works as it is necessary

Sorry for my bad english...

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

What does the following statement do?

 

PORTA.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Disable PIN0 input of PORTA.

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

dadams8355 wrote:

What does the following statement do?

 

PORTA.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;

 

Maybe its a good idea if you take a look at this application note:

http://ww1.microchip.com/downloa...

AVR1000: Getting Started Writing C-code for XMEGA