Not shure of what I do with ADC XMega128

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

Hi,

My code work but I don't know if it's the good way to do. I what to scan ADCA from PA0 to PA3 and I want to work with interrupt, I had try with Free Run Mode but without success. Here is my small part of code, Any help will be welcome.

void ADCInit(void)
{
ADCA.CTRLB = ADC_RESOLUTION_12BIT_gc; //12 bit, unsigned
ADCA.REFCTRL = ADC_REFSEL_INT1V_gc; // Ref 1V
ADCA.PRESCALER = ADC_PRESCALER_DIV256_gc; // Prescaler / 256
ADCA.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc | ADC_CH_GAIN_1X_gc; // single end, gain 1
ADCA.CH1.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc | ADC_CH_GAIN_1X_gc; // single end, gain 1
ADCA.CH2.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc | ADC_CH_GAIN_1X_gc; // single end, gain 1
ADCA.CH3.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc | ADC_CH_GAIN_1X_gc; // single end, gain 1

ADCA.CH3.INTCTRL |= ADC_CH_INTLVL0_bm ; // Set interrupt on channel 3
ADCA.CTRLA |= ADC_ENABLE_bm; // Enable ADC

ADCA.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN0_gc ; // Pin A0 to AD0
ADCA.CH1.MUXCTRL = ADC_CH_MUXPOS_PIN1_gc ; // Pin A1 to AD1
ADCA.CH2.MUXCTRL = ADC_CH_MUXPOS_PIN2_gc ; // Pin A2 to AD2
ADCA.CH3.MUXCTRL = ADC_CH_MUXPOS_PIN3_gc ; // Pin A3 to AD3
ADCA.CTRLA |= (ADC_CH0START_bm | ADC_CH1START_bm | ADC_CH2START_bm | ADC_CH3START_bm);
}

ISR(ADCA_CH3_vect)
{
AD0 = ADCA.CH0RES;
AD1 = ADCA.CH1RES;
AD2 = ADCA.CH2RES;
AD3 = ADCA.CH3RES;
ADCA.CTRLA |= (ADC_CH0START_bm | ADC_CH1START_bm | ADC_CH2START_bm | ADC_CH3START_bm);

}

Yours truly,
Sylvain Bissonnette
www.microsyl.com

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

Quote:

AD0 = ADCA.CH0RES;
AD1 = ADCA.CH1RES;
AD2 = ADCA.CH2RES;
AD3 = ADCA.CH3RES;

[side note]
Presumably AD0, AD1, AD2, and AD3 are the variables taking the final result? Just a question of programming style but I'd make them mixed/lower case as upper-case usually implies macros (like just about everything else in the code above). Changing it will help the reader easily identify what the final "output" of all this is.
[/side note]

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

AVR1505 shows how to do it free-running or sweeping . I might do this:

0) Use an array to store conversions .
1) Event trigger on a timer .
2) Set for sweep mode of all 4 channels .
3) Use DMA, ADC to buffer array .

It all depends on your final app, as far as what's best way to do it .

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

Thanks I will check a look to AVR1505

Yours truly,
Sylvain Bissonnette
www.microsyl.com