Asking for the macros for ADC in mega128

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

Hi, guys,

I know this sounds lazy, but still please, who ever share his macros is greatly appreciated!

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

What macros? I can give you some working ADC C code if you like?

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

great!!! please

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
	// select channel 1 and AVcc reference
	ADMUX = (1<<REFS0) + 1;
	// 0xD5, precale = /32 = 250Khz, enable and start
	ADCSRA = (1<< ADEN) | (1<<ADSC) | (1<<ADIF) | (5<<ADPS0); 

	// Gonna wait for first conversion to complete but discard (as it's usually inaccuarate)
	do {
	    // keep waiting
	} while((ADCSRA & (1 << ADSC)));		// Wait for A/D conversion to finish

	// Then start the REAL conversion we're interested in....
	ADCSRA |= (1 << ADSC); // start another conversion (discard the first reading)

	do {
	    // keep waiting
	} while((ADCSRA & (1 << ADSC)));		// Wait for A/D conversion to finish

	adc_val = ADC;

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

thanks