ADC and then changing channels

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

Hello All,

I am having a little trouble changing channels when carrying out two analogue to digital conversions one after another. I have successfully tested that the differential ADC on channel AD0 and AD1 works fine, it's currently attached to a bench power supply. I have done the same by testing AD2 and AD3 channels on their own and have been able to get the correct measurement.

However, when i try to measure between AD0 and AD1, then try to measure between AD2 and AD3 straight after, both results show the conversion value across AD2 and AD3. No matter what i do with the voltage across AD0 and AD1 i get the conversion value across AD2 and AD3.

		
//---Setup ADC---
ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (0 << ADPS0); // "110", set prescaler 64 of ADC (8Mhz/64 = 125KHz)
ADMUX |= (0 << REFS1) |(0 << REFS0); //ADC ref volatge set to 00 for AREF
ADMUX |= (1 << ADLAR); //Read to 8bit value not 10bit	 //0right adjust
ADCSRA |= (1 << ADEN);
_delay_ms(5) //ensure setup complete
		
		
//negative terminal ADC1, positive terminal ADC0, Gain 1x
//Select channel 10000
ADMUX |= (1 << MUX4) |(0 << MUX3) | (0 << MUX2) | (0 << MUX1) | (0 << MUX0); 
_delay_ms(5);
ADCSRA |= (1 << ADSC);  // Sample channel 
while(ADCSRA & (1<<ADSC));
itoa(ADCH, adc_imonH , 10); //convert interger to ASCII
		
_delay_ms(10);
	
//negative terminal ADC2, positive terminal ADC3, Gain 1x
//Select channel 11011
ADMUX |= (1 << MUX4) |(1 << MUX3) | (0 << MUX2) | (1 << MUX1) | (1 << MUX0); 
_delay_ms(5);
ADCSRA |= (1 << ADSC);  // Sample channel 
while(ADCSRA & (1<<ADSC));
//itoa(ADCL, adc_imonL, 10); //convert interger to ASCII
itoa(ADCH, adc_paH , 10); //convert interger to ASCII

Any tips would be much appreciated! Thank you.

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

Quote:

ADMUX |= (1 << MUX4) |(0 << MUX3) | (0 << MUX2) | (0 << MUX1) | (0 << MUX0);

Quote:

ADMUX |= (1 << MUX4) |(1 << MUX3) | (0 << MUX2) | (1 << MUX1) | (1 << MUX0);

So, what is the value of ADMUX after you apply successive "OR" operations to it?

Tip: Rebuild ADMUX each time before starting the next conversion.

See my post and links to prior discussions at
https://www.avrfreaks.net/index.p...

Quote:
Suggestion: just rebuild ADMUX from scratch every operation. Avoids any possible RMW situation; takes less code and cycles; avoids this situation.

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

Excellent! Thank you, managed to solve it.