xmega ADC structs

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

Just when I though I had this new struct thing down I get stick on this:

I'm trying to config my ADC channel on my xmega 256A3 but cant seem to figure it out.

I got the other registers figured out, just not the config ones. Ive been looking over iox256a3.h for a bit now and am seeing things I never have before, which I obviously don't understand.

void adc_setup(){
	ADCA.CTRLA |= ADC_ENABLE_bm; //enable ADC A
	ADCA.CTRLB |= ADC_FREERUN_bm | ADC_RESOLUTION1_bm; //turn on free running mode, results in 8 bits right justified
	//ADCA.CH_CTRLA |= ADC_CH_INPUTMODE_SINGLEENDED_gc; //WRONG
	//ADCA.ADC_CH0.CTRL = 1; //WRONG again!
}

Just looking for a little bump in the right direction! Trying to config a channel for ADC_CH_INPUTMODE_SINGLEENDED_gc mode

I appreciate it!

You don't gno-me!

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

Read application note AVR1300.

Stealing Proteus doesn't make you an engineer.

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

Quote:

ADCA.CTRLA |=

This construct always rankles me. If this is indeed "adc_setup" then why isn't there first an assignment? Better yet unless there is a reason, do it all in one assignment, and save a few instruction words.

Reasons:
1) What if you call this more than once in varying stages of the program? The registers may >>not<< have the initial values.

2) If the rebuttal is "it is only called once, at startup, and I know the initial value" then why create a function?

3) Unless a reason, why stretch out init bit-by-bit? Save a few flash words. When you do a real app, you'll be happy with your niggardliness.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

ArnoldB wrote:
Read application note AVR1300.

gerrr, totaly forgot about the xmega app notes. got it now, thanks!.

ADCA.CH0.CTRL |= ADC_CH_INPUTMODE_SINGLEENDED_gc;

I add the OR out of habit. I'm not worried about speed/space right now. But I see where your coming from. There is no need for it in a setup function. Putting it in a function just makes main() easier to read/debug for me.

You don't gno-me!