I'm using atmega32 µc with the internal 10-bit ADC. I connected my potentiometer to the ADC 1 and I'm using 5 V Voltage Reference.
using the following code, I did the ADC-config
void ADC_init(void)
{
//Turn on the ADC
ADCSRA |= 1<<ADEN; // Turn On ADC (Enable ADC)
//ADMUX |= 1<<ADLAR ; // Config shifting to the left (10-bit), otherwise it is right adjusted
ADMUX |= 1<<REFS0 ; // Config VRef (external Vref in this case)
ADMUX |= 1<<MUX1 ; // ADC-Channel 1
// ADCSRA |= 1<<ADIE; // Enable ADC Interrupt
ADCSRA |= 3<<ADPS0; // Assign ADC-prescaler 128
ADCSRA |= 1<<ADSC; //start the the measure conversion
}
Then in Main function I am calling the following function each 1000ms and send the data to the USART interface
void ADC_measure(void)
{
_delay_ms(50);
// if the ADC right adjusted
theLow = ADCL; // ADC Value Low
_delay_ms(50);
ADC_TenBit = ADCH<<8 | theLow ; // because of lift adjustment of ADC
_delay_ms(50);
sprintf( ADCBuffer, "The ADCValue is : %d \n", ADC_TenBit );
_delay_ms(50);
usart_pstr(ADCBuffer);
_delay_ms(50);
//start the the measure conversion
ADCSRA |= 1<<ADSC;
}
The problem is : when I open the terminal , I see only the ADC Value = 255 or 248
increasing or decreasing the potentiometer value doesn't change the ADC value.
what can I do now?
Best Answer
You have incorrect multiplexer setting. To select channel 1, it should be
Edit: Another thing is incorrect clock prescaler. To get \$f_{clk}/128\$: