ADC on Xmega

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

Just trying to get something out of the ADC.
If I leave all registers in default settings, I should get internal temp readings when I enable the ADC and start conversion by setting bit 7 of the channel control register or setting appropriate bits in CTRLA register?

Can anyone confirm that?

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

Yes, but keep in mind the xmega ADC is very crippled.

http://www.xbitinc.com/knowledgebase/questions.php?questionid=3

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

Yes, I read about all the problems.

At the moment, I can't seem to get any readings from it, so there's something obvious I'm not doing.

Can the ADC port function be split between Normal IO and ADC? I want to use ADCA6 and 7 as IO pins.

I'm assuming that if Port A is set to input on PA0 to 5 and output on PA6 and 7 and the ADC is then enabled, I can still use the top two bits as IO.

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

The code below just hangs waiting for the ADC to complete. I must be missing some other register that needs setting to get the ADc to run:

PORTA.DIR = 0;
ADCA.CTRLB = ADC_RESOLUTION_12BIT_gc;
ADCA.REFCTRL = ADC_REFSEL_INT1V_gc | 0x02;
ADCA.PRESCALER = ADC_PRESCALER_DIV8_gc;
ADCA.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
ADCA.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN0_gc;
ADCA.CTRLA |= ADC_ENABLE_bm; // enable adc

mdelay(25);

ADCA.CH0.CTRL |= ADC_CH_START_bm;
while(!ADCA.CH0.INTFLAGS);

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

Found it!
Something somewhere has turned off the ADC clock in the power reduction register...
Still trying to see where that could have been set...?
Surely it defaults on, unless there are some fuses that set it?

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

Quote:

Surely it defaults on, unless there are some fuses that set it?

I don't know Xmega but that's not my experience in, for example, AT91SAM9. In that you have to enable the clocks for most internal function blocks before you can use them. They default off to save power.

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

Turns out the demo code example LEDCHASER, which I have using as a base to start from, has a function called sysclk_init(); which turns off all the peripheral clocks:

void sysclk_init(void)
{
uint8_t *reg = (uint8_t *)&PR.PRGEN;
uint8_t i;
#ifdef CONFIG_OSC_RC32_CAL
uint16_t cal;
#endif

/* Turn off all peripheral clocks that can be turned off. */
for (i = 0; i <= SYSCLK_PORT_F; i++) {
*(reg++) = 0xff;
}