I want to make ADC with internal reference(1.1V) .With the code below, on Proteus, above 5V it always shows the same value, and below 5V it shows the correct values. What should I do for higher voltage values? And theoretically, can I measure 12 volts correctly with this voltage divider circuit?
void setup() {
Serial.begin(9600);
}
void loop() {
ADMUX|= B00000100; //We read A4
ADMUX|= B11000000; //REFS1 AND REFSO equal to 1 (INTERNAL 1.1V)
ADCSRA|=B00000111;
ADCSRA|= B11000000; //ADEN and ADSC equal to 1 (Start conversion)
while (bit_is_set(ADCSRA, ADSC)); //Wait for conversion to end
float value =ADCL | (ADCH << 8); //Get analog read value
value= value*(1.1/1023)*(11/1);//Multiply by voltage divider inverted// using10kohm and 1k ohm
Serial.println(value);
delay(500);
}
5V where? On BAT1? Anything up to around 10V should result in a proper reading if you do set the ADC to use the internal reference.
Is there any particular reason you're using direct register access to set up the ADC?
Also, you're reconfiguring the ADC without disabling it first. IDK what kind of behavior to expect in that case.
I've not checked if you set all registers correctly for the ADC.
What I mean by 5 volts is actually the value of the battery in the simulation circuit. If I run the simulation on 5 volts, Arduino always reads 5.5 volts. However, if the battery's value is less than 5 volts, it reads properly.
There is no particular reason to use register.
This video is the source from which I get help.
ADC blocks and REGISTERS | Internal Reference | Internal Temperature Sensor Arduino101 by
Electronoobs
Then I'd suggest to use the Arduino API instead, which will save you some trouble. Once you get that to work, you can always replace certain elements with direct register writes if you like.
I don't know about your current problem but I hope you know that the internal reference voltage of 1.1 volts is not exact and varies quite widely (+/-10%). You must calibrate the program for each specific microcontroller instance.