const long InternalReferenceVoltage = 1115L; // Adjust this value to your boards specific internal BG voltage x1000
// For 168/328 boards const long InternalReferenceVoltage = 1056L; // Adjust this value to your boards specific internal BG voltage x1000 // REFS1 REFS0 --> 0 1, AVcc internal ref. -Selects AVcc external reference // MUX3 MUX2 MUX1 MUX0 --> 1110 1.1V (VBG) -Selects channel 14, bandgap voltage, to measure ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);
int results = (((InternalReferenceVoltage * 1023L) / ADC) + 5L) / 10L; // calculates for straight line value
It looks like this Vcc calculation is gonna work just fine. It doesn't mean much until Vcc goes below 5 volts, but then I use it to correct the analog readings for my TMP36 and other analog sensors. I measured the temperature of a glass of ice water and it measured a pretty constant 32 degrees as the battery went dead. I added a routine that posts like a low battery on the LCD when Vcc drops below 5 Volts and stops the routine when Vcc gets below 4 volts. Thanks to Lefty and Coding Badly for the routine and the others for your comments and help. My first project is to log temperatures along the fuel system of an antique car to investigate vapor locking. Bill
AREF, IRV (internal reference voltage), and ADC (value from the analog-to-digital converter) are related by a ratio...[font=Courier New] AREF / IRV = 1023 / ADC[/font]Solve for AREF...[font=Courier New] AREF = IRV * 1023 / ADC[/font]The "+5L" rounds fractions up. The "/10L" converts from millivolts to centivolts (volts * 100) giving three significant digits (which is the most we can expect from a 12 bit converter). The basic equation is the one above. The rest is to avoid floating-point math.Make sense?
Ooh. That 1023 should be 1024...[font=Courier New]int results = (((InternalReferenceVoltage * 1024L) / ADC) + 5L) / 10L; // calculates for straight line value[/font]Dang, @retrolefty. Why didn't you catch that? You're supposed to have my back.
I don't exactly understand what is happening in the following line of code where all the magic happens:
I thought that I would have to build a voltage regulating circuit