ADC ATMEGA16 microcontroller

OP #3190039
Hy.
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;
   ADC_Setup();
   while(1)
   {
      rezultat = ADC_Read_Channel(0);
      if(rezultat < 70)
      PORTB = 0xF0;
      else
      PORTB = 0x0F;
   }
}
Guest
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.

Reply

A question of your own? This thread is over 13 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.