I am using a simple code to read from ADC pin A0. When I read from ADCH and ADCL. The result is correct only once in the startup. When I change the analog value in A0, output from the ADC don't change at all. Unless I have reset the mcu.

In the datasheet it is not state clearly that there is a register called ADC. They highlight ADCH and ADCL.

This is my simple code that don't work.

/*
* Section: Function Defintion
*/
// Select the refence voltage to be AVcc, which is connected to Vcc in the Arduino Nano board
// Set Prescaler to 128, so that the ADC clock is 16M/128= 125Khz
sei();

}
}
// if changed to i = ADC; it work fine!!
return i;
}


What is could be the cause to make the ADC hold conversion because of reading from ADCL?

• I whoud try this uint16_t i = (uint16_t) (ADCL + (ADCH*256)); becouse ADCL must be read first, then ADCH
– G36
Oct 5 '20 at 15:09
• @G36, thanks it worked. However, no any logical explanation for this. Oct 5 '20 at 21:20

Use this code

/*
* Section: Function Defintion
*/
// Select the refence voltage to be AVcc, which is connected to Vcc in the Arduino Nano board
// Set Prescaler to 128, so that the ADC clock is 16M/128= 125Khz
sei();

}
}
return i;
}

• I looked again in the datasheet and it is said that ADCL must be read first. As G36 suggested Oct 5 '20 at 21:22
• @AshrafAlmubarak thanks for correcting me, So I am editing the code. Oct 6 '20 at 4:40