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; } }
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.