ADC setup Xmega128a1 [solved]

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

Hi

I'm trying to find out why I can't read an ADC pin connected to PA1. I have a changing DC value connected to that pin PA1 that I adjust with a potmeter. Below my general init-settings for the ADC and start conversion-settings.
As a result I have only b7 high of PORTJ, knowing
I'm bringing out the 8bit ADC-value, right adjusted out to portJ. :

ADCA.CTRLA |= 0x01; // enable adc
ADCA.CTRLB = 0x04; // set 8 bit conversion
ADCA.CH0.CTRL = 0x01; // single ended
ADCA.CH0.MUXCTRL = 0x08; // PORTA:1
ADCA.REFCTRL = 0x00; // reference is PORTA:0 (internal reference 1V)
ADCA.PRESCALER = 0x00; // peripheral clk/4

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

while(1)
{
// read adc to determine waveform freq
ADCA.CTRLA |= 0x4; // start conversion ch0
while(!ADCA.CH0.INTFLAGS); // wait for conversion complete flag
ADCA.CH0.INTFLAGS = 0; // clear int flags
Reading = ADCA.CH0RESL; // read 8 bit value from POT
PORTJ.OUT=(unsigned char)Reading;
delay_ms(50);
};

Second question:
The manual of the ATMEGA128a1 is not clearly explaining the ADC.ACTRLA register, espc. how the ADC start single conversion works. The only explanation is (p302):" Bits 5:2 "“ CH[3:0]START: ADC Channel Start single conversion
Setting any of these bits will start a conversion on the corresponding ADC channel. Setting several
bits at the same time will start a conversion sweep on the selected ADC channels, starting
with the channel with lowest number. These bits are cleared by hardware when the conversion
has started."
Anyone can explain me a little bit more?

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

Hi

first problem is solved. I made a big mistake: PORTJ was not fully set as OUTPUT in the direction register. Sometimes the most easy steps are forgotten. Shame on me!

Still want to figure out my second question!!

thks for help