Forum: µC & Digital Electronics ADC ATMEGA16 microcontroller

von Dragu M. (mircea2012)

Rate this post
not useful
I use for the first time ADC of ATMEGA16 16PU 1010K microcontroller.
I dont understand why the least four signifiant leds doesn't turn on.
Always the most four signifiant leds are on.

void ADC_Setup()
   ADMUX = (1<<REFS0);
   ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
unsigned int ADC_Read_Channel(unsigned int ch)
   ch &= 0b00000111;
   ADMUX = (ADMUX & 0xE0) | ch;
   ADCSRA |= (1<<ADSC);
   while(ADCSRA & (1<<ADSC));

   return (ADCL);
int main()
   unsigned int rezultat;
   DDRA = 0;
   DDRB = 0xFF;
      rezultat = ADC_Read_Channel(0);
      if(rezultat < 70)
      PORTB = 0xF0;
      PORTB = 0x0F;

von reverse (Guest)

Rate this post
not useful
post a picture of your circuit, try to measure the voltage on the pin of 
the mux channel 0 with an multimeter. Calculate what value you get with 
your  ADC settings.


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.