Can't get continuous ADC conversions, ATMEGA88

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

I'm following penquissciguy's TUT on the AVR ADC. I've been reading the ATMEGA88 datasheet, and managed to adapt his example. However, I can't get the ADC into Free Running mode.

Looking at page 258 in the datasheet, Free Running mode is enabled by writing 0 to ADTS2, ADTS1 and ADTS0. Doesn't that mean I won't have to do anything in my C code, that they're already 0 by default? (There's an example of this in the TUT, where all "5 MUX bits" are set to 0 by default).

However, I only get one, initial ADC conversion. My workaround is to restart the conversions within the loop (see commented out line), but that's obviously not a real solution.

Any tips? Please have a look at my code:

#include 
#include 

typedef unsigned char u08;

int main (void)
{

	u08 red = 0x01, green = 0x02;

	DDRB = 0xff;

   ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // Set ADC prescalar to 128 - 125KHz sample rate @ 16MHz

   ADMUX |= (1 << REFS0); // Set ADC reference to AVCC
   ADMUX |= (1 << ADLAR); // Left adjust ADC result to allow easy 8 bit reading
   // No MUX values needed to be changed to use ADC0

   ADCSRB |= (0 << ADTS2) | (0 << ADTS1) | (0 << ADTS0); // Set ADC to Free-Running Mode ???
   ADCSRA |= (1 << ADEN);  // Enable ADC
   ADCSRA |= (1 << ADSC);  // Start A2D Conversions

   for(;;)  // Loop Forever
   {

		//ADCSRA |= (1 << ADSC);  // workaround -- this way I get continuous ADC...

      if(ADCH < 128)
      {
		PORTB = ~red;
      }
      else
      {
		PORTB = ~green;
      }

   }

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

Quote:

Free Running mode is enabled by writing 0 to ADTS2, ADTS1 and ADTS0.

Not exactly. Doesn't your datasheet have this right where those bits are described?
Quote:
• Bit 2:0 – ADTS2:0: ADC Auto Trigger Source
If ADATE in ADCSRA is written to one, the value of these bits selects which source will trigger an ADC conversion. If ADATE is cleared, the ADTS2:0 settings will have no effect.

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

Shoot, it's not easy getting all the little bits of information right from those PDF's :)

Thanks for the tip! Setting 1 in ADCSRA.ADATE got it working.