Xmega ADC multiplexer problem?

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

Hi freaks

I find it difficult to believe that I haven't get my Xmega ADC working for 2 days already. My task is simple, I just need to sample ADC from ADCA1 of xmegaA3BU.

I had the code

		PORTA.DIRCLR = PIN1_bm;
		PORTA.PIN1CTRL = PORT_OPC_TOTEM_gc | PORT_ISC_INPUT_DISABLE_gc;
	
		PR.PRPA &= ~PR_ADC_bm;

		ADCA.CTRLB = ADC_CONMODE_bm | ADC_RESOLUTION_12BIT_gc;
		ADCA.EVCTRL = 0;
		ADCA.REFCTRL = ADC_BANDGAP_bm | ADC_REFSEL_INT1V_gc;
		ADCA.PRESCALER = ADC_PRESCALER_DIV32_gc;
		ADCA.CH1.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
		ADCA.CH1.MUXCTRL = ADC_CH_MUXPOS_PIN1_gc;
		ADCA.CH1.INTCTRL = 0;

		ADCA.CTRLA = ADC_ENABLE_bm;
		timer_delay_us(400);
		
		ADCA.CH1.INTFLAGS = ADC_CH_CHIF_bm;
		ADCA.CH1.CTRL = ADC_CH_START_bm;

		while (!(ADCA.CH1.INTFLAGS & ADC_CH_CHIF_bm));
		dbg_printf("ADC %u\n", ADCA.CH1.RES);

I left the pin floating, or tied to ground,  and the value remains the same. It is around 1360 and 2360 in unsigned mode. I tried internal inputs, the result is good, but not the external input. Neither differential mode nor single ended mode makes differences.

M suspecting that is it possible the multiplexer did not route the PA1 pin to the pipeline for some reason?

 

By the way, I also tried to put PA1 output and HIGH when ADCA is enabled and connecting to PA1 at channel 1. Is it normal?

"The life of the individual only has meaning insofar as it aids in making the life of every living thing nobler and more beautiful. Life is sacred, that is to say, it is the supreme value to which all other values are subordinate."
-- Albert Einstein

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

I'm never a great fan of the bloat-fest that is ASF but in the absence of anything better have you tried some ASF code for reading ADC? If it works dig down into it (the 50+ layers!!) and see what they are actually doing then replicate something simpler in your own code.

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

Thanks for replying. That was the first thing i tried, and it gave the same result... Maybe I can try it once more.

"The life of the individual only has meaning insofar as it aids in making the life of every living thing nobler and more beautiful. Life is sacred, that is to say, it is the supreme value to which all other values are subordinate."
-- Albert Einstein

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

Sounds like it may be clocking to fast, check your clock source and prescaler values to see if they are reasonable.

 

Jim

 

 

 

 

 

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

If two attempts at doing the same thing fail does it not maybe suggest the fault may lie elsewhere (like in the actual electronics) or something?

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

Might help to see more of your code too. What you posted looks correct at first glance.

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

jjexyy wrote:

Hi freaks

I find it difficult to believe that I haven't get my Xmega ADC working for 2 days already. My task is simple, I just need to sample ADC from ADCA1 of xmegaA3BU.

I had the code

		PORTA.DIRCLR = PIN1_bm;
		PORTA.PIN1CTRL = PORT_OPC_TOTEM_gc | PORT_ISC_INPUT_DISABLE_gc;

		PR.PRPA &= ~PR_ADC_bm;

		ADCA.CTRLB = ADC_CONMODE_bm | ADC_RESOLUTION_12BIT_gc;
		ADCA.EVCTRL = 0;
		ADCA.REFCTRL = ADC_BANDGAP_bm | ADC_REFSEL_INT1V_gc;
		ADCA.PRESCALER = ADC_PRESCALER_DIV32_gc;
		ADCA.CH1.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
		ADCA.CH1.MUXCTRL = ADC_CH_MUXPOS_PIN1_gc;
		ADCA.CH1.INTCTRL = 0;

		ADCA.CTRLA = ADC_ENABLE_bm;
		timer_delay_us(400);

		ADCA.CH1.INTFLAGS = ADC_CH_CHIF_bm;
		ADCA.CH1.CTRL = ADC_CH_START_bm;

		while (!(ADCA.CH1.INTFLAGS & ADC_CH_CHIF_bm));
		dbg_printf("ADC %u\n", ADCA.CH1.RES);

I left the pin floating, or tied to ground,  and the value remains the same. It is around 1360 and 2360 in unsigned mode. I tried internal inputs, the result is good, but not the external input. Neither differential mode nor single ended mode makes differences.

M suspecting that is it possible the multiplexer did not route the PA1 pin to the pipeline for some reason?

 

By the way, I also tried to put PA1 output and HIGH when ADCA is enabled and connecting to PA1 at channel 1. Is it normal?

 

Your problem is due to:

ADCA.CH1.CTRL = ADC_CH_START_bm;

Because this line sets internal mode. Try:

ADCA.CH1.CTRL |= ADC_CH_START_bm;

 

Ozhan KD
Knowledge is POWER

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

O!M!G!, I can not believe myself. for not seeing this!!! Thanks for thousand times! 

"The life of the individual only has meaning insofar as it aids in making the life of every living thing nobler and more beautiful. Life is sacred, that is to say, it is the supreme value to which all other values are subordinate."
-- Albert Einstein