Forum: µC & Digital Electronics ADC ATMEGA16 microcontroller

Author: Dragu Mircea (mircea2012)
Posted on:

Rate this post
0 useful
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;

Author: reverse (Guest)
Posted on:

Rate this post
0 useful
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]
  • [avrasm]AVR assembler code[/avrasm]
  • [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.